Skip to content

Commit 12a6fdd

Browse files
committed
Merge branch 'upstream' into wasm
# Conflicts: # async-openai-wasm/src/audit_logs.rs # async-openai-wasm/src/invites.rs # async-openai-wasm/src/project_api_keys.rs # async-openai-wasm/src/project_service_accounts.rs # async-openai-wasm/src/project_users.rs # async-openai-wasm/src/projects.rs # async-openai-wasm/src/types/audio.rs # async-openai-wasm/src/types/audit_log.rs # async-openai-wasm/src/types/chat.rs # async-openai-wasm/src/types/fine_tuning.rs # async-openai-wasm/src/types/impls.rs # async-openai-wasm/src/types/invites.rs # async-openai-wasm/src/types/mod.rs # async-openai-wasm/src/types/moderation.rs # async-openai-wasm/src/types/project_api_key.rs # async-openai-wasm/src/types/project_service_account.rs # async-openai-wasm/src/types/project_users.rs # async-openai-wasm/src/types/projects.rs # async-openai-wasm/src/types/upload.rs # async-openai-wasm/src/types/users.rs # async-openai-wasm/src/uploads.rs # async-openai-wasm/src/users.rs # async-openai/Cargo.toml # async-openai/README.md # async-openai/src/types/common.rs # examples/assistants-code-interpreter/Cargo.toml # examples/assistants-file-search/Cargo.toml # examples/assistants-file-search/src/main.rs # examples/assistants-func-call-stream/Cargo.toml # examples/assistants/Cargo.toml # examples/audio-speech/Cargo.toml # examples/audio-transcribe/Cargo.toml # examples/audio-translate/Cargo.toml # examples/azure-openai-service/Cargo.toml # examples/chat-stream/Cargo.toml # examples/chat/Cargo.toml # examples/completions-stream/Cargo.toml # examples/completions/Cargo.toml # examples/create-image-b64-json/Cargo.toml # examples/create-image-edit/Cargo.toml # examples/create-image-variation/Cargo.toml # examples/create-image/Cargo.toml # examples/embeddings/Cargo.toml # examples/function-call-stream/src/main.rs # examples/function-call/Cargo.toml # examples/function-call/src/main.rs # examples/in-memory-file/Cargo.toml # examples/models/Cargo.toml # examples/moderations/Cargo.toml # examples/moderations/src/main.rs # examples/openai-web-app-chat/Cargo.toml # examples/structured-outputs/Cargo.toml # examples/tool-call-stream/Cargo.toml # examples/tool-call-stream/src/main.rs # examples/tool-call/Cargo.toml # examples/vision-chat/Cargo.toml # examples/vision-chat/src/main.rs
2 parents b3cacfa + a1a5d99 commit 12a6fdd

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed

async-openai-wasm/src/types/impls.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,12 @@ impl From<String> for ChatCompletionRequestDeveloperMessage {
624624
}
625625
}
626626

627+
impl From<String> for ChatCompletionRequestDeveloperMessage {
628+
fn from(value: String) -> Self {
629+
value.as_str().into()
630+
}
631+
}
632+
627633
impl From<&str> for ChatCompletionRequestAssistantMessage {
628634
fn from(value: &str) -> Self {
629635
ChatCompletionRequestAssistantMessageContent::Text(value.into()).into()

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.135"
10+
tokio = { version = "1.43.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 async_openai::{
2+
types::{
3+
ChatCompletionRequestSystemMessageArgs, ChatCompletionRequestUserMessageArgs,
4+
CreateChatCompletionRequestArgs,
5+
},
6+
Client,
7+
};
8+
use serde_json::json;
9+
use std::error::Error;
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)