sticklight-io / declarai

A Pythonic integration for LLMs.

Home Page:https://declarai.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support `OPENAI_API_KEY` env var

giladbarnea opened this issue · comments

Most libraries and services that have to do with OpenAI, and need an api token, support the OPENAI_API_KEY env var. So I often export OPENAI_API_KEY to my shell session once, and that satisfies the requirements of most tools.

But Declarai specially requires DECLARAI_OPENAI_API_KEY, which introduces some friction to my workflow.

image

Please support OPENAI_API_KEY. You can still support DECLARAI_OPENAI_API_KEY and even give precedence to it over OPENAI_API_KEY if both exist.

Thanks!

Thanks for raising that. Will be integrated in the next release.

I would love to contribute to this issue.... please can you provide some more information..... on how can I get started.

Hey @shobhit9957 ! That would be great!

Here is a brief guide that I think might help you get started:

Familiarize with the current code:
The code currently looks for environment variables prefixed with "DECLARAI". This prefix is dynamically used, and the final key is ${DECLARAI_PREFIX}_OPENAI_API_KEY. (view declarai/operators/openai_operators/settings)

Modify to support OPEN_AI_KEY:
We need to check first if DECLARAI_OPEN_AI_KEY is set. If not, then fall back to OPEN_AI_KEY. You can achieve this using os.getenv() for both environment variables and choosing the one that's set.

OPENAI_API_KEY: str = os.getenv(f"{DECLARAI_PREFIX}_OPENAI_API_KEY", os.getenv("OPENAI_API_KEY", ""))

Test your changes:
Set only the OPEN_AI_KEY environment variable and check if the code picks it up.
Set only the DECLARAI_OPEN_AI_KEY environment variable and check if the code picks it up.
Set both environment variables and verify that DECLARAI_OPEN_AI_KEY gets precedence.

Document your changes:
Add a comment in the code explaining the precedence and why it was done. This ensures that future developers understand the intent behind the changes.

Create a Pull Request (PR):
Open a Pull Request from your branch to the main branch of the repository. This will allow the maintainers (and others) to review your changes and provide feedback.

You can also view the contribute page - https://declarai.com/contribute/

Let us know if you got any questions, you can use this thread :)
Thank you for your first contribution, this means a lot to all of us 🥇

Hey, thanks @matankley for giving me this opportunity. Will follow the steps you have provided and update you with the feedbacks. Thanks!