diff --git a/examples/chat_completion.rs b/examples/chat_completion.rs index f5fd4a0a..f15b4e49 100644 --- a/examples/chat_completion.rs +++ b/examples/chat_completion.rs @@ -16,7 +16,8 @@ fn main() -> Result<(), Box> { ); let result = client.chat_completion(req)?; - println!("{:?}", result.choices[0].message.content); + println!("Content: {:?}", result.choices[0].message.content); + println!("Response Headers: {:?}", result.headers); Ok(()) } diff --git a/src/v1/api.rs b/src/v1/api.rs index f188fb50..dd1e1129 100644 --- a/src/v1/api.rs +++ b/src/v1/api.rs @@ -175,7 +175,10 @@ impl Client { let res = self.post("/completions", &req)?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -184,7 +187,10 @@ impl Client { let res = self.post("/edits", &req)?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -196,7 +202,10 @@ impl Client { let res = self.post("/images/generations", &req)?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -205,7 +214,10 @@ impl Client { let res = self.post("/images/edits", &req)?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -217,7 +229,10 @@ impl Client { let res = self.post("/images/variations", &req)?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -226,7 +241,10 @@ impl Client { let res = self.post("/embeddings", &req)?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -235,7 +253,10 @@ impl Client { let res = self.get("/files")?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -244,7 +265,10 @@ impl Client { let res = self.post("/files", &req)?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -253,7 +277,10 @@ impl Client { let res = self.delete(&format!("{}/{}", "/files", req.file_id))?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -265,7 +292,10 @@ impl Client { let res = self.get(&format!("{}/{}", "/files", req.file_id))?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -277,7 +307,10 @@ impl Client { let res = self.get(&format!("{}/{}/content", "/files", req.file_id))?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -289,7 +322,10 @@ impl Client { let res = self.post("/chat/completions", &req)?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -301,7 +337,10 @@ impl Client { let res = self.post("/audio/transcriptions", &req)?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -313,7 +352,10 @@ impl Client { let res = self.post("/audio/translations", &req)?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -348,7 +390,10 @@ impl Client { }) } } - Ok(AudioSpeechResponse { result: true }) + Ok(AudioSpeechResponse { + result: true, + headers: Some(res.headers), + }) } pub fn create_fine_tuning_job( @@ -358,7 +403,10 @@ impl Client { let res = self.post("/fine_tuning/jobs", &req)?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -369,7 +417,10 @@ impl Client { let res = self.get("/fine_tuning/jobs")?; let r = res.json::>(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -384,7 +435,10 @@ impl Client { ))?; let r = res.json::>(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -396,7 +450,10 @@ impl Client { let res = self.get(&format!("/fine_tuning/jobs/{}", req.fine_tuning_job_id))?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -411,7 +468,10 @@ impl Client { )?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -423,7 +483,10 @@ impl Client { let res = self.post("/moderations", &req)?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -432,7 +495,10 @@ impl Client { let res = self.post("/assistants", &req)?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -441,7 +507,10 @@ impl Client { let res = self.get(&format!("/assistants/{}", assistant_id))?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -454,7 +523,10 @@ impl Client { let res = self.post(&format!("/assistants/{}", assistant_id), &req)?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -463,7 +535,10 @@ impl Client { let res = self.delete(&format!("/assistants/{}", assistant_id))?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -480,7 +555,10 @@ impl Client { let res = self.get(&url)?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -493,7 +571,10 @@ impl Client { let res = self.post(&format!("/assistants/{}/files", assistant_id), &req)?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -506,7 +587,10 @@ impl Client { let res = self.get(&format!("/assistants/{}/files/{}", assistant_id, file_id))?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -519,7 +603,10 @@ impl Client { let res = self.delete(&format!("/assistants/{}/files/{}", assistant_id, file_id))?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -537,7 +624,10 @@ impl Client { let res = self.get(&url)?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -546,7 +636,10 @@ impl Client { let res = self.post("/threads", &req)?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -555,7 +648,10 @@ impl Client { let res = self.get(&format!("/threads/{}", thread_id))?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -568,7 +664,10 @@ impl Client { let res = self.post(&format!("/threads/{}", thread_id), &req)?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -577,7 +676,10 @@ impl Client { let res = self.delete(&format!("/threads/{}", thread_id))?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -590,7 +692,10 @@ impl Client { let res = self.post(&format!("/threads/{}/messages", thread_id), &req)?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -603,7 +708,10 @@ impl Client { let res = self.get(&format!("/threads/{}/messages/{}", thread_id, message_id))?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -620,7 +728,10 @@ impl Client { )?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -629,7 +740,10 @@ impl Client { let res = self.get(&format!("/threads/{}/messages", thread_id))?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -646,7 +760,10 @@ impl Client { ))?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -665,7 +782,10 @@ impl Client { let res = self.get(&url)?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -678,7 +798,10 @@ impl Client { let res = self.post(&format!("/threads/{}/runs", thread_id), &req)?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -687,7 +810,10 @@ impl Client { let res = self.get(&format!("/threads/{}/runs/{}", thread_id, run_id))?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -701,7 +827,10 @@ impl Client { let res = self.post(&format!("/threads/{}/runs/{}", thread_id, run_id), &req)?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -719,7 +848,10 @@ impl Client { let res = self.get(&url)?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -732,7 +864,10 @@ impl Client { )?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -744,7 +879,10 @@ impl Client { let res = self.post("/threads/runs", &req)?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -761,7 +899,10 @@ impl Client { ))?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } @@ -780,7 +921,10 @@ impl Client { let res = self.get(&url)?; let r = res.json::(); match r { - Ok(r) => Ok(r), + Ok(mut r) => { + r.headers = Some(res.headers); + Ok(r) + } Err(e) => Err(self.new_error(e)), } } diff --git a/src/v1/assistant.rs b/src/v1/assistant.rs index 2bdc6742..3b62b97c 100644 --- a/src/v1/assistant.rs +++ b/src/v1/assistant.rs @@ -59,6 +59,7 @@ pub struct AssistantObject { pub tools: Vec>, pub file_ids: Vec, pub metadata: HashMap, + pub headers: Option>, } #[derive(Debug, Deserialize, Serialize)] @@ -66,12 +67,14 @@ pub struct DeletionStatus { pub id: String, pub object: String, pub deleted: bool, + pub headers: Option>, } #[derive(Debug, Deserialize, Serialize)] pub struct ListAssistant { pub object: String, pub data: Vec, + pub headers: Option>, } #[derive(Debug, Serialize, Clone)] @@ -85,10 +88,12 @@ pub struct AssistantFileObject { pub object: String, pub created_at: i64, pub assistant_id: String, + pub headers: Option>, } #[derive(Debug, Deserialize, Serialize)] pub struct ListAssistantFile { pub object: String, pub data: Vec, + pub headers: Option>, } diff --git a/src/v1/audio.rs b/src/v1/audio.rs index 6daf36df..07e53bd6 100644 --- a/src/v1/audio.rs +++ b/src/v1/audio.rs @@ -1,3 +1,5 @@ +use std::collections::HashMap; + use serde::{Deserialize, Serialize}; use crate::impl_builder_methods; @@ -42,6 +44,7 @@ impl_builder_methods!( #[derive(Debug, Deserialize, Serialize)] pub struct AudioTranscriptionResponse { pub text: String, + pub headers: Option>, } #[derive(Debug, Serialize, Clone)] @@ -78,6 +81,7 @@ impl_builder_methods!( #[derive(Debug, Deserialize, Serialize)] pub struct AudioTranslationResponse { pub text: String, + pub headers: Option>, } pub const TTS_1: &str = "tts-1"; @@ -114,4 +118,5 @@ impl_builder_methods!(AudioSpeechRequest,); #[derive(Debug, Deserialize, Serialize)] pub struct AudioSpeechResponse { pub result: bool, + pub headers: Option>, } diff --git a/src/v1/chat_completion.rs b/src/v1/chat_completion.rs index 7f1dda70..cf94c8bd 100644 --- a/src/v1/chat_completion.rs +++ b/src/v1/chat_completion.rs @@ -175,6 +175,7 @@ pub struct ChatCompletionResponse { pub choices: Vec, pub usage: common::Usage, pub system_fingerprint: Option, + pub headers: Option>, } #[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)] diff --git a/src/v1/completion.rs b/src/v1/completion.rs index a5adeafc..c4d347f8 100644 --- a/src/v1/completion.rs +++ b/src/v1/completion.rs @@ -117,4 +117,5 @@ pub struct CompletionResponse { pub model: String, pub choices: Vec, pub usage: common::Usage, + pub headers: Option>, } diff --git a/src/v1/edit.rs b/src/v1/edit.rs index 18cf3834..c47ab014 100644 --- a/src/v1/edit.rs +++ b/src/v1/edit.rs @@ -1,4 +1,5 @@ use serde::{Deserialize, Serialize}; +use std::collections::HashMap; use std::option::Option; use crate::impl_builder_methods; @@ -51,4 +52,5 @@ pub struct EditResponse { pub created: i64, pub usage: common::Usage, pub choices: Vec, + pub headers: Option>, } diff --git a/src/v1/embedding.rs b/src/v1/embedding.rs index ea114142..4abd41fc 100644 --- a/src/v1/embedding.rs +++ b/src/v1/embedding.rs @@ -1,4 +1,5 @@ use serde::{Deserialize, Serialize}; +use std::collections::HashMap; use std::option::Option; use crate::impl_builder_methods; @@ -42,6 +43,7 @@ pub struct EmbeddingResponse { pub data: Vec, pub model: String, pub usage: Usage, + pub headers: Option>, } #[derive(Debug, Deserialize, Serialize)] diff --git a/src/v1/file.rs b/src/v1/file.rs index 248b2f73..4bf1c7eb 100644 --- a/src/v1/file.rs +++ b/src/v1/file.rs @@ -1,3 +1,5 @@ +use std::collections::HashMap; + use serde::{Deserialize, Serialize}; #[derive(Debug, Deserialize, Serialize)] @@ -14,6 +16,7 @@ pub struct FileData { pub struct FileListResponse { pub object: String, pub data: Vec, + pub headers: Option>, } #[derive(Debug, Serialize)] @@ -36,6 +39,7 @@ pub struct FileUploadResponse { pub created_at: i64, pub filename: String, pub purpose: String, + pub headers: Option>, } #[derive(Debug, Serialize)] @@ -54,6 +58,7 @@ pub struct FileDeleteResponse { pub id: String, pub oejct: String, pub delete: bool, + pub headers: Option>, } #[derive(Debug, Serialize)] @@ -75,6 +80,7 @@ pub struct FileRetrieveResponse { pub created_at: i64, pub filename: String, pub purpose: String, + pub headers: Option>, } #[derive(Debug, Serialize)] @@ -96,4 +102,5 @@ pub struct FileRetrieveContentResponse { pub created_at: i64, pub filename: String, pub purpose: String, + pub headers: Option>, } diff --git a/src/v1/fine_tuning.rs b/src/v1/fine_tuning.rs index 8d696f94..8408a9d7 100644 --- a/src/v1/fine_tuning.rs +++ b/src/v1/fine_tuning.rs @@ -1,4 +1,5 @@ use serde::{Deserialize, Serialize}; +use std::collections::HashMap; use crate::impl_builder_methods; @@ -98,6 +99,7 @@ pub struct FineTuningPagination { pub object: String, pub data: Vec, pub has_more: bool, + pub headers: Option>, } #[derive(Debug, Deserialize, Serialize)] @@ -116,6 +118,7 @@ pub struct FineTuningJobObject { pub trained_tokens: Option, pub training_file: String, pub validation_file: Option, + pub headers: Option>, } #[derive(Debug, Deserialize, Serialize)] diff --git a/src/v1/image.rs b/src/v1/image.rs index 54e8288f..896b30a0 100644 --- a/src/v1/image.rs +++ b/src/v1/image.rs @@ -1,4 +1,5 @@ use serde::{Deserialize, Serialize}; +use std::collections::HashMap; use std::option::Option; use crate::impl_builder_methods; @@ -49,6 +50,7 @@ impl_builder_methods!( pub struct ImageGenerationResponse { pub created: i64, pub data: Vec, + pub headers: Option>, } #[derive(Debug, Serialize, Clone)] @@ -98,6 +100,7 @@ impl_builder_methods!( pub struct ImageEditResponse { pub created: i64, pub data: Vec, + pub headers: Option>, } #[derive(Debug, Serialize, Clone)] @@ -141,4 +144,5 @@ impl_builder_methods!( pub struct ImageVariationResponse { pub created: i64, pub data: Vec, + pub headers: Option>, } diff --git a/src/v1/message.rs b/src/v1/message.rs index 9e2d81d4..7942dd5e 100644 --- a/src/v1/message.rs +++ b/src/v1/message.rs @@ -67,6 +67,7 @@ pub struct MessageObject { pub run_id: Option, pub file_ids: Vec, pub metadata: HashMap, + pub headers: Option>, } #[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)] @@ -98,6 +99,7 @@ pub struct ListMessage { pub first_id: String, pub last_id: String, pub has_more: bool, + pub headers: Option>, } #[derive(Debug, Deserialize, Serialize)] @@ -106,6 +108,7 @@ pub struct MessageFileObject { pub object: String, pub created_at: i64, pub message_id: String, + pub headers: Option>, } #[derive(Debug, Deserialize, Serialize)] @@ -115,4 +118,5 @@ pub struct ListMessageFile { pub first_id: String, pub last_id: String, pub has_more: bool, + pub headers: Option>, } diff --git a/src/v1/moderation.rs b/src/v1/moderation.rs index 69acece0..b4989ebc 100644 --- a/src/v1/moderation.rs +++ b/src/v1/moderation.rs @@ -1,4 +1,5 @@ use serde::{Deserialize, Serialize}; +use std::collections::HashMap; use crate::impl_builder_methods; @@ -25,6 +26,7 @@ pub struct CreateModerationResponse { pub id: String, pub model: String, pub results: Vec, + pub headers: Option>, } #[derive(Debug, Deserialize, Serialize)] diff --git a/src/v1/run.rs b/src/v1/run.rs index 3bcb0879..392bc5ed 100644 --- a/src/v1/run.rs +++ b/src/v1/run.rs @@ -87,6 +87,7 @@ pub struct RunObject { pub tools: Vec>, pub file_ids: Vec, pub metadata: HashMap, + pub headers: Option>, } #[derive(Debug, Deserialize, Serialize)] @@ -96,6 +97,7 @@ pub struct ListRun { pub first_id: String, pub last_id: String, pub has_more: bool, + pub headers: Option>, } #[derive(Debug, Serialize, Clone)] @@ -138,6 +140,7 @@ pub struct RunStepObject { #[serde(skip_serializing_if = "Option::is_none")] pub completed_at: Option, pub metadata: HashMap, + pub headers: Option>, } #[derive(Debug, Deserialize, Serialize, Clone)] @@ -147,4 +150,5 @@ pub struct ListRunStep { pub first_id: String, pub last_id: String, pub has_more: bool, + pub headers: Option>, } diff --git a/src/v1/thread.rs b/src/v1/thread.rs index 7fa60081..cd591cd3 100644 --- a/src/v1/thread.rs +++ b/src/v1/thread.rs @@ -38,6 +38,7 @@ pub struct ThreadObject { pub object: String, pub created_at: i64, pub metadata: HashMap, + pub headers: Option>, } #[derive(Debug, Deserialize, Serialize, Clone)]