Add API key parameter to NewClient and NewTranslator functions #41
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request primarily focuses on changes to the OpenAI client within the
internal/cli/cli.go
andinternal/openai/client.go
files. The main change is the removal of the dependency on theos
package to fetch the OpenAI API key from the environment variables. Instead, the API key is now passed as an argument when creating a new client. This change is reflected across the codebase, including in the tests and the main program.API Key Handling:
internal/cli/cli.go
: TheNewTranslator
function now accepts an API key as an argument instead of fetching it from the environment variables.internal/openai/client.go
: TheClient
struct now includes anAPIKey
field. TheNewClient
function accepts the API key as an argument and validates it. TheChat
function uses the API key from theClient
struct instead of the environment variables. [1] [2] [3] [4] [5]internal/openai/client_test.go
: The tests for the client have been updated to pass an API key when creating a new client and to validate theAuthorization
header. [1] [2] [3]main.go
: The main program fetches the API key from the environment variables and passes it to theNewTranslator
function. It also includes error handling for the case where the API key is not set.