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

Setting up model credentials programmatically? #859

Open
sahuguet opened this issue Nov 13, 2024 · 5 comments
Open

Setting up model credentials programmatically? #859

sahuguet opened this issue Nov 13, 2024 · 5 comments

Comments

@sahuguet
Copy link
Contributor

At my firm, we are proxying all requests to LLM service providers; users are assigned keys we rotate keys frequently; these are then translated into OpenAI/Anthropic/etc. keys on the backend.

Having keys hardcoded in the .env file is not practical.

Is there a way of programmatically setting up keys for the various models inside the script itself?

@pelikhan
Copy link
Member

pelikhan commented Nov 14, 2024

Currently not aside from dynamically setting the environment variables when launching the CLI. The .env file is only used to populate the process.env object.

One could think of registering a function that reads secrets?

readSecret(id: string) => promise

We kind of have a similar support for the Azure providers where we fetch a token on demand.

@sahuguet
Copy link
Contributor Author

And what variable would that function need to update to override the value from .env?

@pelikhan
Copy link
Member

I've added a documentation section about skipping the '.env' file all together (https://microsoft.github.io/genaiscript/getting-started/configuration/#no-env-file). I wonder if this would be enough to unblock as you "just" need to have a wrapper that sets up the environment variables and launch genaiscript. (genaiscript optionally loads the .env file)

@sahuguet
Copy link
Contributor Author

I ended up writing a zx script that fetches the credentials and update the .env file.

A more elegant option (for me) would be to be able to override these variables in the script section, e.g. using process.env.XXXX to retrieve the values.

script({
    OPENAI_API_KEY: process.env.OPENAI_API_KEY,   // or any arbitrary function
   ...
})

@pelikhan
Copy link
Member

If you simply need to use process.env variable, you already get this for free since this is where GenAIScript loads the secrets (after optionally applying the .env file). So in your case, remove any .env file and set the process environment variables when lauching genaiscript. This is what I tried to document in the new docs.

(Looking for a better option for a javascript-based config)

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

No branches or pull requests

2 participants