Skip to content
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

[Bug]: Global Overwrite of OpenAI API Key During Text Embedding Execution #2979

Closed
watanabeycr7 opened this issue Oct 21, 2024 · 1 comment
Closed
Assignees
Labels
bug Something isn't working

Comments

@watanabeycr7
Copy link
Contributor

What happened?

When the OpenAIEmbeddingFunction() is executed, the api_key provided as an argument overwrites the openai.api_key that is referenced globally throughout the application. This behavior prevents the application from being able to differentiate between the API key used for embeddings and the API key used for regular chat operations.

Here's a snippet of the affected code:

app.logger.info(f"openai.api_key: {openai.api_key[-4:]}")
app.logger.info(f"ANOHTER_OPENAI_API_KEY: {ANOTHER_OPENAI_API_KEY[-4:]}")

embedding_function = embedding_functions.OpenAIEmbeddingFunction(
    api_key=ANOTHER_OPENAI_API_KEY, model_name=EMBEDDING_MODEL
)

app.logger.info(f"openai.api_key: {openai.api_key[-4:]}")

Versions

chroma v0.5.5
flask v2.3.2
python 3.11.6

Relevant log output

2024-10-21 17:34:25 [2024-10-21 08:34:25,464] INFO in internal_chatbot_documents_controller: openai.api_key: pTV4
2024-10-21 17:34:25 [2024-10-21 08:34:25,464] INFO in internal_chatbot_documents_controller: ANOHTER_OPENAI_API_KEY: -EsA
2024-10-21 17:34:25 [2024-10-21 08:34:25,483] INFO in internal_chatbot_documents_controller: openai.api_key: -EsA
@watanabeycr7 watanabeycr7 added the bug Something isn't working label Oct 21, 2024
@watanabeycr7
Copy link
Contributor Author

I've identified the issue and have a possible solution in mind. I'll begin working on a PR to address this.

@itaismith itaismith self-assigned this Oct 30, 2024
rescrv pushed a commit that referenced this issue Nov 13, 2024
## Description of changes

*Summarize the changes made by this PR.*
 - Improvements & Bug fixes
 Allow multiple openAI API keys #2979 
Removed direct assignment to global openai.api_key to prevent unintended
side effects.


## Test plan
*How are these changes tested?*

- [ ] Tests pass locally with `pytest` for python, `yarn test` for js,
`cargo test` for rust

It seems that `cargo test` is failing due to a build issue. #2294 
Both `pytest` and `yarn test` succeed.


## Documentation Changes
*Are all docstrings for user-facing APIs updated if required? Do we need
to make documentation changes in the [docs
repository](https://github.com/chroma-core/docs)?*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants