Skip to content

Commit

Permalink
Merge pull request #297 from shashankleanmvp/main
Browse files Browse the repository at this point in the history
Updated Docs, adding information about how use apikey without enviroment variable.
  • Loading branch information
williamhogman authored Jul 29, 2024
2 parents 9e6e49e + 875e578 commit af3c8d9
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,40 @@ One common issue you might encounter is forgetting to set the OpenAI API key. Ma

```bash
export OPENAI_API_KEY="YOUR_OPEN_AI_KEY" # TIP: It stars with sk-
```
If you don't want to set enviroment variable or want to multiple api-keys. Then you can use a different macro like this.

```rust
use llm_chain::{executor, options, parameters, prompt};
use tokio;

// Declare an async main function
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a new ChatGPT executor
let options = options! {
ApiKey: "sk-proj-..."
};

let exec = executor!(chatgpt, options);
match exec {
Ok(exec) => {

let res = prompt!(
"You are a robot assistant for making personalized greetings",
"Make a personalized greeting for Joe"
)
.run(&parameters!(), &exec) // ...and run it
.await?;
println!("{}", res);
}
Err(err) => panic!("Unable to create executor: {}", err),
}
// Create our step containing our prompt template

Ok(())
}

```

In the next tutorial, we'll cover adding parameters to customize the LLM prompt to create more complicated interactions.

0 comments on commit af3c8d9

Please sign in to comment.