Skip to content

Commit d66dc55

Browse files
authored
Merge pull request #152 from dongri/fix-client-headers
Add headers to client
2 parents 2e6ea3e + d4bf0a8 commit d66dc55

26 files changed

+102
-113
lines changed

examples/assistant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::env;
1010
#[tokio::main]
1111
async fn main() -> Result<(), Box<dyn std::error::Error>> {
1212
let api_key = env::var("OPENAI_API_KEY").unwrap().to_string();
13-
let client = OpenAIClient::builder().with_api_key(api_key).build()?;
13+
let mut client = OpenAIClient::builder().with_api_key(api_key).build()?;
1414

1515
let mut tools = HashMap::new();
1616
tools.insert("type".to_string(), "code_interpreter".to_string());

examples/audio_speech.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::env;
55
#[tokio::main]
66
async fn main() -> Result<(), Box<dyn std::error::Error>> {
77
let api_key = env::var("OPENAI_API_KEY").unwrap().to_string();
8-
let client = OpenAIClient::builder().with_api_key(api_key).build()?;
8+
let mut client = OpenAIClient::builder().with_api_key(api_key).build()?;
99

1010
let req = AudioSpeechRequest::new(
1111
TTS_1.to_string(),

examples/audio_transcriptions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::io::Read;
77
#[tokio::main]
88
async fn main() -> Result<(), Box<dyn std::error::Error>> {
99
let api_key = env::var("OPENAI_API_KEY").unwrap().to_string();
10-
let client = OpenAIClient::builder().with_api_key(api_key).build()?;
10+
let mut client = OpenAIClient::builder().with_api_key(api_key).build()?;
1111

1212
let file_path = "examples/data/problem.mp3";
1313

examples/audio_translations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::env;
55
#[tokio::main]
66
async fn main() -> Result<(), Box<dyn std::error::Error>> {
77
let api_key = env::var("OPENAI_API_KEY").unwrap().to_string();
8-
let client = OpenAIClient::builder().with_api_key(api_key).build()?;
8+
let mut client = OpenAIClient::builder().with_api_key(api_key).build()?;
99

1010
let req = AudioTranslationRequest::new(
1111
"examples/data/problem_cn.mp3".to_string(),

examples/batch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::str;
1010
#[tokio::main]
1111
async fn main() -> Result<(), Box<dyn std::error::Error>> {
1212
let api_key = env::var("OPENAI_API_KEY").unwrap().to_string();
13-
let client = OpenAIClient::builder().with_api_key(api_key).build()?;
13+
let mut client = OpenAIClient::builder().with_api_key(api_key).build()?;
1414

1515
let req = FileUploadRequest::new(
1616
"examples/data/batch_request.json".to_string(),

examples/chat_completion.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::env;
66
#[tokio::main]
77
async fn main() -> Result<(), Box<dyn std::error::Error>> {
88
let api_key = env::var("OPENAI_API_KEY").unwrap().to_string();
9-
let client = OpenAIClient::builder().with_api_key(api_key).build()?;
9+
let mut client = OpenAIClient::builder().with_api_key(api_key).build()?;
1010

1111
let req = ChatCompletionRequest::new(
1212
GPT4_O_MINI.to_string(),
@@ -21,7 +21,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
2121

2222
let result = client.chat_completion(req).await?;
2323
println!("Content: {:?}", result.choices[0].message.content);
24-
println!("Response Headers: {:?}", result.headers);
24+
25+
// print response headers
26+
for (key, value) in client.headers.unwrap().iter() {
27+
println!("{}: {:?}", key, value);
28+
}
2529

2630
Ok(())
2731
}

examples/completion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::env;
55
#[tokio::main]
66
async fn main() -> Result<(), Box<dyn std::error::Error>> {
77
let api_key = env::var("OPENAI_API_KEY").unwrap().to_string();
8-
let client = OpenAIClient::builder().with_api_key(api_key).build()?;
8+
let mut client = OpenAIClient::builder().with_api_key(api_key).build()?;
99

1010
let req = CompletionRequest::new(
1111
completion::GPT3_TEXT_DAVINCI_003.to_string(),

examples/embedding.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::env;
66
#[tokio::main]
77
async fn main() -> Result<(), Box<dyn std::error::Error>> {
88
let api_key = env::var("OPENAI_API_KEY").unwrap().to_string();
9-
let client = OpenAIClient::builder().with_api_key(api_key).build()?;
9+
let mut client = OpenAIClient::builder().with_api_key(api_key).build()?;
1010

1111
let mut req = EmbeddingRequest::new(
1212
TEXT_EMBEDDING_3_SMALL.to_string(),

examples/function_call.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fn get_coin_price(coin: &str) -> f64 {
1818
#[tokio::main]
1919
async fn main() -> Result<(), Box<dyn std::error::Error>> {
2020
let api_key = env::var("OPENAI_API_KEY").unwrap().to_string();
21-
let client = OpenAIClient::builder().with_api_key(api_key).build()?;
21+
let mut client = OpenAIClient::builder().with_api_key(api_key).build()?;
2222

2323
let mut properties = HashMap::new();
2424
properties.insert(

examples/function_call_role.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fn get_coin_price(coin: &str) -> f64 {
1818
#[tokio::main]
1919
async fn main() -> Result<(), Box<dyn std::error::Error>> {
2020
let api_key = env::var("OPENAI_API_KEY").unwrap().to_string();
21-
let client = OpenAIClient::builder().with_api_key(api_key).build()?;
21+
let mut client = OpenAIClient::builder().with_api_key(api_key).build()?;
2222

2323
let mut properties = HashMap::new();
2424
properties.insert(

examples/openrouter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::env;
66
#[tokio::main]
77
async fn main() -> Result<(), Box<dyn std::error::Error>> {
88
let api_key = env::var("OPENROUTER_API_KEY").unwrap().to_string();
9-
let client = OpenAIClient::builder()
9+
let mut client = OpenAIClient::builder()
1010
.with_endpoint("https://openrouter.ai/api/v1")
1111
.with_api_key(api_key)
1212
.build()?;
@@ -24,7 +24,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
2424

2525
let result = client.chat_completion(req).await?;
2626
println!("Content: {:?}", result.choices[0].message.content);
27-
println!("Response Headers: {:?}", result.headers);
27+
println!("Response Headers: {:?}", client.headers);
2828

2929
Ok(())
3030
}

examples/vision.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::env;
66
#[tokio::main]
77
async fn main() -> Result<(), Box<dyn std::error::Error>> {
88
let api_key = env::var("OPENAI_API_KEY").unwrap().to_string();
9-
let client = OpenAIClient::builder().with_api_key(api_key).build()?;
9+
let mut client = OpenAIClient::builder().with_api_key(api_key).build()?;
1010

1111
let req = ChatCompletionRequest::new(
1212
GPT4_O.to_string(),

0 commit comments

Comments
 (0)