Skip to content

Commit 13b8fc8

Browse files
authored
Add store and metadata parameters (#300)
* Add store flag for chat completion request * Add metadata and example used in evals and distillation guides
1 parent bd7a87e commit 13b8fc8

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

async-openai/src/types/chat.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,16 @@ pub struct CreateChatCompletionRequest {
506506
/// See the [model endpoint compatibility](https://platform.openai.com/docs/models/model-endpoint-compatibility) table for details on which models work with the Chat API.
507507
pub model: String,
508508

509+
/// Whether or not to store the output of this chat completion request
510+
///
511+
/// for use in our [model distillation](https://platform.openai.com/docs/guides/distillation) or [evals](https://platform.openai.com/docs/guides/evals) products.
512+
#[serde(skip_serializing_if = "Option::is_none")]
513+
pub store: Option<bool>, // nullable: true, default: false
514+
515+
/// Developer-defined tags and values used for filtering completions in the [dashboard](https://platform.openai.com/chat-completions).
516+
#[serde(skip_serializing_if = "Option::is_none")]
517+
pub metadata: Option<serde_json::Value>, // nullable: true
518+
509519
/// Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.
510520
///
511521
/// [See more information about frequency and presence penalties.](https://platform.openai.com/docs/api-reference/parameter-details)

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)