Skip to content

Commit f453dc9

Browse files
committed
chore: update examples
1 parent ffe2bd4 commit f453dc9

File tree

5 files changed

+15
-20
lines changed

5 files changed

+15
-20
lines changed

examples/chat_completion.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ use openai_api_rs::v1::api::Client;
22
use openai_api_rs::v1::chat_completion::{self, ChatCompletionRequest};
33
use std::env;
44

5-
#[tokio::main]
6-
async fn main() -> Result<(), Box<dyn std::error::Error>> {
5+
fn main() -> Result<(), Box<dyn std::error::Error>> {
76
let client = Client::new(env::var("OPENAI_API_KEY").unwrap().to_string());
87
let req = ChatCompletionRequest {
98
model: chat_completion::GPT4.to_string(),
@@ -26,7 +25,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
2625
logit_bias: None,
2726
user: None,
2827
};
29-
let result = client.chat_completion(req).await?;
28+
let result = client.chat_completion(req)?;
3029
println!("{:?}", result.choices[0].message.content);
3130
Ok(())
3231
}

examples/completion.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ use openai_api_rs::v1::api::Client;
22
use openai_api_rs::v1::completion::{self, CompletionRequest};
33
use std::env;
44

5-
#[tokio::main]
6-
async fn main() -> Result<(), Box<dyn std::error::Error>> {
5+
fn main() -> Result<(), Box<dyn std::error::Error>> {
76
let client = Client::new(env::var("OPENAI_API_KEY").unwrap().to_string());
87
let req = CompletionRequest {
98
model: completion::GPT3_TEXT_DAVINCI_003.to_string(),
@@ -23,7 +22,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
2322
logit_bias: None,
2423
user: None,
2524
};
26-
let result = client.completion(req).await?;
25+
let result = client.completion(req)?;
2726
println!("{:}", result.choices[0].text);
2827

2928
Ok(())

examples/embedding.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ use openai_api_rs::v1::api::Client;
22
use openai_api_rs::v1::embedding::EmbeddingRequest;
33
use std::env;
44

5-
#[tokio::main]
6-
async fn main() -> Result<(), Box<dyn std::error::Error>> {
5+
fn main() -> Result<(), Box<dyn std::error::Error>> {
76
let client = Client::new(env::var("OPENAI_API_KEY").unwrap().to_string());
87
let req = EmbeddingRequest {
98
model: "text-embedding-ada-002".to_string(),
109
input: "story time".to_string(),
1110
user: Option::None,
1211
};
13-
let result = client.embedding(req).await?;
12+
let result = client.embedding(req)?;
1413
println!("{:?}", result.data);
1514

1615
Ok(())

examples/function_call.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
44
use std::collections::HashMap;
55
use std::{env, vec};
66

7-
async fn get_coin_price(coin: &str) -> f64 {
7+
fn get_coin_price(coin: &str) -> f64 {
88
let coin = coin.to_lowercase();
99
match coin.as_str() {
1010
"btc" | "bitcoin" => 10000.0,
@@ -13,8 +13,7 @@ async fn get_coin_price(coin: &str) -> f64 {
1313
}
1414
}
1515

16-
#[tokio::main]
17-
async fn main() -> Result<(), Box<dyn std::error::Error>> {
16+
fn main() -> Result<(), Box<dyn std::error::Error>> {
1817
let client = Client::new(env::var("OPENAI_API_KEY").unwrap().to_string());
1918

2019
let mut properties = HashMap::new();
@@ -60,7 +59,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
6059
user: None,
6160
};
6261

63-
let result = client.chat_completion(req).await?;
62+
let result = client.chat_completion(req)?;
6463

6564
match result.choices[0].finish_reason {
6665
chat_completion::FinishReason::stop => {
@@ -82,7 +81,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
8281
let c: Currency = serde_json::from_str(&arguments)?;
8382
let coin = c.coin;
8483
if name == "get_coin_price" {
85-
let price = get_coin_price(&coin).await;
84+
let price = get_coin_price(&coin);
8685
println!("{} price: {}", coin, price);
8786
}
8887
}

examples/function_call_role.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
44
use std::collections::HashMap;
55
use std::{env, vec};
66

7-
async fn get_coin_price(coin: &str) -> f64 {
7+
fn get_coin_price(coin: &str) -> f64 {
88
let coin = coin.to_lowercase();
99
match coin.as_str() {
1010
"btc" | "bitcoin" => 10000.0,
@@ -13,8 +13,7 @@ async fn get_coin_price(coin: &str) -> f64 {
1313
}
1414
}
1515

16-
#[tokio::main]
17-
async fn main() -> Result<(), Box<dyn std::error::Error>> {
16+
fn main() -> Result<(), Box<dyn std::error::Error>> {
1817
let client = Client::new(env::var("OPENAI_API_KEY").unwrap().to_string());
1918

2019
let mut properties = HashMap::new();
@@ -60,7 +59,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
6059
user: None,
6160
};
6261

63-
let result = client.chat_completion(req).await?;
62+
let result = client.chat_completion(req)?;
6463

6564
match result.choices[0].finish_reason {
6665
chat_completion::FinishReason::stop => {
@@ -93,7 +92,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
9392
chat_completion::ChatCompletionMessage {
9493
role: chat_completion::MessageRole::function,
9594
content: {
96-
let price = get_coin_price(&coin).await;
95+
let price = get_coin_price(&coin);
9796
format!("{{\"price\": {}}}", price)
9897
},
9998
name: Some(String::from("get_coin_price")),
@@ -113,7 +112,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
113112
logit_bias: None,
114113
user: None,
115114
};
116-
let result = client.chat_completion(req).await?;
115+
let result = client.chat_completion(req)?;
117116
println!("{:?}", result.choices[0].message.content);
118117
}
119118
chat_completion::FinishReason::content_filter => {

0 commit comments

Comments
 (0)