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

Add store and metadata parameters #300

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions async-openai/src/types/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,16 @@ pub struct CreateChatCompletionRequest {
/// 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.
pub model: String,

/// Whether or not to store the output of this chat completion request
///
/// for use in our [model distillation](https://platform.openai.com/docs/guides/distillation) or [evals](https://platform.openai.com/docs/guides/evals) products.
#[serde(skip_serializing_if = "Option::is_none")]
pub store: Option<bool>, // nullable: true, default: false

/// Developer-defined tags and values used for filtering completions in the [dashboard](https://platform.openai.com/chat-completions).
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<serde_json::Value>, // nullable: true

/// 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.
///
/// [See more information about frequency and presence penalties.](https://platform.openai.com/docs/api-reference/parameter-details)
Expand Down
10 changes: 10 additions & 0 deletions examples/chat-store/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "chat-store"
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
async-openai = {path = "../../async-openai"}
serde_json = "1.0.117"
tokio = { version = "1.38.0", features = ["full"] }
5 changes: 5 additions & 0 deletions examples/chat-store/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### Output

> Response:
>
> 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
49 changes: 49 additions & 0 deletions examples/chat-store/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use std::error::Error;
use async_openai::{
types::{
ChatCompletionRequestAssistantMessageArgs, ChatCompletionRequestSystemMessageArgs,
ChatCompletionRequestUserMessageArgs, CreateChatCompletionRequestArgs,
},
Client,
};
use serde_json::json;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let client = Client::new();

let request = CreateChatCompletionRequestArgs::default()
.max_tokens(512u32)
.model("gpt-3.5-turbo")
.store(true)
.metadata(json!({
"role": "manager",
"department": "accounting",
"source": "homepage",
}))
.messages([
ChatCompletionRequestSystemMessageArgs::default()
.content("You are a corporate IT support expert.")
.build()?
.into(),
ChatCompletionRequestUserMessageArgs::default()
.content("How can I hide the dock on my Mac?")
.build()?
.into(),
])
.build()?;

println!("{}", serde_json::to_string(&request).unwrap());

let response = client.chat().create(request).await?;

println!("\nResponse:\n");
for choice in response.choices {
println!(
"{}: Role: {} Content: {:?}",
choice.index, choice.message.role, choice.message.content
);
}

Ok(())
}