Closed nickworks closed 2 months ago
The README, examples, and rig.rs indicate I should set the
OPENAI_API_KEY
environment variable.Where and how is this done??
Thanks!
Hi! Thank you for your question. Setting your API Key for LLM providers like OpenAI or Cohere is pretty easy to do; please see the following guides depending on your preference:
Before setting environment variables, make sure you have the necessary API keys:
export OPENAI_API_KEY='your-api-key-here'
export COHERE_API_KEY='your-api-key-here'
~/.bashrc
, ~/.zshrc
, etc.):
nano ~/.bashrc
export OPENAI_API_KEY='your-api-key-here'
export COHERE_API_KEY='your-api-key-here'
source ~/.bashrc
set OPENAI_API_KEY=your-api-key-here
set COHERE_API_KEY=your-api-key-here
OPENAI_API_KEY
, Value: your OpenAI API keyCOHERE_API_KEY
, Value: your Cohere API keyTo check if your environment variables are set correctly:
echo $OPENAI_API_KEY
echo $COHERE_API_KEY
echo %OPENAI_API_KEY%
echo %COHERE_API_KEY%
With environment variables set, Rig can automatically access these API keys:
use rig::providers::{openai, cohere};
// OpenAI client
let openai_client = openai::Client::from_env();
// Cohere client
let cohere_client = cohere::Client::from_env();
For VS Code users, you can set environment variables in your launch.json
:
{
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug executable 'your-project-name'",
"cargo": {
"args": ["build", "--bin=your-project-name", "--package=your-project-name"],
"filter": {
"name": "your-project-name",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}",
"env": {
"OPENAI_API_KEY": "your-api-key-here",
"COHERE_API_KEY": "your-api-key-here"
}
}
]
}
If you're using rust-analyzer, you can set environment variables in .cargo/config.toml
:
[env]
OPENAI_API_KEY = "your-api-key-here"
COHERE_API_KEY = "your-api-key-here"
Remember to add this file to your .gitignore
to avoid accidentally sharing your API keys.
Thank you! I've added the .cargo/config.toml
with my api key and it works great.
@nickworks if you intent to make your project into a github repo, remember to not push your API key to the repo!
The README, examples, and rig.rs indicate I should set the
OPENAI_API_KEY
environment variable.Where and how is this done??
Thanks!