Skip to content

Add headers to client #152

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

Merged
merged 3 commits into from
Mar 4, 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
2 changes: 1 addition & 1 deletion examples/assistant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::env;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = env::var("OPENAI_API_KEY").unwrap().to_string();
let client = OpenAIClient::builder().with_api_key(api_key).build()?;
let mut client = OpenAIClient::builder().with_api_key(api_key).build()?;

let mut tools = HashMap::new();
tools.insert("type".to_string(), "code_interpreter".to_string());
Expand Down
2 changes: 1 addition & 1 deletion examples/audio_speech.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::env;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = env::var("OPENAI_API_KEY").unwrap().to_string();
let client = OpenAIClient::builder().with_api_key(api_key).build()?;
let mut client = OpenAIClient::builder().with_api_key(api_key).build()?;

let req = AudioSpeechRequest::new(
TTS_1.to_string(),
Expand Down
2 changes: 1 addition & 1 deletion examples/audio_transcriptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::io::Read;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = env::var("OPENAI_API_KEY").unwrap().to_string();
let client = OpenAIClient::builder().with_api_key(api_key).build()?;
let mut client = OpenAIClient::builder().with_api_key(api_key).build()?;

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

Expand Down
2 changes: 1 addition & 1 deletion examples/audio_translations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::env;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = env::var("OPENAI_API_KEY").unwrap().to_string();
let client = OpenAIClient::builder().with_api_key(api_key).build()?;
let mut client = OpenAIClient::builder().with_api_key(api_key).build()?;

let req = AudioTranslationRequest::new(
"examples/data/problem_cn.mp3".to_string(),
Expand Down
2 changes: 1 addition & 1 deletion examples/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::str;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = env::var("OPENAI_API_KEY").unwrap().to_string();
let client = OpenAIClient::builder().with_api_key(api_key).build()?;
let mut client = OpenAIClient::builder().with_api_key(api_key).build()?;

let req = FileUploadRequest::new(
"examples/data/batch_request.json".to_string(),
Expand Down
8 changes: 6 additions & 2 deletions examples/chat_completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::env;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = env::var("OPENAI_API_KEY").unwrap().to_string();
let client = OpenAIClient::builder().with_api_key(api_key).build()?;
let mut client = OpenAIClient::builder().with_api_key(api_key).build()?;

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

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

// print response headers
for (key, value) in client.headers.unwrap().iter() {
println!("{}: {:?}", key, value);
}

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion examples/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::env;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = env::var("OPENAI_API_KEY").unwrap().to_string();
let client = OpenAIClient::builder().with_api_key(api_key).build()?;
let mut client = OpenAIClient::builder().with_api_key(api_key).build()?;

let req = CompletionRequest::new(
completion::GPT3_TEXT_DAVINCI_003.to_string(),
Expand Down
2 changes: 1 addition & 1 deletion examples/embedding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::env;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = env::var("OPENAI_API_KEY").unwrap().to_string();
let client = OpenAIClient::builder().with_api_key(api_key).build()?;
let mut client = OpenAIClient::builder().with_api_key(api_key).build()?;

let mut req = EmbeddingRequest::new(
TEXT_EMBEDDING_3_SMALL.to_string(),
Expand Down
2 changes: 1 addition & 1 deletion examples/function_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn get_coin_price(coin: &str) -> f64 {
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = env::var("OPENAI_API_KEY").unwrap().to_string();
let client = OpenAIClient::builder().with_api_key(api_key).build()?;
let mut client = OpenAIClient::builder().with_api_key(api_key).build()?;

let mut properties = HashMap::new();
properties.insert(
Expand Down
2 changes: 1 addition & 1 deletion examples/function_call_role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn get_coin_price(coin: &str) -> f64 {
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = env::var("OPENAI_API_KEY").unwrap().to_string();
let client = OpenAIClient::builder().with_api_key(api_key).build()?;
let mut client = OpenAIClient::builder().with_api_key(api_key).build()?;

let mut properties = HashMap::new();
properties.insert(
Expand Down
4 changes: 2 additions & 2 deletions examples/openrouter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::env;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = env::var("OPENROUTER_API_KEY").unwrap().to_string();
let client = OpenAIClient::builder()
let mut client = OpenAIClient::builder()
.with_endpoint("https://openrouter.ai/api/v1")
.with_api_key(api_key)
.build()?;
Expand All @@ -24,7 +24,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

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

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion examples/vision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::env;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = env::var("OPENAI_API_KEY").unwrap().to_string();
let client = OpenAIClient::builder().with_api_key(api_key).build()?;
let mut client = OpenAIClient::builder().with_api_key(api_key).build()?;

let req = ChatCompletionRequest::new(
GPT4_O.to_string(),
Expand Down
Loading
Loading