Skip to content

Commit a8f6bb8

Browse files
didriksgSevenannn
authored andcommitted
Add store and metadata parameters (64bit#300)
* Add store flag for chat completion request * Add metadata and example used in evals and distillation guides
1 parent 9debf20 commit a8f6bb8

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

examples/chat-store/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "chat-store"
3+
version = "0.1.0"
4+
edition = "2021"
5+
publish = false
6+
7+
[dependencies]
8+
async-openai = {path = "../../async-openai"}
9+
serde_json = "1.0.117"
10+
tokio = { version = "1.38.0", features = ["full"] }

examples/chat-store/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
### Output
2+
3+
> Response:
4+
>
5+
> 0: Role: assistant Content: To hide the dock on a Mac, you can follow these steps:\n\n1. Click on the Apple logo in the top-left corner of the screen.\n2. Select \"System Preferences\" from the drop-down menu.\n3. Click on \"Dock & Menu Bar\".\n4. Under the \"Dock\" section, you will see an option to \"Automatically hide and show the Dock\". Check the box next to this option.\n5. The dock will now be hidden until you move your cursor to the bottom of the screen, at which point it will slide back into view.\n\nYou can also change the size and position of the dock in the Dock preferences

examples/chat-store/src/main.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
use std::error::Error;
2+
use async_openai::{
3+
types::{
4+
ChatCompletionRequestAssistantMessageArgs, ChatCompletionRequestSystemMessageArgs,
5+
ChatCompletionRequestUserMessageArgs, CreateChatCompletionRequestArgs,
6+
},
7+
Client,
8+
};
9+
use serde_json::json;
10+
11+
#[tokio::main]
12+
async fn main() -> Result<(), Box<dyn Error>> {
13+
let client = Client::new();
14+
15+
let request = CreateChatCompletionRequestArgs::default()
16+
.max_tokens(512u32)
17+
.model("gpt-3.5-turbo")
18+
.store(true)
19+
.metadata(json!({
20+
"role": "manager",
21+
"department": "accounting",
22+
"source": "homepage",
23+
}))
24+
.messages([
25+
ChatCompletionRequestSystemMessageArgs::default()
26+
.content("You are a corporate IT support expert.")
27+
.build()?
28+
.into(),
29+
ChatCompletionRequestUserMessageArgs::default()
30+
.content("How can I hide the dock on my Mac?")
31+
.build()?
32+
.into(),
33+
])
34+
.build()?;
35+
36+
println!("{}", serde_json::to_string(&request).unwrap());
37+
38+
let response = client.chat().create(request).await?;
39+
40+
println!("\nResponse:\n");
41+
for choice in response.choices {
42+
println!(
43+
"{}: Role: {} Content: {:?}",
44+
choice.index, choice.message.role, choice.message.content
45+
);
46+
}
47+
48+
Ok(())
49+
}

0 commit comments

Comments
 (0)