Skip to content

Add API key parameter to NewClient and NewTranslator functions #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 14, 2024

Conversation

catatsuy
Copy link
Owner

This pull request primarily focuses on changes to the OpenAI client within the internal/cli/cli.go and internal/openai/client.go files. The main change is the removal of the dependency on the os 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: The NewTranslator function now accepts an API key as an argument instead of fetching it from the environment variables.
  • internal/openai/client.go: The Client struct now includes an APIKey field. The NewClient function accepts the API key as an argument and validates it. The Chat function uses the API key from the Client 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 the Authorization header. [1] [2] [3]
  • main.go: The main program fetches the API key from the environment variables and passes it to the NewTranslator function. It also includes error handling for the case where the API key is not set.

@catatsuy catatsuy merged commit 7eaf917 into main Jul 14, 2024
5 checks passed
@catatsuy catatsuy deleted the feature-add-api-key-to-newclient branch July 14, 2024 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant