Add headers to client

This commit is contained in:
Dongri Jin
2025-03-05 07:26:04 +09:00
parent 2e6ea3eedd
commit ddeefd256c
26 changed files with 77 additions and 113 deletions

View File

@ -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());

View File

@ -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(),

View File

@ -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";

View File

@ -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(),

View File

@ -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(),

View File

@ -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(),
@ -21,7 +21,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(())
}

View File

@ -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(),

View File

@ -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(),

View File

@ -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(

View File

@ -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(

View File

@ -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()?;
@ -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(())
}

View File

@ -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(),