forked from 64bit/async-openai
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add store and metadata parameters (64bit#300)
* Add store flag for chat completion request * Add metadata and example used in evals and distillation guides
- Loading branch information
Showing
4 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} |