From dd5146351927d698fa59b9162ad77ceab6f96cf2 Mon Sep 17 00:00:00 2001 From: Himanshu Neema Date: Mon, 17 Nov 2025 16:22:54 -0800 Subject: [PATCH 01/22] feat: RequestOptions --- async-openai/Cargo.toml | 1 + async-openai/src/admin_api_keys.rs | 30 ++- async-openai/src/assistants.rs | 18 +- async-openai/src/audio.rs | 8 +- async-openai/src/audit_logs.rs | 10 +- async-openai/src/batches.rs | 15 +- async-openai/src/certificates.rs | 22 +- async-openai/src/chat.rs | 36 +++- async-openai/src/chatkit.rs | 31 ++- async-openai/src/client.rs | 194 ++++++++++++++---- async-openai/src/completion.rs | 11 +- async-openai/src/container_files.rs | 12 +- async-openai/src/containers.rs | 16 +- async-openai/src/conversation_items.rs | 10 +- async-openai/src/conversations.rs | 16 +- async-openai/src/embedding.rs | 12 +- async-openai/src/eval_run_output_items.rs | 7 +- async-openai/src/eval_runs.rs | 13 +- async-openai/src/evals.rs | 18 +- async-openai/src/file.rs | 16 +- async-openai/src/fine_tuning.rs | 22 +- async-openai/src/image.rs | 18 +- async-openai/src/invites.rs | 16 +- async-openai/src/lib.rs | 2 + async-openai/src/messages.rs | 13 +- async-openai/src/model.rs | 14 +- async-openai/src/moderation.rs | 10 +- async-openai/src/project_api_keys.rs | 7 +- async-openai/src/project_certificates.rs | 7 +- async-openai/src/project_rate_limits.rs | 6 +- async-openai/src/project_service_accounts.rs | 8 +- async-openai/src/project_users.rs | 11 +- async-openai/src/projects.rs | 16 +- async-openai/src/realtime.rs | 33 ++- async-openai/src/request_options.rs | 66 ++++++ async-openai/src/responses.rs | 21 +- async-openai/src/runs.rs | 15 +- async-openai/src/speech.rs | 12 +- async-openai/src/steps.rs | 16 +- async-openai/src/threads.rs | 20 +- async-openai/src/traits.rs | 37 ++++ async-openai/src/transcriptions.rs | 18 +- async-openai/src/translations.rs | 14 +- async-openai/src/types/impls.rs | 116 +++++++++++ async-openai/src/uploads.rs | 15 +- async-openai/src/usage.rs | 26 ++- async-openai/src/users.rs | 16 +- async-openai/src/vector_store_file_batches.rs | 9 +- async-openai/src/vector_store_files.rs | 13 +- async-openai/src/vector_stores.rs | 20 +- async-openai/src/video.rs | 18 +- examples/chat/src/main.rs | 7 +- 52 files changed, 868 insertions(+), 270 deletions(-) create mode 100644 async-openai/src/request_options.rs diff --git a/async-openai/Cargo.toml b/async-openai/Cargo.toml index 354dae89..d38ae00d 100644 --- a/async-openai/Cargo.toml +++ b/async-openai/Cargo.toml @@ -50,6 +50,7 @@ derive_builder = "0.20.2" secrecy = { version = "0.10.3", features = ["serde"] } bytes = "1.9.0" eventsource-stream = "0.2.3" +serde_urlencoded = "0.7.1" tokio-tungstenite = { version = "0.26.1", optional = true, default-features = false } hmac = { version = "0.12", optional = true, default-features = false} sha2 = { version = "0.10", optional = true, default-features = false } diff --git a/async-openai/src/admin_api_keys.rs b/async-openai/src/admin_api_keys.rs index 20b58a53..96ceff93 100644 --- a/async-openai/src/admin_api_keys.rs +++ b/async-openai/src/admin_api_keys.rs @@ -6,7 +6,7 @@ use crate::{ types::admin::api_keys::{ AdminApiKey, AdminApiKeyDeleteResponse, ApiKeyList, CreateAdminApiKeyRequest, }, - Client, + Client, RequestOptions, }; /// Admin API keys enable Organization Owners to programmatically manage various aspects of their @@ -14,11 +14,15 @@ use crate::{ /// allowing you to automate organization management tasks. pub struct AdminAPIKeys<'c, C: Config> { client: &'c Client, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> AdminAPIKeys<'c, C> { pub fn new(client: &'c Client) -> Self { - Self { client } + Self { + client, + request_options: RequestOptions::new(), + } } /// List all organization and project API keys. @@ -28,7 +32,11 @@ impl<'c, C: Config> AdminAPIKeys<'c, C> { Q: Serialize + ?Sized, { self.client - .get_with_query("/organization/admin_api_keys", &query) + .get_with_query( + "/organization/admin_api_keys", + &query, + &self.request_options, + ) .await } @@ -38,7 +46,11 @@ impl<'c, C: Config> AdminAPIKeys<'c, C> { request: CreateAdminApiKeyRequest, ) -> Result { self.client - .post("/organization/admin_api_keys", request) + .post( + "/organization/admin_api_keys", + request, + &self.request_options, + ) .await } @@ -46,7 +58,10 @@ impl<'c, C: Config> AdminAPIKeys<'c, C> { #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, key_id: &str) -> Result { self.client - .get(format!("/organization/admin_api_keys/{key_id}").as_str()) + .get( + format!("/organization/admin_api_keys/{key_id}").as_str(), + &self.request_options, + ) .await } @@ -54,7 +69,10 @@ impl<'c, C: Config> AdminAPIKeys<'c, C> { #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn delete(&self, key_id: &str) -> Result { self.client - .delete(format!("/organization/admin_api_keys/{key_id}").as_str()) + .delete( + format!("/organization/admin_api_keys/{key_id}").as_str(), + &self.request_options, + ) .await } } diff --git a/async-openai/src/assistants.rs b/async-openai/src/assistants.rs index abca6d75..196b3524 100644 --- a/async-openai/src/assistants.rs +++ b/async-openai/src/assistants.rs @@ -7,7 +7,7 @@ use crate::{ AssistantObject, CreateAssistantRequest, DeleteAssistantResponse, ListAssistantsResponse, ModifyAssistantRequest, }, - Client, + Client, RequestOptions, }; /// Build assistants that can call models and use tools to perform tasks. @@ -15,11 +15,15 @@ use crate::{ /// [Get started with the Assistants API](https://platform.openai.com/docs/assistants) pub struct Assistants<'c, C: Config> { client: &'c Client, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> Assistants<'c, C> { pub fn new(client: &'c Client) -> Self { - Self { client } + Self { + client, + request_options: RequestOptions::new(), + } } /// Create an assistant with a model and instructions. @@ -28,14 +32,14 @@ impl<'c, C: Config> Assistants<'c, C> { &self, request: CreateAssistantRequest, ) -> Result { - self.client.post("/assistants", request).await + self.client.post("/assistants", request, &self.request_options).await } /// Retrieves an assistant. #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, assistant_id: &str) -> Result { self.client - .get(&format!("/assistants/{assistant_id}")) + .get(&format!("/assistants/{assistant_id}"), &self.request_options) .await } @@ -47,7 +51,7 @@ impl<'c, C: Config> Assistants<'c, C> { request: ModifyAssistantRequest, ) -> Result { self.client - .post(&format!("/assistants/{assistant_id}"), request) + .post(&format!("/assistants/{assistant_id}"), request, &self.request_options) .await } @@ -55,7 +59,7 @@ impl<'c, C: Config> Assistants<'c, C> { #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn delete(&self, assistant_id: &str) -> Result { self.client - .delete(&format!("/assistants/{assistant_id}")) + .delete(&format!("/assistants/{assistant_id}"), &self.request_options) .await } @@ -65,6 +69,6 @@ impl<'c, C: Config> Assistants<'c, C> { where Q: Serialize + ?Sized, { - self.client.get_with_query("/assistants", &query).await + self.client.get_with_query("/assistants", &query, &self.request_options).await } } diff --git a/async-openai/src/audio.rs b/async-openai/src/audio.rs index 8993eb25..027f42b4 100644 --- a/async-openai/src/audio.rs +++ b/async-openai/src/audio.rs @@ -1,14 +1,18 @@ -use crate::{config::Config, Client, Speech, Transcriptions, Translations}; +use crate::{config::Config, Client, RequestOptions, Speech, Transcriptions, Translations}; /// Turn audio into text or text into audio. /// Related guide: [Speech to text](https://platform.openai.com/docs/guides/speech-to-text) pub struct Audio<'c, C: Config> { client: &'c Client, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> Audio<'c, C> { pub fn new(client: &'c Client) -> Self { - Self { client } + Self { + client, + request_options: RequestOptions::new(), + } } /// APIs in Speech group. diff --git a/async-openai/src/audit_logs.rs b/async-openai/src/audit_logs.rs index 7f09f9df..e170db90 100644 --- a/async-openai/src/audit_logs.rs +++ b/async-openai/src/audit_logs.rs @@ -1,7 +1,7 @@ use serde::Serialize; use crate::{ - config::Config, error::OpenAIError, types::admin::audit_logs::ListAuditLogsResponse, Client, + config::Config, error::OpenAIError, types::admin::audit_logs::ListAuditLogsResponse, Client, RequestOptions, }; /// Logs of user actions and configuration changes within this organization. @@ -9,11 +9,15 @@ use crate::{ /// Once activated, for security reasons, logging cannot be deactivated. pub struct AuditLogs<'c, C: Config> { client: &'c Client, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> AuditLogs<'c, C> { pub fn new(client: &'c Client) -> Self { - Self { client } + Self { + client, + request_options: RequestOptions::new(), + } } /// List user actions and configuration changes within this organization. @@ -23,7 +27,7 @@ impl<'c, C: Config> AuditLogs<'c, C> { Q: Serialize + ?Sized, { self.client - .get_with_query("/organization/audit_logs", &query) + .get_with_query("/organization/audit_logs", &query, &self.request_options) .await } } diff --git a/async-openai/src/batches.rs b/async-openai/src/batches.rs index efa5b0da..df62ca9c 100644 --- a/async-openai/src/batches.rs +++ b/async-openai/src/batches.rs @@ -4,7 +4,7 @@ use crate::{ config::Config, error::OpenAIError, types::batches::{Batch, BatchRequest, ListBatchesResponse}, - Client, + Client, RequestOptions, }; /// Create large batches of API requests for asynchronous processing. The Batch API returns completions within 24 hours for a 50% discount. @@ -12,17 +12,21 @@ use crate::{ /// Related guide: [Batch](https://platform.openai.com/docs/guides/batch) pub struct Batches<'c, C: Config> { client: &'c Client, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> Batches<'c, C> { pub fn new(client: &'c Client) -> Self { - Self { client } + Self { + client, + request_options: RequestOptions::new(), + } } /// Creates and executes a batch from an uploaded file of requests #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] pub async fn create(&self, request: BatchRequest) -> Result { - self.client.post("/batches", request).await + self.client.post("/batches", request, &self.request_options).await } /// List your organization's batches. @@ -31,13 +35,13 @@ impl<'c, C: Config> Batches<'c, C> { where Q: Serialize + ?Sized, { - self.client.get_with_query("/batches", &query).await + self.client.get_with_query("/batches", &query, &self.request_options).await } /// Retrieves a batch. #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, batch_id: &str) -> Result { - self.client.get(&format!("/batches/{batch_id}")).await + self.client.get(&format!("/batches/{batch_id}"), &self.request_options).await } /// Cancels an in-progress batch. The batch will be in status `cancelling` for up to 10 minutes, before changing to `cancelled`, where it will have partial results (if any) available in the output file. @@ -47,6 +51,7 @@ impl<'c, C: Config> Batches<'c, C> { .post( &format!("/batches/{batch_id}/cancel"), serde_json::json!({}), + &self.request_options, ) .await } diff --git a/async-openai/src/certificates.rs b/async-openai/src/certificates.rs index 44048fc5..9eee1c0e 100644 --- a/async-openai/src/certificates.rs +++ b/async-openai/src/certificates.rs @@ -7,18 +7,22 @@ use crate::{ Certificate, DeleteCertificateResponse, ListCertificatesResponse, ModifyCertificateRequest, ToggleCertificatesRequest, UploadCertificateRequest, }, - Client, + Client, RequestOptions, }; /// Certificates enable Mutual TLS (mTLS) authentication for your organization. /// Manage certificates at the organization level. pub struct Certificates<'c, C: Config> { client: &'c Client, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> Certificates<'c, C> { pub fn new(client: &'c Client) -> Self { - Self { client } + Self { + client, + request_options: RequestOptions::new(), + } } // Organization-level certificate operations @@ -33,7 +37,7 @@ impl<'c, C: Config> Certificates<'c, C> { Q: Serialize + ?Sized, { self.client - .get_with_query("/organization/certificates", &query) + .get_with_query("/organization/certificates", &query, &self.request_options) .await } @@ -44,7 +48,7 @@ impl<'c, C: Config> Certificates<'c, C> { request: UploadCertificateRequest, ) -> Result { self.client - .post("/organization/certificates", request) + .post("/organization/certificates", request, &self.request_options) .await } @@ -55,7 +59,7 @@ impl<'c, C: Config> Certificates<'c, C> { request: ToggleCertificatesRequest, ) -> Result { self.client - .post("/organization/certificates/activate", request) + .post("/organization/certificates/activate", request, &self.request_options) .await } @@ -66,7 +70,7 @@ impl<'c, C: Config> Certificates<'c, C> { request: ToggleCertificatesRequest, ) -> Result { self.client - .post("/organization/certificates/deactivate", request) + .post("/organization/certificates/deactivate", request, &self.request_options) .await } @@ -74,7 +78,7 @@ impl<'c, C: Config> Certificates<'c, C> { #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, certificate_id: &str) -> Result { self.client - .get(format!("/organization/certificates/{certificate_id}").as_str()) + .get(format!("/organization/certificates/{certificate_id}").as_str(), &self.request_options) .await } @@ -91,6 +95,7 @@ impl<'c, C: Config> Certificates<'c, C> { .get_with_query( format!("/organization/certificates/{certificate_id}").as_str(), query, + &self.request_options, ) .await } @@ -106,6 +111,7 @@ impl<'c, C: Config> Certificates<'c, C> { .post( format!("/organization/certificates/{certificate_id}").as_str(), request, + &self.request_options, ) .await } @@ -118,7 +124,7 @@ impl<'c, C: Config> Certificates<'c, C> { certificate_id: &str, ) -> Result { self.client - .delete(format!("/organization/certificates/{certificate_id}").as_str()) + .delete(format!("/organization/certificates/{certificate_id}").as_str(), &self.request_options) .await } } diff --git a/async-openai/src/chat.rs b/async-openai/src/chat.rs index e826e4f5..fde09594 100644 --- a/async-openai/src/chat.rs +++ b/async-openai/src/chat.rs @@ -8,7 +8,7 @@ use crate::{ ChatCompletionResponseStream, CreateChatCompletionRequest, CreateChatCompletionResponse, UpdateChatCompletionRequest, }, - Client, + Client, RequestOptions, }; /// Given a list of messages comprising a conversation, the model will return a response. @@ -16,11 +16,15 @@ use crate::{ /// Related guide: [Chat Completions](https://platform.openai.com/docs/guides/text-generation) pub struct Chat<'c, C: Config> { client: &'c Client, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> Chat<'c, C> { pub fn new(client: &'c Client) -> Self { - Self { client } + Self { + client, + request_options: RequestOptions::new(), + } } /// Creates a model response for the given chat conversation. @@ -48,7 +52,9 @@ impl<'c, C: Config> Chat<'c, C> { )); } } - self.client.post("/chat/completions", request).await + self.client + .post("/chat/completions", request, &self.request_options) + .await } /// Creates a completion for the chat message. @@ -81,7 +87,10 @@ impl<'c, C: Config> Chat<'c, C> { request.stream = Some(true); } - Ok(self.client.post_stream("/chat/completions", request).await) + Ok(self + .client + .post_stream("/chat/completions", request, &self.request_options) + .await) } /// List stored Chat Completions. Only Chat Completions that have been stored @@ -92,7 +101,7 @@ impl<'c, C: Config> Chat<'c, C> { Q: Serialize + ?Sized, { self.client - .get_with_query("/chat/completions", &query) + .get_with_query("/chat/completions", &query, &self.request_options) .await } @@ -104,7 +113,10 @@ impl<'c, C: Config> Chat<'c, C> { completion_id: &str, ) -> Result { self.client - .get(&format!("/chat/completions/{completion_id}")) + .get( + &format!("/chat/completions/{completion_id}"), + &self.request_options, + ) .await } @@ -122,7 +134,11 @@ impl<'c, C: Config> Chat<'c, C> { request: UpdateChatCompletionRequest, ) -> Result { self.client - .post(&format!("/chat/completions/{completion_id}"), request) + .post( + &format!("/chat/completions/{completion_id}"), + request, + &self.request_options, + ) .await } @@ -131,7 +147,10 @@ impl<'c, C: Config> Chat<'c, C> { #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn delete(&self, completion_id: &str) -> Result { self.client - .delete(&format!("/chat/completions/{completion_id}")) + .delete( + &format!("/chat/completions/{completion_id}"), + &self.request_options, + ) .await } @@ -149,6 +168,7 @@ impl<'c, C: Config> Chat<'c, C> { .get_with_query( &format!("/chat/completions/{completion_id}/messages"), &query, + &self.request_options, ) .await } diff --git a/async-openai/src/chatkit.rs b/async-openai/src/chatkit.rs index 3eb795fb..17161108 100644 --- a/async-openai/src/chatkit.rs +++ b/async-openai/src/chatkit.rs @@ -7,7 +7,7 @@ use crate::{ ChatSessionResource, CreateChatSessionBody, DeletedThreadResource, ThreadItemListResource, ThreadListResource, ThreadResource, }, - Client, + Client, RequestOptions, }; /// ChatKit API for managing sessions and threads. @@ -15,11 +15,15 @@ use crate::{ /// Related guide: [ChatKit](https://platform.openai.com/docs/api-reference/chatkit) pub struct Chatkit<'c, C: Config> { client: &'c Client, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> Chatkit<'c, C> { pub fn new(client: &'c Client) -> Self { - Self { client } + Self { + client, + request_options: RequestOptions::new(), + } } /// Access sessions API. @@ -36,11 +40,15 @@ impl<'c, C: Config> Chatkit<'c, C> { /// ChatKit sessions API. pub struct ChatkitSessions<'c, C: Config> { client: &'c Client, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> ChatkitSessions<'c, C> { pub fn new(client: &'c Client) -> Self { - Self { client } + Self { + client, + request_options: RequestOptions::new(), + } } /// Create a ChatKit session. @@ -49,7 +57,7 @@ impl<'c, C: Config> ChatkitSessions<'c, C> { &self, request: CreateChatSessionBody, ) -> Result { - self.client.post("/chatkit/sessions", request).await + self.client.post("/chatkit/sessions", request, &self.request_options).await } /// Cancel a ChatKit session. @@ -59,6 +67,7 @@ impl<'c, C: Config> ChatkitSessions<'c, C> { .post( &format!("/chatkit/sessions/{session_id}/cancel"), serde_json::json!({}), + &self.request_options, ) .await } @@ -67,11 +76,15 @@ impl<'c, C: Config> ChatkitSessions<'c, C> { /// ChatKit threads API. pub struct ChatkitThreads<'c, C: Config> { client: &'c Client, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> ChatkitThreads<'c, C> { pub fn new(client: &'c Client) -> Self { - Self { client } + Self { + client, + request_options: RequestOptions::new(), + } } /// List ChatKit threads. @@ -80,14 +93,14 @@ impl<'c, C: Config> ChatkitThreads<'c, C> { where Q: Serialize + ?Sized, { - self.client.get_with_query("/chatkit/threads", &query).await + self.client.get_with_query("/chatkit/threads", &query, &self.request_options).await } /// Retrieve a ChatKit thread. #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, thread_id: &str) -> Result { self.client - .get(&format!("/chatkit/threads/{thread_id}")) + .get(&format!("/chatkit/threads/{thread_id}"), &self.request_options) .await } @@ -95,7 +108,7 @@ impl<'c, C: Config> ChatkitThreads<'c, C> { #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn delete(&self, thread_id: &str) -> Result { self.client - .delete(&format!("/chatkit/threads/{thread_id}")) + .delete(&format!("/chatkit/threads/{thread_id}"), &self.request_options) .await } @@ -110,7 +123,7 @@ impl<'c, C: Config> ChatkitThreads<'c, C> { Q: Serialize + ?Sized, { self.client - .get_with_query(&format!("/chatkit/threads/{thread_id}/items"), &query) + .get_with_query(&format!("/chatkit/threads/{thread_id}/items"), &query, &self.request_options) .await } } diff --git a/async-openai/src/client.rs b/async-openai/src/client.rs index ec8363dd..b9ca1f3a 100644 --- a/async-openai/src/client.rs +++ b/async-openai/src/client.rs @@ -16,7 +16,7 @@ use crate::{ moderation::Moderations, traits::AsyncTryFrom, Assistants, Audio, Batches, Chat, Completions, Containers, Conversations, Embeddings, Evals, - FineTuning, Models, Responses, Threads, Uploads, Usage, VectorStores, Videos, + FineTuning, Models, RequestOptions, Responses, Threads, Uploads, Usage, VectorStores, Videos, }; #[cfg(feature = "realtime")] @@ -198,53 +198,93 @@ impl Client { } /// Make a GET request to {path} and deserialize the response body - pub(crate) async fn get(&self, path: &str) -> Result + pub(crate) async fn get( + &self, + path: &str, + request_options: &RequestOptions, + ) -> Result where O: DeserializeOwned, { let request_maker = || async { - Ok(self + let mut request_builder = self .http_client .get(self.config.url(path)) .query(&self.config.query()) - .headers(self.config.headers()) - .build()?) + .headers(self.config.headers()); + + if let Some(headers) = request_options.headers() { + request_builder = request_builder.headers(headers.clone()); + } + + if let Some(query) = request_options.query() { + request_builder = request_builder.query(query); + } + + Ok(request_builder.build()?) }; self.execute(request_maker).await } /// Make a GET request to {path} with given Query and deserialize the response body - pub(crate) async fn get_with_query(&self, path: &str, query: &Q) -> Result + pub(crate) async fn get_with_query( + &self, + path: &str, + query: &Q, + request_options: &RequestOptions, + ) -> Result where O: DeserializeOwned, Q: Serialize + ?Sized, { let request_maker = || async { - Ok(self + let mut request_builder = self .http_client .get(self.config.url(path)) .query(&self.config.query()) .query(query) - .headers(self.config.headers()) - .build()?) + .headers(self.config.headers()); + + if let Some(headers) = request_options.headers() { + request_builder = request_builder.headers(headers.clone()); + } + + if let Some(query_str) = request_options.query() { + request_builder = request_builder.query(query_str); + } + + Ok(request_builder.build()?) }; self.execute(request_maker).await } /// Make a DELETE request to {path} and deserialize the response body - pub(crate) async fn delete(&self, path: &str) -> Result + pub(crate) async fn delete( + &self, + path: &str, + request_options: &RequestOptions, + ) -> Result where O: DeserializeOwned, { let request_maker = || async { - Ok(self + let mut request_builder = self .http_client .delete(self.config.url(path)) .query(&self.config.query()) - .headers(self.config.headers()) - .build()?) + .headers(self.config.headers()); + + if let Some(headers) = request_options.headers() { + request_builder = request_builder.headers(headers.clone()); + } + + if let Some(query) = request_options.query() { + request_builder = request_builder.query(query); + } + + Ok(request_builder.build()?) }; self.execute(request_maker).await @@ -290,37 +330,61 @@ impl Client { &self, path: &str, request: I, + request_options: &RequestOptions, ) -> Result<(Bytes, HeaderMap), OpenAIError> where I: Serialize, { let request_maker = || async { - Ok(self + let mut request_builder = self .http_client .post(self.config.url(path)) .query(&self.config.query()) .headers(self.config.headers()) - .json(&request) - .build()?) + .json(&request); + + if let Some(headers) = request_options.headers() { + request_builder = request_builder.headers(headers.clone()); + } + + if let Some(query) = request_options.query() { + request_builder = request_builder.query(query); + } + + Ok(request_builder.build()?) }; self.execute_raw(request_maker).await } /// Make a POST request to {path} and deserialize the response body - pub(crate) async fn post(&self, path: &str, request: I) -> Result + pub(crate) async fn post( + &self, + path: &str, + request: I, + request_options: &RequestOptions, + ) -> Result where I: Serialize, O: DeserializeOwned, { let request_maker = || async { - Ok(self + let mut request_builder = self .http_client .post(self.config.url(path)) .query(&self.config.query()) .headers(self.config.headers()) - .json(&request) - .build()?) + .json(&request); + + if let Some(headers) = request_options.headers() { + request_builder = request_builder.headers(headers.clone()); + } + + if let Some(query) = request_options.query() { + request_builder = request_builder.query(query); + } + + Ok(request_builder.build()?) }; self.execute(request_maker).await @@ -331,39 +395,63 @@ impl Client { &self, path: &str, form: F, + request_options: &RequestOptions, ) -> Result<(Bytes, HeaderMap), OpenAIError> where Form: AsyncTryFrom, F: Clone, { let request_maker = || async { - Ok(self + let mut request_builder = self .http_client .post(self.config.url(path)) .query(&self.config.query()) .headers(self.config.headers()) - .multipart(
>::try_from(form.clone()).await?) - .build()?) + .multipart(>::try_from(form.clone()).await?); + + if let Some(headers) = request_options.headers() { + request_builder = request_builder.headers(headers.clone()); + } + + if let Some(query) = request_options.query() { + request_builder = request_builder.query(query); + } + + Ok(request_builder.build()?) }; self.execute_raw(request_maker).await } /// POST a form at {path} and deserialize the response body - pub(crate) async fn post_form(&self, path: &str, form: F) -> Result + pub(crate) async fn post_form( + &self, + path: &str, + form: F, + request_options: &RequestOptions, + ) -> Result where O: DeserializeOwned, Form: AsyncTryFrom, F: Clone, { let request_maker = || async { - Ok(self + let mut request_builder = self .http_client .post(self.config.url(path)) .query(&self.config.query()) .headers(self.config.headers()) - .multipart(>::try_from(form.clone()).await?) - .build()?) + .multipart(>::try_from(form.clone()).await?); + + if let Some(headers) = request_options.headers() { + request_builder = request_builder.headers(headers.clone()); + } + + if let Some(query) = request_options.query() { + request_builder = request_builder.query(query); + } + + Ok(request_builder.build()?) }; self.execute(request_maker).await @@ -373,6 +461,7 @@ impl Client { &self, path: &str, form: F, + request_options: &RequestOptions, ) -> Result> + Send>>, OpenAIError> where F: Clone, @@ -381,15 +470,22 @@ impl Client { { // Build and execute request manually since multipart::Form is not Clone // and .eventsource() requires cloneability - let response = self + let mut request_builder = self .http_client .post(self.config.url(path)) .query(&self.config.query()) .multipart(>::try_from(form.clone()).await?) - .headers(self.config.headers()) - .send() - .await - .map_err(OpenAIError::Reqwest)?; + .headers(self.config.headers()); + + if let Some(headers) = request_options.headers() { + request_builder = request_builder.headers(headers.clone()); + } + + if let Some(query) = request_options.query() { + request_builder = request_builder.query(query); + } + + let response = request_builder.send().await.map_err(OpenAIError::Reqwest)?; // Check for error status if !response.status().is_success() { @@ -519,19 +615,28 @@ impl Client { &self, path: &str, request: I, + request_options: &RequestOptions, ) -> Pin> + Send>> where I: Serialize, O: DeserializeOwned + std::marker::Send + 'static, { - let event_source = self + let mut request_builder = self .http_client .post(self.config.url(path)) .query(&self.config.query()) .headers(self.config.headers()) - .json(&request) - .eventsource() - .unwrap(); + .json(&request); + + if let Some(headers) = request_options.headers() { + request_builder = request_builder.headers(headers.clone()); + } + + if let Some(query) = request_options.query() { + request_builder = request_builder.query(query); + } + + let event_source = request_builder.eventsource().unwrap(); stream(event_source).await } @@ -540,20 +645,29 @@ impl Client { &self, path: &str, request: I, + request_options: &RequestOptions, event_mapper: impl Fn(eventsource_stream::Event) -> Result + Send + 'static, ) -> Pin> + Send>> where I: Serialize, O: DeserializeOwned + std::marker::Send + 'static, { - let event_source = self + let mut request_builder = self .http_client .post(self.config.url(path)) .query(&self.config.query()) .headers(self.config.headers()) - .json(&request) - .eventsource() - .unwrap(); + .json(&request); + + if let Some(headers) = request_options.headers() { + request_builder = request_builder.headers(headers.clone()); + } + + if let Some(query) = request_options.query() { + request_builder = request_builder.query(query); + } + + let event_source = request_builder.eventsource().unwrap(); stream_mapped_raw_events(event_source, event_mapper).await } diff --git a/async-openai/src/completion.rs b/async-openai/src/completion.rs index 432201c3..56fc02a3 100644 --- a/async-openai/src/completion.rs +++ b/async-openai/src/completion.rs @@ -3,6 +3,7 @@ use crate::{ config::Config, error::OpenAIError, types::{CompletionResponseStream, CreateCompletionRequest, CreateCompletionResponse}, + RequestOptions, }; /// Given a prompt, the model will return one or more predicted completions, @@ -13,11 +14,15 @@ use crate::{ /// Related guide: [Legacy Completions](https://platform.openai.com/docs/guides/gpt/completions-api) pub struct Completions<'c, C: Config> { client: &'c Client, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> Completions<'c, C> { pub fn new(client: &'c Client) -> Self { - Self { client } + Self { + client, + request_options: RequestOptions::new(), + } } /// Creates a completion for the provided prompt and parameters @@ -39,7 +44,7 @@ impl<'c, C: Config> Completions<'c, C> { )); } } - self.client.post("/completions", request).await + self.client.post("/completions", request, &self.request_options).await } /// Creates a completion request for the provided prompt and parameters @@ -72,6 +77,6 @@ impl<'c, C: Config> Completions<'c, C> { request.stream = Some(true); } - Ok(self.client.post_stream("/completions", request).await) + Ok(self.client.post_stream("/completions", request, &self.request_options).await) } } diff --git a/async-openai/src/container_files.rs b/async-openai/src/container_files.rs index fd0f03d3..7a25fe51 100644 --- a/async-openai/src/container_files.rs +++ b/async-openai/src/container_files.rs @@ -8,13 +8,14 @@ use crate::{ ContainerFileListResource, ContainerFileResource, CreateContainerFileRequest, DeleteContainerFileResponse, }, - Client, + Client, RequestOptions, }; /// Create and manage container files for use with the Code Interpreter tool. pub struct ContainerFiles<'c, C: Config> { client: &'c Client, container_id: String, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> ContainerFiles<'c, C> { @@ -22,6 +23,7 @@ impl<'c, C: Config> ContainerFiles<'c, C> { Self { client, container_id: container_id.to_string(), + request_options: RequestOptions::new(), } } @@ -36,7 +38,7 @@ impl<'c, C: Config> ContainerFiles<'c, C> { request: CreateContainerFileRequest, ) -> Result { self.client - .post_form(&format!("/containers/{}/files", self.container_id), request) + .post_form(&format!("/containers/{}/files", self.container_id), request, &self.request_options) .await } @@ -47,7 +49,7 @@ impl<'c, C: Config> ContainerFiles<'c, C> { Q: Serialize + ?Sized, { self.client - .get_with_query(&format!("/containers/{}/files", self.container_id), &query) + .get_with_query(&format!("/containers/{}/files", self.container_id), &query, &self.request_options) .await } @@ -55,7 +57,7 @@ impl<'c, C: Config> ContainerFiles<'c, C> { #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, file_id: &str) -> Result { self.client - .get(format!("/containers/{}/files/{file_id}", self.container_id).as_str()) + .get(format!("/containers/{}/files/{file_id}", self.container_id).as_str(), &self.request_options) .await } @@ -63,7 +65,7 @@ impl<'c, C: Config> ContainerFiles<'c, C> { #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn delete(&self, file_id: &str) -> Result { self.client - .delete(format!("/containers/{}/files/{file_id}", self.container_id).as_str()) + .delete(format!("/containers/{}/files/{file_id}", self.container_id).as_str(), &self.request_options) .await } diff --git a/async-openai/src/containers.rs b/async-openai/src/containers.rs index 7254bccf..3871f8b9 100644 --- a/async-openai/src/containers.rs +++ b/async-openai/src/containers.rs @@ -7,16 +7,20 @@ use crate::{ types::containers::{ ContainerListResource, ContainerResource, CreateContainerRequest, DeleteContainerResponse, }, - Client, + Client, RequestOptions, }; pub struct Containers<'c, C: Config> { client: &'c Client, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> Containers<'c, C> { pub fn new(client: &'c Client) -> Self { - Self { client } + Self { + client, + request_options: RequestOptions::new(), + } } /// [ContainerFiles] API group @@ -30,7 +34,7 @@ impl<'c, C: Config> Containers<'c, C> { &self, request: CreateContainerRequest, ) -> Result { - self.client.post("/containers", request).await + self.client.post("/containers", request, &self.request_options).await } /// List containers. @@ -39,14 +43,14 @@ impl<'c, C: Config> Containers<'c, C> { where Q: Serialize + ?Sized, { - self.client.get_with_query("/containers", &query).await + self.client.get_with_query("/containers", &query, &self.request_options).await } /// Retrieve a container. #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, container_id: &str) -> Result { self.client - .get(format!("/containers/{container_id}").as_str()) + .get(format!("/containers/{container_id}").as_str(), &self.request_options) .await } @@ -54,7 +58,7 @@ impl<'c, C: Config> Containers<'c, C> { #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn delete(&self, container_id: &str) -> Result { self.client - .delete(format!("/containers/{container_id}").as_str()) + .delete(format!("/containers/{container_id}").as_str(), &self.request_options) .await } } diff --git a/async-openai/src/conversation_items.rs b/async-openai/src/conversation_items.rs index f58cd162..a86e77d8 100644 --- a/async-openai/src/conversation_items.rs +++ b/async-openai/src/conversation_items.rs @@ -7,13 +7,14 @@ use crate::{ ConversationItem, ConversationItemList, ConversationResource, CreateConversationItemsRequest, }, - Client, + Client, RequestOptions, }; /// Conversation items represent items within a conversation. pub struct ConversationItems<'c, C: Config> { client: &'c Client, pub conversation_id: String, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> ConversationItems<'c, C> { @@ -21,6 +22,7 @@ impl<'c, C: Config> ConversationItems<'c, C> { Self { client, conversation_id: conversation_id.into(), + request_options: RequestOptions::new(), } } @@ -34,6 +36,7 @@ impl<'c, C: Config> ConversationItems<'c, C> { .post( &format!("/conversations/{}/items", &self.conversation_id), request, + &self.request_options, ) .await } @@ -48,6 +51,7 @@ impl<'c, C: Config> ConversationItems<'c, C> { .get_with_query( &format!("/conversations/{}/items", &self.conversation_id), &query, + &self.request_options, ) .await } @@ -59,7 +63,7 @@ impl<'c, C: Config> ConversationItems<'c, C> { .get(&format!( "/conversations/{}/items/{item_id}", &self.conversation_id - )) + ), &self.request_options) .await } @@ -70,7 +74,7 @@ impl<'c, C: Config> ConversationItems<'c, C> { .delete(&format!( "/conversations/{}/items/{item_id}", &self.conversation_id - )) + ), &self.request_options) .await } } diff --git a/async-openai/src/conversations.rs b/async-openai/src/conversations.rs index 41c0cee8..1f2bbf10 100644 --- a/async-openai/src/conversations.rs +++ b/async-openai/src/conversations.rs @@ -6,16 +6,20 @@ use crate::{ ConversationResource, CreateConversationRequest, DeleteConversationResponse, UpdateConversationRequest, }, - Client, + Client, RequestOptions, }; pub struct Conversations<'c, C: Config> { client: &'c Client, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> Conversations<'c, C> { pub fn new(client: &'c Client) -> Self { - Self { client } + Self { + client, + request_options: RequestOptions::new(), + } } /// [ConversationItems] API group @@ -29,7 +33,7 @@ impl<'c, C: Config> Conversations<'c, C> { &self, request: CreateConversationRequest, ) -> Result { - self.client.post("/conversations", request).await + self.client.post("/conversations", request, &self.request_options).await } /// Retrieves a conversation. @@ -39,7 +43,7 @@ impl<'c, C: Config> Conversations<'c, C> { conversation_id: &str, ) -> Result { self.client - .get(&format!("/conversations/{conversation_id}")) + .get(&format!("/conversations/{conversation_id}"), &self.request_options) .await } @@ -50,7 +54,7 @@ impl<'c, C: Config> Conversations<'c, C> { conversation_id: &str, ) -> Result { self.client - .delete(&format!("/conversations/{conversation_id}")) + .delete(&format!("/conversations/{conversation_id}"), &self.request_options) .await } @@ -62,7 +66,7 @@ impl<'c, C: Config> Conversations<'c, C> { request: UpdateConversationRequest, ) -> Result { self.client - .post(&format!("/conversations/{conversation_id}"), request) + .post(&format!("/conversations/{conversation_id}"), request, &self.request_options) .await } } diff --git a/async-openai/src/embedding.rs b/async-openai/src/embedding.rs index 7b7f4395..9044c312 100644 --- a/async-openai/src/embedding.rs +++ b/async-openai/src/embedding.rs @@ -4,7 +4,7 @@ use crate::{ types::embeddings::{ CreateBase64EmbeddingResponse, CreateEmbeddingRequest, CreateEmbeddingResponse, }, - Client, + Client, RequestOptions, }; #[cfg(not(feature = "byot"))] @@ -16,11 +16,15 @@ use crate::types::embeddings::EncodingFormat; /// Related guide: [Embeddings](https://platform.openai.com/docs/guides/embeddings) pub struct Embeddings<'c, C: Config> { client: &'c Client, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> Embeddings<'c, C> { pub fn new(client: &'c Client) -> Self { - Self { client } + Self { + client, + request_options: RequestOptions::new(), + } } /// Creates an embedding vector representing the input text. @@ -39,7 +43,7 @@ impl<'c, C: Config> Embeddings<'c, C> { )); } } - self.client.post("/embeddings", request).await + self.client.post("/embeddings", request, &self.request_options).await } /// Creates an embedding vector representing the input text. @@ -60,7 +64,7 @@ impl<'c, C: Config> Embeddings<'c, C> { )); } } - self.client.post("/embeddings", request).await + self.client.post("/embeddings", request, &self.request_options).await } } diff --git a/async-openai/src/eval_run_output_items.rs b/async-openai/src/eval_run_output_items.rs index 7e89b8e2..fe3d8072 100644 --- a/async-openai/src/eval_run_output_items.rs +++ b/async-openai/src/eval_run_output_items.rs @@ -4,13 +4,14 @@ use crate::{ config::Config, error::OpenAIError, types::evals::{EvalRunOutputItem, EvalRunOutputItemList}, - Client, + Client, RequestOptions, }; pub struct EvalRunOutputItems<'c, C: Config> { client: &'c Client, pub eval_id: String, pub run_id: String, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> EvalRunOutputItems<'c, C> { @@ -19,6 +20,7 @@ impl<'c, C: Config> EvalRunOutputItems<'c, C> { client, eval_id: eval_id.into(), run_id: run_id.into(), + request_options: RequestOptions::new(), } } @@ -32,6 +34,7 @@ impl<'c, C: Config> EvalRunOutputItems<'c, C> { .get_with_query( &format!("/evals/{}/runs/{}/output_items", self.eval_id, self.run_id), &query, + &self.request_options, ) .await } @@ -43,7 +46,7 @@ impl<'c, C: Config> EvalRunOutputItems<'c, C> { .get(&format!( "/evals/{}/runs/{}/output_items/{}", self.eval_id, self.run_id, output_item_id - )) + ), &self.request_options) .await } } diff --git a/async-openai/src/eval_runs.rs b/async-openai/src/eval_runs.rs index f19e6dc7..8415335c 100644 --- a/async-openai/src/eval_runs.rs +++ b/async-openai/src/eval_runs.rs @@ -5,12 +5,13 @@ use crate::{ error::OpenAIError, eval_run_output_items::EvalRunOutputItems, types::evals::{CreateEvalRunRequest, DeleteEvalRunResponse, EvalRun, EvalRunList}, - Client, + Client, RequestOptions, }; pub struct EvalRuns<'c, C: Config> { client: &'c Client, pub eval_id: String, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> EvalRuns<'c, C> { @@ -18,6 +19,7 @@ impl<'c, C: Config> EvalRuns<'c, C> { Self { client, eval_id: eval_id.into(), + request_options: RequestOptions::new(), } } @@ -33,7 +35,7 @@ impl<'c, C: Config> EvalRuns<'c, C> { Q: Serialize + ?Sized, { self.client - .get_with_query(&format!("/evals/{}/runs", self.eval_id), &query) + .get_with_query(&format!("/evals/{}/runs", self.eval_id), &query, &self.request_options) .await } @@ -41,7 +43,7 @@ impl<'c, C: Config> EvalRuns<'c, C> { #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] pub async fn create(&self, request: CreateEvalRunRequest) -> Result { self.client - .post(&format!("/evals/{}/runs", self.eval_id), request) + .post(&format!("/evals/{}/runs", self.eval_id), request, &self.request_options) .await } @@ -49,7 +51,7 @@ impl<'c, C: Config> EvalRuns<'c, C> { #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, run_id: &str) -> Result { self.client - .get(&format!("/evals/{}/runs/{}", self.eval_id, run_id)) + .get(&format!("/evals/{}/runs/{}", self.eval_id, run_id), &self.request_options) .await } @@ -60,6 +62,7 @@ impl<'c, C: Config> EvalRuns<'c, C> { .post( &format!("/evals/{}/runs/{}", self.eval_id, run_id), serde_json::json!({}), + &self.request_options, ) .await } @@ -68,7 +71,7 @@ impl<'c, C: Config> EvalRuns<'c, C> { #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn delete(&self, run_id: &str) -> Result { self.client - .delete(&format!("/evals/{}/runs/{}", self.eval_id, run_id)) + .delete(&format!("/evals/{}/runs/{}", self.eval_id, run_id), &self.request_options) .await } } diff --git a/async-openai/src/evals.rs b/async-openai/src/evals.rs index 1cc5aeac..f5ea2d37 100644 --- a/async-openai/src/evals.rs +++ b/async-openai/src/evals.rs @@ -5,18 +5,22 @@ use crate::{ error::OpenAIError, eval_runs::EvalRuns, types::evals::{CreateEvalRequest, DeleteEvalResponse, Eval, EvalList, UpdateEvalRequest}, - Client, + Client, RequestOptions, }; /// Create, manage, and run evals in the OpenAI platform. Related guide: /// [Evals](https://platform.openai.com/docs/guides/evals) pub struct Evals<'c, C: Config> { client: &'c Client, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> Evals<'c, C> { pub fn new(client: &'c Client) -> Self { - Self { client } + Self { + client, + request_options: RequestOptions::new(), + } } /// [EvalRuns] API group @@ -30,7 +34,7 @@ impl<'c, C: Config> Evals<'c, C> { where Q: Serialize + ?Sized, { - self.client.get_with_query("/evals", &query).await + self.client.get_with_query("/evals", &query, &self.request_options).await } /// Create the structure of an evaluation that can be used to test a model's performance. @@ -40,13 +44,13 @@ impl<'c, C: Config> Evals<'c, C> { /// datasources. For more information, see the [Evals guide](https://platform.openai.com/docs/guides/evals). #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] pub async fn create(&self, request: CreateEvalRequest) -> Result { - self.client.post("/evals", request).await + self.client.post("/evals", request, &self.request_options).await } /// Get an evaluation by ID. #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, eval_id: &str) -> Result { - self.client.get(&format!("/evals/{eval_id}")).await + self.client.get(&format!("/evals/{eval_id}"), &self.request_options).await } /// Update certain properties of an evaluation. @@ -57,13 +61,13 @@ impl<'c, C: Config> Evals<'c, C> { request: UpdateEvalRequest, ) -> Result { self.client - .post(&format!("/evals/{eval_id}"), request) + .post(&format!("/evals/{eval_id}"), request, &self.request_options) .await } /// Delete an evaluation. #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn delete(&self, eval_id: &str) -> Result { - self.client.delete(&format!("/evals/{eval_id}")).await + self.client.delete(&format!("/evals/{eval_id}"), &self.request_options).await } } diff --git a/async-openai/src/file.rs b/async-openai/src/file.rs index bce20415..6d142dcc 100644 --- a/async-openai/src/file.rs +++ b/async-openai/src/file.rs @@ -5,17 +5,21 @@ use crate::{ config::Config, error::OpenAIError, types::files::{CreateFileRequest, DeleteFileResponse, ListFilesResponse, OpenAIFile}, - Client, + Client, RequestOptions, }; /// Files are used to upload documents that can be used with features like Assistants and Fine-tuning. pub struct Files<'c, C: Config> { client: &'c Client, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> Files<'c, C> { pub fn new(client: &'c Client) -> Self { - Self { client } + Self { + client, + request_options: RequestOptions::new(), + } } /// Upload a file that can be used across various endpoints. Individual files can be up to 512 MB, and the size of all files uploaded by one organization can be up to 1 TB. @@ -33,7 +37,7 @@ impl<'c, C: Config> Files<'c, C> { where_clause = "reqwest::multipart::Form: crate::traits::AsyncTryFrom", )] pub async fn create(&self, request: CreateFileRequest) -> Result { - self.client.post_form("/files", request).await + self.client.post_form("/files", request, &self.request_options).await } /// Returns a list of files that belong to the user's organization. @@ -42,20 +46,20 @@ impl<'c, C: Config> Files<'c, C> { where Q: Serialize + ?Sized, { - self.client.get_with_query("/files", &query).await + self.client.get_with_query("/files", &query, &self.request_options).await } /// Returns information about a specific file. #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, file_id: &str) -> Result { - self.client.get(format!("/files/{file_id}").as_str()).await + self.client.get(format!("/files/{file_id}").as_str(), &self.request_options).await } /// Delete a file. #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn delete(&self, file_id: &str) -> Result { self.client - .delete(format!("/files/{file_id}").as_str()) + .delete(format!("/files/{file_id}").as_str(), &self.request_options) .await } diff --git a/async-openai/src/fine_tuning.rs b/async-openai/src/fine_tuning.rs index 4a4d271c..7c0a1a93 100644 --- a/async-openai/src/fine_tuning.rs +++ b/async-openai/src/fine_tuning.rs @@ -9,7 +9,7 @@ use crate::{ ListFineTuningCheckpointPermissionResponse, ListFineTuningJobCheckpointsResponse, ListFineTuningJobEventsResponse, ListPaginatedFineTuningJobsResponse, }, - Client, + Client, RequestOptions, }; /// Manage fine-tuning jobs to tailor a model to your specific training data. @@ -17,11 +17,15 @@ use crate::{ /// Related guide: [Fine-tune models](https://platform.openai.com/docs/guides/fine-tuning) pub struct FineTuning<'c, C: Config> { client: &'c Client, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> FineTuning<'c, C> { pub fn new(client: &'c Client) -> Self { - Self { client } + Self { + client, + request_options: RequestOptions::new(), + } } /// Creates a fine-tuning job which begins the process of creating a new model from a given dataset. @@ -35,7 +39,7 @@ impl<'c, C: Config> FineTuning<'c, C> { &self, request: CreateFineTuningJobRequest, ) -> Result { - self.client.post("/fine_tuning/jobs", request).await + self.client.post("/fine_tuning/jobs", request, &self.request_options).await } /// List your organization's fine-tuning jobs @@ -48,7 +52,7 @@ impl<'c, C: Config> FineTuning<'c, C> { Q: Serialize + ?Sized, { self.client - .get_with_query("/fine_tuning/jobs", &query) + .get_with_query("/fine_tuning/jobs", &query, &self.request_options) .await } @@ -58,7 +62,7 @@ impl<'c, C: Config> FineTuning<'c, C> { #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, fine_tuning_job_id: &str) -> Result { self.client - .get(format!("/fine_tuning/jobs/{fine_tuning_job_id}").as_str()) + .get(format!("/fine_tuning/jobs/{fine_tuning_job_id}").as_str(), &self.request_options) .await } @@ -69,6 +73,7 @@ impl<'c, C: Config> FineTuning<'c, C> { .post( format!("/fine_tuning/jobs/{fine_tuning_job_id}/cancel").as_str(), (), + &self.request_options, ) .await } @@ -80,6 +85,7 @@ impl<'c, C: Config> FineTuning<'c, C> { .post( format!("/fine_tuning/jobs/{fine_tuning_job_id}/pause").as_str(), (), + &self.request_options, ) .await } @@ -91,6 +97,7 @@ impl<'c, C: Config> FineTuning<'c, C> { .post( format!("/fine_tuning/jobs/{fine_tuning_job_id}/resume").as_str(), (), + &self.request_options, ) .await } @@ -109,6 +116,7 @@ impl<'c, C: Config> FineTuning<'c, C> { .get_with_query( format!("/fine_tuning/jobs/{fine_tuning_job_id}/events").as_str(), &query, + &self.request_options, ) .await } @@ -127,6 +135,7 @@ impl<'c, C: Config> FineTuning<'c, C> { .get_with_query( format!("/fine_tuning/jobs/{fine_tuning_job_id}/checkpoints").as_str(), &query, + &self.request_options, ) .await } @@ -142,6 +151,7 @@ impl<'c, C: Config> FineTuning<'c, C> { format!("/fine_tuning/checkpoints/{fine_tuned_model_checkpoint}/permissions") .as_str(), request, + &self.request_options, ) .await } @@ -160,6 +170,7 @@ impl<'c, C: Config> FineTuning<'c, C> { format!("/fine_tuning/checkpoints/{fine_tuned_model_checkpoint}/permissions") .as_str(), &query, + &self.request_options, ) .await } @@ -174,6 +185,7 @@ impl<'c, C: Config> FineTuning<'c, C> { .delete( format!("/fine_tuning/checkpoints/{fine_tuned_model_checkpoint}/permissions/{permission_id}") .as_str(), + &self.request_options, ) .await } diff --git a/async-openai/src/image.rs b/async-openai/src/image.rs index 8516727a..c7297ee1 100644 --- a/async-openai/src/image.rs +++ b/async-openai/src/image.rs @@ -5,7 +5,7 @@ use crate::{ CreateImageEditRequest, CreateImageRequest, CreateImageVariationRequest, ImageEditStream, ImageGenStream, ImagesResponse, }, - Client, + Client, RequestOptions, }; /// Given a prompt and/or an input image, the model will generate a new image. @@ -13,11 +13,15 @@ use crate::{ /// Related guide: [Image generation](https://platform.openai.com/docs/guides/images) pub struct Images<'c, C: Config> { client: &'c Client, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> Images<'c, C> { pub fn new(client: &'c Client) -> Self { - Self { client } + Self { + client, + request_options: RequestOptions::new(), + } } /// Creates an image given a prompt. @@ -26,7 +30,7 @@ impl<'c, C: Config> Images<'c, C> { &self, request: CreateImageRequest, ) -> Result { - self.client.post("/images/generations", request).await + self.client.post("/images/generations", request, &self.request_options).await } /// Creates an image given a prompt. @@ -54,7 +58,7 @@ impl<'c, C: Config> Images<'c, C> { Ok(self .client - .post_stream("/images/generations", request) + .post_stream("/images/generations", request, &self.request_options) .await) } @@ -69,7 +73,7 @@ impl<'c, C: Config> Images<'c, C> { &self, request: CreateImageEditRequest, ) -> Result { - self.client.post_form("/images/edits", request).await + self.client.post_form("/images/edits", request, &self.request_options).await } /// Creates an edited or extended image given one or more source images and a prompt. @@ -96,7 +100,7 @@ impl<'c, C: Config> Images<'c, C> { } request.stream = Some(true); } - self.client.post_form_stream("/images/edits", request).await + self.client.post_form_stream("/images/edits", request, &self.request_options).await } /// Creates a variation of a given image. This endpoint only supports dall-e-2. @@ -109,6 +113,6 @@ impl<'c, C: Config> Images<'c, C> { &self, request: CreateImageVariationRequest, ) -> Result { - self.client.post_form("/images/variations", request).await + self.client.post_form("/images/variations", request, &self.request_options).await } } diff --git a/async-openai/src/invites.rs b/async-openai/src/invites.rs index 3291b3b9..62cb31f3 100644 --- a/async-openai/src/invites.rs +++ b/async-openai/src/invites.rs @@ -4,17 +4,21 @@ use crate::{ config::Config, error::OpenAIError, types::admin::invites::{Invite, InviteDeleteResponse, InviteListResponse, InviteRequest}, - Client, + Client, RequestOptions, }; /// Invite and manage invitations for an organization. Invited users are automatically added to the Default project. pub struct Invites<'c, C: Config> { client: &'c Client, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> Invites<'c, C> { pub fn new(client: &'c Client) -> Self { - Self { client } + Self { + client, + request_options: RequestOptions::new(), + } } /// Returns a list of invites in the organization. @@ -24,7 +28,7 @@ impl<'c, C: Config> Invites<'c, C> { Q: Serialize + ?Sized, { self.client - .get_with_query("/organization/invites", &query) + .get_with_query("/organization/invites", &query, &self.request_options) .await } @@ -32,21 +36,21 @@ impl<'c, C: Config> Invites<'c, C> { #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, invite_id: &str) -> Result { self.client - .get(format!("/organization/invites/{invite_id}").as_str()) + .get(format!("/organization/invites/{invite_id}").as_str(), &self.request_options) .await } /// Create an invite for a user to the organization. The invite must be accepted by the user before they have access to the organization. #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] pub async fn create(&self, request: InviteRequest) -> Result { - self.client.post("/organization/invites", request).await + self.client.post("/organization/invites", request, &self.request_options).await } /// Delete an invite. If the invite has already been accepted, it cannot be deleted. #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn delete(&self, invite_id: &str) -> Result { self.client - .delete(format!("/organization/invites/{invite_id}").as_str()) + .delete(format!("/organization/invites/{invite_id}").as_str(), &self.request_options) .await } } diff --git a/async-openai/src/lib.rs b/async-openai/src/lib.rs index 846eff32..4ea77473 100644 --- a/async-openai/src/lib.rs +++ b/async-openai/src/lib.rs @@ -177,6 +177,7 @@ mod project_users; mod projects; #[cfg(feature = "realtime")] mod realtime; +mod request_options; mod responses; mod runs; mod speech; @@ -231,6 +232,7 @@ pub use project_users::ProjectUsers; pub use projects::Projects; #[cfg(feature = "realtime")] pub use realtime::Realtime; +pub use request_options::RequestOptions; pub use responses::Responses; pub use runs::Runs; pub use speech::Speech; diff --git a/async-openai/src/messages.rs b/async-openai/src/messages.rs index cd59bed4..4d0693fd 100644 --- a/async-openai/src/messages.rs +++ b/async-openai/src/messages.rs @@ -7,7 +7,7 @@ use crate::{ CreateMessageRequest, DeleteMessageResponse, ListMessagesResponse, MessageObject, ModifyMessageRequest, }, - Client, + Client, RequestOptions, }; /// Represents a message within a [thread](https://platform.openai.com/docs/api-reference/threads). @@ -15,6 +15,7 @@ pub struct Messages<'c, C: Config> { /// The ID of the [thread](https://platform.openai.com/docs/api-reference/threads) to create a message for. pub thread_id: String, client: &'c Client, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> Messages<'c, C> { @@ -22,6 +23,7 @@ impl<'c, C: Config> Messages<'c, C> { Self { client, thread_id: thread_id.into(), + request_options: RequestOptions::new(), } } @@ -32,7 +34,7 @@ impl<'c, C: Config> Messages<'c, C> { request: CreateMessageRequest, ) -> Result { self.client - .post(&format!("/threads/{}/messages", self.thread_id), request) + .post(&format!("/threads/{}/messages", self.thread_id), request, &self.request_options) .await } @@ -43,7 +45,7 @@ impl<'c, C: Config> Messages<'c, C> { .get(&format!( "/threads/{}/messages/{message_id}", self.thread_id - )) + ), &self.request_options) .await } @@ -58,6 +60,7 @@ impl<'c, C: Config> Messages<'c, C> { .post( &format!("/threads/{}/messages/{message_id}", self.thread_id), request, + &self.request_options, ) .await } @@ -69,7 +72,7 @@ impl<'c, C: Config> Messages<'c, C> { Q: Serialize + ?Sized, { self.client - .get_with_query(&format!("/threads/{}/messages", self.thread_id), &query) + .get_with_query(&format!("/threads/{}/messages", self.thread_id), &query, &self.request_options) .await } @@ -79,7 +82,7 @@ impl<'c, C: Config> Messages<'c, C> { .delete(&format!( "/threads/{}/messages/{message_id}", self.thread_id - )) + ), &self.request_options) .await } } diff --git a/async-openai/src/model.rs b/async-openai/src/model.rs index 8d56bcb4..6a51795b 100644 --- a/async-openai/src/model.rs +++ b/async-openai/src/model.rs @@ -2,7 +2,7 @@ use crate::{ config::Config, error::OpenAIError, types::models::{DeleteModelResponse, ListModelResponse, Model}, - Client, + Client, RequestOptions, }; /// List and describe the various models available in the API. @@ -10,32 +10,36 @@ use crate::{ /// models are available and the differences between them. pub struct Models<'c, C: Config> { client: &'c Client, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> Models<'c, C> { pub fn new(client: &'c Client) -> Self { - Self { client } + Self { + client, + request_options: RequestOptions::new(), + } } /// Lists the currently available models, and provides basic information /// about each one such as the owner and availability. #[crate::byot(R = serde::de::DeserializeOwned)] pub async fn list(&self) -> Result { - self.client.get("/models").await + self.client.get("/models", &self.request_options).await } /// Retrieves a model instance, providing basic information about the model /// such as the owner and permissioning. #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, model: &str) -> Result { - self.client.get(format!("/models/{model}").as_str()).await + self.client.get(format!("/models/{model}").as_str(), &self.request_options).await } /// Delete a fine-tuned model. You must have the Owner role in your organization. #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn delete(&self, model: &str) -> Result { self.client - .delete(format!("/models/{model}").as_str()) + .delete(format!("/models/{model}").as_str(), &self.request_options) .await } } diff --git a/async-openai/src/moderation.rs b/async-openai/src/moderation.rs index 2e900256..29dde159 100644 --- a/async-openai/src/moderation.rs +++ b/async-openai/src/moderation.rs @@ -2,7 +2,7 @@ use crate::{ config::Config, error::OpenAIError, types::moderations::{CreateModerationRequest, CreateModerationResponse}, - Client, + Client, RequestOptions, }; /// Given text and/or image inputs, classifies if those inputs are potentially harmful across several categories. @@ -10,11 +10,15 @@ use crate::{ /// Related guide: [Moderations](https://platform.openai.com/docs/guides/moderation) pub struct Moderations<'c, C: Config> { client: &'c Client, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> Moderations<'c, C> { pub fn new(client: &'c Client) -> Self { - Self { client } + Self { + client, + request_options: RequestOptions::new(), + } } /// Classifies if text and/or image inputs are potentially harmful. Learn @@ -24,6 +28,6 @@ impl<'c, C: Config> Moderations<'c, C> { &self, request: CreateModerationRequest, ) -> Result { - self.client.post("/moderations", request).await + self.client.post("/moderations", request, &self.request_options).await } } diff --git a/async-openai/src/project_api_keys.rs b/async-openai/src/project_api_keys.rs index ce5d56c1..ed15e070 100644 --- a/async-openai/src/project_api_keys.rs +++ b/async-openai/src/project_api_keys.rs @@ -6,7 +6,7 @@ use crate::{ types::admin::project_api_keys::{ ProjectApiKey, ProjectApiKeyDeleteResponse, ProjectApiKeyListResponse, }, - Client, + Client, RequestOptions, }; /// Manage API keys for a given project. Supports listing and deleting keys for users. @@ -14,6 +14,7 @@ use crate::{ pub struct ProjectAPIKeys<'c, C: Config> { client: &'c Client, pub project_id: String, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> ProjectAPIKeys<'c, C> { @@ -21,6 +22,7 @@ impl<'c, C: Config> ProjectAPIKeys<'c, C> { Self { client, project_id: project_id.into(), + request_options: RequestOptions::new(), } } @@ -34,6 +36,7 @@ impl<'c, C: Config> ProjectAPIKeys<'c, C> { .get_with_query( format!("/organization/projects/{}/api_keys", self.project_id).as_str(), &query, + &self.request_options, ) .await } @@ -48,6 +51,7 @@ impl<'c, C: Config> ProjectAPIKeys<'c, C> { self.project_id ) .as_str(), + &self.request_options, ) .await } @@ -62,6 +66,7 @@ impl<'c, C: Config> ProjectAPIKeys<'c, C> { self.project_id ) .as_str(), + &self.request_options, ) .await } diff --git a/async-openai/src/project_certificates.rs b/async-openai/src/project_certificates.rs index a7cc2dd1..1b6a3d13 100644 --- a/async-openai/src/project_certificates.rs +++ b/async-openai/src/project_certificates.rs @@ -4,13 +4,14 @@ use crate::{ config::Config, error::OpenAIError, types::admin::certificates::{ListCertificatesResponse, ToggleCertificatesRequest}, - Client, + Client, RequestOptions, }; /// Manage certificates for a given project. Supports listing, activating, and deactivating certificates. pub struct ProjectCertificates<'c, C: Config> { client: &'c Client, pub project_id: String, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> ProjectCertificates<'c, C> { @@ -18,6 +19,7 @@ impl<'c, C: Config> ProjectCertificates<'c, C> { Self { client, project_id: project_id.into(), + request_options: RequestOptions::new(), } } @@ -30,6 +32,7 @@ impl<'c, C: Config> ProjectCertificates<'c, C> { .get_with_query( format!("/organization/projects/{}/certificates", self.project_id).as_str(), query, + &self.request_options, ) .await } @@ -48,6 +51,7 @@ impl<'c, C: Config> ProjectCertificates<'c, C> { ) .as_str(), request, + &self.request_options, ) .await } @@ -66,6 +70,7 @@ impl<'c, C: Config> ProjectCertificates<'c, C> { ) .as_str(), request, + &self.request_options, ) .await } diff --git a/async-openai/src/project_rate_limits.rs b/async-openai/src/project_rate_limits.rs index 13c7e643..6eb27b83 100644 --- a/async-openai/src/project_rate_limits.rs +++ b/async-openai/src/project_rate_limits.rs @@ -6,13 +6,14 @@ use crate::{ types::admin::project_rate_limits::{ ProjectRateLimit, ProjectRateLimitListResponse, ProjectRateLimitUpdateRequest, }, - Client, + Client, RequestOptions, }; /// Manage rate limits for a given project. Supports listing and updating rate limits per model. pub struct ProjectRateLimits<'c, C: Config> { client: &'c Client, pub project_id: String, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> ProjectRateLimits<'c, C> { @@ -20,6 +21,7 @@ impl<'c, C: Config> ProjectRateLimits<'c, C> { Self { client, project_id: project_id.into(), + request_options: RequestOptions::new(), } } @@ -33,6 +35,7 @@ impl<'c, C: Config> ProjectRateLimits<'c, C> { .get_with_query( format!("/organization/projects/{}/rate_limits", self.project_id).as_str(), &query, + &self.request_options, ) .await } @@ -52,6 +55,7 @@ impl<'c, C: Config> ProjectRateLimits<'c, C> { ) .as_str(), request, + &self.request_options, ) .await } diff --git a/async-openai/src/project_service_accounts.rs b/async-openai/src/project_service_accounts.rs index 53548e21..9b2f41d7 100644 --- a/async-openai/src/project_service_accounts.rs +++ b/async-openai/src/project_service_accounts.rs @@ -8,7 +8,7 @@ use crate::{ ProjectServiceAccountCreateResponse, ProjectServiceAccountDeleteResponse, ProjectServiceAccountListResponse, }, - Client, + Client, RequestOptions, }; /// Manage service accounts within a project. A service account is a bot user that is not @@ -18,6 +18,7 @@ use crate::{ pub struct ProjectServiceAccounts<'c, C: Config> { client: &'c Client, pub project_id: String, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> ProjectServiceAccounts<'c, C> { @@ -25,6 +26,7 @@ impl<'c, C: Config> ProjectServiceAccounts<'c, C> { Self { client, project_id: project_id.into(), + request_options: RequestOptions::new(), } } @@ -42,6 +44,7 @@ impl<'c, C: Config> ProjectServiceAccounts<'c, C> { ) .as_str(), &query, + &self.request_options, ) .await } @@ -60,6 +63,7 @@ impl<'c, C: Config> ProjectServiceAccounts<'c, C> { ) .as_str(), request, + &self.request_options, ) .await } @@ -77,6 +81,7 @@ impl<'c, C: Config> ProjectServiceAccounts<'c, C> { self.project_id ) .as_str(), + &self.request_options, ) .await } @@ -94,6 +99,7 @@ impl<'c, C: Config> ProjectServiceAccounts<'c, C> { self.project_id ) .as_str(), + &self.request_options, ) .await } diff --git a/async-openai/src/project_users.rs b/async-openai/src/project_users.rs index 658031b2..abef3320 100644 --- a/async-openai/src/project_users.rs +++ b/async-openai/src/project_users.rs @@ -7,7 +7,7 @@ use crate::{ ProjectUser, ProjectUserCreateRequest, ProjectUserDeleteResponse, ProjectUserListResponse, ProjectUserUpdateRequest, }, - Client, + Client, RequestOptions, }; /// Manage users within a project, including adding, updating roles, and removing users. @@ -15,6 +15,7 @@ use crate::{ pub struct ProjectUsers<'c, C: Config> { client: &'c Client, pub project_id: String, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> ProjectUsers<'c, C> { @@ -22,6 +23,7 @@ impl<'c, C: Config> ProjectUsers<'c, C> { Self { client, project_id: project_id.into(), + request_options: RequestOptions::new(), } } @@ -35,6 +37,7 @@ impl<'c, C: Config> ProjectUsers<'c, C> { .get_with_query( format!("/organization/projects/{}/users", self.project_id).as_str(), &query, + &self.request_options, ) .await } @@ -49,6 +52,7 @@ impl<'c, C: Config> ProjectUsers<'c, C> { .post( format!("/organization/projects/{}/users", self.project_id).as_str(), request, + &self.request_options, ) .await } @@ -57,7 +61,7 @@ impl<'c, C: Config> ProjectUsers<'c, C> { #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, user_id: &str) -> Result { self.client - .get(format!("/organization/projects/{}/users/{user_id}", self.project_id).as_str()) + .get(format!("/organization/projects/{}/users/{user_id}", self.project_id).as_str(), &self.request_options) .await } @@ -72,6 +76,7 @@ impl<'c, C: Config> ProjectUsers<'c, C> { .post( format!("/organization/projects/{}/users/{user_id}", self.project_id).as_str(), request, + &self.request_options, ) .await } @@ -80,7 +85,7 @@ impl<'c, C: Config> ProjectUsers<'c, C> { #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn delete(&self, user_id: &str) -> Result { self.client - .delete(format!("/organization/projects/{}/users/{user_id}", self.project_id).as_str()) + .delete(format!("/organization/projects/{}/users/{user_id}", self.project_id).as_str(), &self.request_options) .await } } diff --git a/async-openai/src/projects.rs b/async-openai/src/projects.rs index bdbdcc2a..7fc6b6a0 100644 --- a/async-openai/src/projects.rs +++ b/async-openai/src/projects.rs @@ -9,18 +9,22 @@ use crate::{ types::admin::projects::{ Project, ProjectCreateRequest, ProjectListResponse, ProjectUpdateRequest, }, - Client, ProjectServiceAccounts, ProjectUsers, + Client, ProjectServiceAccounts, ProjectUsers, RequestOptions, }; /// Manage the projects within an organization includes creation, updating, and archiving or projects. /// The Default project cannot be modified or archived. pub struct Projects<'c, C: Config> { client: &'c Client, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> Projects<'c, C> { pub fn new(client: &'c Client) -> Self { - Self { client } + Self { + client, + request_options: RequestOptions::new(), + } } // call [ProjectUsers] group APIs @@ -55,21 +59,21 @@ impl<'c, C: Config> Projects<'c, C> { Q: Serialize + ?Sized, { self.client - .get_with_query("/organization/projects", &query) + .get_with_query("/organization/projects", &query, &self.request_options) .await } /// Create a new project in the organization. Projects can be created and archived, but cannot be deleted. #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] pub async fn create(&self, request: ProjectCreateRequest) -> Result { - self.client.post("/organization/projects", request).await + self.client.post("/organization/projects", request, &self.request_options).await } /// Retrieves a project. #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, project_id: String) -> Result { self.client - .get(format!("/organization/projects/{project_id}").as_str()) + .get(format!("/organization/projects/{project_id}").as_str(), &self.request_options) .await } @@ -84,6 +88,7 @@ impl<'c, C: Config> Projects<'c, C> { .post( format!("/organization/projects/{project_id}").as_str(), request, + &self.request_options, ) .await } @@ -95,6 +100,7 @@ impl<'c, C: Config> Projects<'c, C> { .post( format!("/organization/projects/{project_id}/archive").as_str(), (), + &self.request_options, ) .await } diff --git a/async-openai/src/realtime.rs b/async-openai/src/realtime.rs index bb75d217..e3cbe53a 100644 --- a/async-openai/src/realtime.rs +++ b/async-openai/src/realtime.rs @@ -6,18 +6,22 @@ use crate::{ RealtimeCallReferRequest, RealtimeCallRejectRequest, RealtimeCreateClientSecretRequest, RealtimeCreateClientSecretResponse, }, - Client, + Client, RequestOptions, }; /// Realtime API for creating sessions, managing calls, and handling WebRTC connections. /// Related guide: [Realtime API](https://platform.openai.com/docs/guides/realtime) pub struct Realtime<'c, C: Config> { client: &'c Client, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> Realtime<'c, C> { pub fn new(client: &'c Client) -> Self { - Self { client } + Self { + client, + request_options: RequestOptions::new(), + } } /// Create a new Realtime API call over WebRTC and receive the SDP answer needed @@ -30,7 +34,7 @@ impl<'c, C: Config> Realtime<'c, C> { ) -> Result { let (bytes, headers) = self .client - .post_form_raw("/realtime/calls", request) + .post_form_raw("/realtime/calls", request, &self.request_options) .await?; // Extract Location header @@ -57,14 +61,22 @@ impl<'c, C: Config> Realtime<'c, C> { request: RealtimeCallAcceptRequest, ) -> Result<(), OpenAIError> { self.client - .post(&format!("/realtime/calls/{}/accept", call_id), request) + .post( + &format!("/realtime/calls/{}/accept", call_id), + request, + &self.request_options, + ) .await } /// End an active Realtime API call, whether it was initiated over SIP or WebRTC. pub async fn hangup_call(&self, call_id: &str) -> Result<(), OpenAIError> { self.client - .post(&format!("/realtime/calls/{}/hangup", call_id), ()) + .post( + &format!("/realtime/calls/{}/hangup", call_id), + (), + &self.request_options, + ) .await } @@ -75,7 +87,11 @@ impl<'c, C: Config> Realtime<'c, C> { request: RealtimeCallReferRequest, ) -> Result<(), OpenAIError> { self.client - .post(&format!("/realtime/calls/{}/refer", call_id), request) + .post( + &format!("/realtime/calls/{}/refer", call_id), + request, + &self.request_options, + ) .await } @@ -89,6 +105,7 @@ impl<'c, C: Config> Realtime<'c, C> { .post( &format!("/realtime/calls/{}/reject", call_id), request.unwrap_or_default(), + &self.request_options, ) .await } @@ -98,6 +115,8 @@ impl<'c, C: Config> Realtime<'c, C> { &self, request: RealtimeCreateClientSecretRequest, ) -> Result { - self.client.post("/realtime/client_secrets", request).await + self.client + .post("/realtime/client_secrets", request, &self.request_options) + .await } } diff --git a/async-openai/src/request_options.rs b/async-openai/src/request_options.rs new file mode 100644 index 00000000..05641e0d --- /dev/null +++ b/async-openai/src/request_options.rs @@ -0,0 +1,66 @@ +use reqwest::header::HeaderMap; +use serde::Serialize; + +use crate::error::OpenAIError; + +#[derive(Clone, Debug, Default)] +pub struct RequestOptions { + query: Option, + headers: Option, +} + +impl RequestOptions { + pub fn new() -> Self { + Self { + query: None, + headers: None, + } + } + + pub fn with_headers(&mut self, headers: HeaderMap) { + // merge with existing headers or update with new headers + if let Some(existing_headers) = &mut self.headers { + existing_headers.extend(headers.into_iter()); + } else { + self.headers = Some(headers); + } + } + + pub fn with_header(&mut self, key: K, value: V) -> Result<(), OpenAIError> + where + K: reqwest::header::IntoHeaderName, + V: TryInto, + V::Error: Into, + { + let value = value.try_into().map_err(|e| { + OpenAIError::InvalidArgument(format!("Invalid header value: {}", e.into())) + })?; + if let Some(headers) = &mut self.headers { + headers.insert(key, value); + } else { + let mut headers = HeaderMap::new(); + headers.insert(key, value.into()); + self.headers = Some(headers); + } + Ok(()) + } + + pub fn with_query(&mut self, query: &Q) -> Result<(), OpenAIError> { + let new_query = serde_urlencoded::to_string(query) + .map_err(|e| OpenAIError::InvalidArgument(format!("Invalid query: {}", e)))?; + if let Some(existing_query) = &self.query { + self.query = Some(format!("{}&{}", existing_query, new_query)); + } else { + self.query = Some(new_query); + } + Ok(()) + } + + pub fn query(&self) -> Option<&str> { + self.query.as_deref() + } + + pub fn headers(&self) -> Option<&HeaderMap> { + self.headers.as_ref() + } +} diff --git a/async-openai/src/responses.rs b/async-openai/src/responses.rs index 223a5b1c..4cb6ebd9 100644 --- a/async-openai/src/responses.rs +++ b/async-openai/src/responses.rs @@ -7,17 +7,21 @@ use crate::{ CreateResponse, DeleteResponse, Response, ResponseItemList, ResponseStream, TokenCountsBody, TokenCountsResource, }, - Client, + Client, RequestOptions, }; pub struct Responses<'c, C: Config> { client: &'c Client, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> Responses<'c, C> { /// Constructs a new Responses client. pub fn new(client: &'c Client) -> Self { - Self { client } + Self { + client, + request_options: RequestOptions::new(), + } } /// Creates a model response. Provide [text](https://platform.openai.com/docs/guides/text) or @@ -34,7 +38,7 @@ impl<'c, C: Config> Responses<'c, C> { R = serde::de::DeserializeOwned )] pub async fn create(&self, request: CreateResponse) -> Result { - self.client.post("/responses", request).await + self.client.post("/responses", request, &self.request_options).await } /// Creates a model response for the given input with streaming. @@ -60,7 +64,7 @@ impl<'c, C: Config> Responses<'c, C> { } request.stream = Some(true); } - Ok(self.client.post_stream("/responses", request).await) + Ok(self.client.post_stream("/responses", request, &self.request_options).await) } /// Retrieves a model response with the given ID. @@ -70,7 +74,7 @@ impl<'c, C: Config> Responses<'c, C> { Q: Serialize + ?Sized, { self.client - .get_with_query(&format!("/responses/{}", response_id), &query) + .get_with_query(&format!("/responses/{}", response_id), &query, &self.request_options) .await } @@ -78,7 +82,7 @@ impl<'c, C: Config> Responses<'c, C> { #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn delete(&self, response_id: &str) -> Result { self.client - .delete(&format!("/responses/{}", response_id)) + .delete(&format!("/responses/{}", response_id), &self.request_options) .await } @@ -91,6 +95,7 @@ impl<'c, C: Config> Responses<'c, C> { .post( &format!("/responses/{}/cancel", response_id), serde_json::json!({}), + &self.request_options, ) .await } @@ -106,7 +111,7 @@ impl<'c, C: Config> Responses<'c, C> { Q: Serialize + ?Sized, { self.client - .get_with_query(&format!("/responses/{}/input_items", response_id), &query) + .get_with_query(&format!("/responses/{}/input_items", response_id), &query, &self.request_options) .await } @@ -116,6 +121,6 @@ impl<'c, C: Config> Responses<'c, C> { &self, request: TokenCountsBody, ) -> Result { - self.client.post("/responses/input_tokens", request).await + self.client.post("/responses/input_tokens", request, &self.request_options).await } } diff --git a/async-openai/src/runs.rs b/async-openai/src/runs.rs index 4fad1424..a81d8d47 100644 --- a/async-openai/src/runs.rs +++ b/async-openai/src/runs.rs @@ -8,7 +8,7 @@ use crate::{ AssistantEventStream, CreateRunRequest, ListRunsResponse, ModifyRunRequest, RunObject, SubmitToolOutputsRunRequest, }, - Client, + Client, RequestOptions, }; /// Represents an execution run on a thread. @@ -17,6 +17,7 @@ use crate::{ pub struct Runs<'c, C: Config> { pub thread_id: String, client: &'c Client, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> Runs<'c, C> { @@ -24,6 +25,7 @@ impl<'c, C: Config> Runs<'c, C> { Self { client, thread_id: thread_id.into(), + request_options: RequestOptions::new(), } } @@ -36,7 +38,7 @@ impl<'c, C: Config> Runs<'c, C> { #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] pub async fn create(&self, request: CreateRunRequest) -> Result { self.client - .post(&format!("/threads/{}/runs", self.thread_id), request) + .post(&format!("/threads/{}/runs", self.thread_id), request, &self.request_options) .await } @@ -70,6 +72,7 @@ impl<'c, C: Config> Runs<'c, C> { .post_stream_mapped_raw_events( &format!("/threads/{}/runs", self.thread_id), request, + &self.request_options, TryFrom::try_from, ) .await) @@ -79,7 +82,7 @@ impl<'c, C: Config> Runs<'c, C> { #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, run_id: &str) -> Result { self.client - .get(&format!("/threads/{}/runs/{run_id}", self.thread_id)) + .get(&format!("/threads/{}/runs/{run_id}", self.thread_id), &self.request_options) .await } @@ -94,6 +97,7 @@ impl<'c, C: Config> Runs<'c, C> { .post( &format!("/threads/{}/runs/{run_id}", self.thread_id), request, + &self.request_options, ) .await } @@ -105,7 +109,7 @@ impl<'c, C: Config> Runs<'c, C> { Q: Serialize + ?Sized, { self.client - .get_with_query(&format!("/threads/{}/runs", self.thread_id), &query) + .get_with_query(&format!("/threads/{}/runs", self.thread_id), &query, &self.request_options) .await } @@ -123,6 +127,7 @@ impl<'c, C: Config> Runs<'c, C> { self.thread_id ), request, + &self.request_options, ) .await } @@ -160,6 +165,7 @@ impl<'c, C: Config> Runs<'c, C> { self.thread_id ), request, + &self.request_options, TryFrom::try_from, ) .await) @@ -172,6 +178,7 @@ impl<'c, C: Config> Runs<'c, C> { .post( &format!("/threads/{}/runs/{run_id}/cancel", self.thread_id), (), + &self.request_options, ) .await } diff --git a/async-openai/src/speech.rs b/async-openai/src/speech.rs index 4bd160af..e0408c23 100644 --- a/async-openai/src/speech.rs +++ b/async-openai/src/speech.rs @@ -2,16 +2,20 @@ use crate::{ config::Config, error::OpenAIError, types::audio::{CreateSpeechRequest, CreateSpeechResponse, SpeechResponseStream}, - Client, + Client, RequestOptions, }; pub struct Speech<'c, C: Config> { client: &'c Client, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> Speech<'c, C> { pub fn new(client: &'c Client) -> Self { - Self { client } + Self { + client, + request_options: RequestOptions::new(), + } } /// Generates audio from the input text. @@ -19,7 +23,7 @@ impl<'c, C: Config> Speech<'c, C> { &self, request: CreateSpeechRequest, ) -> Result { - let (bytes, _headers) = self.client.post_raw("/audio/speech", request).await?; + let (bytes, _headers) = self.client.post_raw("/audio/speech", request, &self.request_options).await?; Ok(CreateSpeechResponse { bytes }) } @@ -49,6 +53,6 @@ impl<'c, C: Config> Speech<'c, C> { request.stream_format = Some(StreamFormat::SSE); } - Ok(self.client.post_stream("/audio/speech", request).await) + Ok(self.client.post_stream("/audio/speech", request, &self.request_options).await) } } diff --git a/async-openai/src/steps.rs b/async-openai/src/steps.rs index e82cb977..c80f85f8 100644 --- a/async-openai/src/steps.rs +++ b/async-openai/src/steps.rs @@ -4,7 +4,7 @@ use crate::{ config::Config, error::OpenAIError, types::assistants::{ListRunStepsResponse, RunStepObject}, - Client, + Client, RequestOptions, }; /// Represents a step in execution of a run. @@ -12,6 +12,7 @@ pub struct Steps<'c, C: Config> { pub thread_id: String, pub run_id: String, client: &'c Client, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> Steps<'c, C> { @@ -20,6 +21,7 @@ impl<'c, C: Config> Steps<'c, C> { client, thread_id: thread_id.into(), run_id: run_id.into(), + request_options: RequestOptions::new(), } } @@ -27,10 +29,13 @@ impl<'c, C: Config> Steps<'c, C> { #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, step_id: &str) -> Result { self.client - .get(&format!( - "/threads/{}/runs/{}/steps/{step_id}", - self.thread_id, self.run_id - )) + .get( + &format!( + "/threads/{}/runs/{}/steps/{step_id}", + self.thread_id, self.run_id + ), + &self.request_options, + ) .await } @@ -44,6 +49,7 @@ impl<'c, C: Config> Steps<'c, C> { .get_with_query( &format!("/threads/{}/runs/{}/steps", self.thread_id, self.run_id), &query, + &self.request_options, ) .await } diff --git a/async-openai/src/threads.rs b/async-openai/src/threads.rs index 5a0fe354..106e1e2e 100644 --- a/async-openai/src/threads.rs +++ b/async-openai/src/threads.rs @@ -5,7 +5,7 @@ use crate::{ AssistantEventStream, CreateThreadAndRunRequest, CreateThreadRequest, DeleteThreadResponse, ModifyThreadRequest, RunObject, ThreadObject, }, - Client, Messages, Runs, + Client, Messages, RequestOptions, Runs, }; /// Create threads that assistants can interact with. @@ -13,11 +13,15 @@ use crate::{ /// Related guide: [Assistants](https://platform.openai.com/docs/assistants/overview) pub struct Threads<'c, C: Config> { client: &'c Client, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> Threads<'c, C> { pub fn new(client: &'c Client) -> Self { - Self { client } + Self { + client, + request_options: RequestOptions::new(), + } } /// Call [Messages] group API to manage message in [thread_id] thread. @@ -36,7 +40,7 @@ impl<'c, C: Config> Threads<'c, C> { &self, request: CreateThreadAndRunRequest, ) -> Result { - self.client.post("/threads/runs", request).await + self.client.post("/threads/runs", request, &self.request_options).await } /// Create a thread and run it in one request (streaming). @@ -65,20 +69,20 @@ impl<'c, C: Config> Threads<'c, C> { } Ok(self .client - .post_stream_mapped_raw_events("/threads/runs", request, TryFrom::try_from) + .post_stream_mapped_raw_events("/threads/runs", request, &self.request_options, TryFrom::try_from) .await) } /// Create a thread. #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] pub async fn create(&self, request: CreateThreadRequest) -> Result { - self.client.post("/threads", request).await + self.client.post("/threads", request, &self.request_options).await } /// Retrieves a thread. #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, thread_id: &str) -> Result { - self.client.get(&format!("/threads/{thread_id}")).await + self.client.get(&format!("/threads/{thread_id}"), &self.request_options).await } /// Modifies a thread. @@ -89,13 +93,13 @@ impl<'c, C: Config> Threads<'c, C> { request: ModifyThreadRequest, ) -> Result { self.client - .post(&format!("/threads/{thread_id}"), request) + .post(&format!("/threads/{thread_id}"), request, &self.request_options) .await } /// Delete a thread. #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn delete(&self, thread_id: &str) -> Result { - self.client.delete(&format!("/threads/{thread_id}")).await + self.client.delete(&format!("/threads/{thread_id}"), &self.request_options).await } } diff --git a/async-openai/src/traits.rs b/async-openai/src/traits.rs index 0ae7462b..65ad1441 100644 --- a/async-openai/src/traits.rs +++ b/async-openai/src/traits.rs @@ -1,3 +1,8 @@ +use reqwest::header::HeaderMap; + +use crate::{error::OpenAIError, RequestOptions}; +use serde::Serialize; + pub trait AsyncTryFrom: Sized { /// The type returned in the event of a conversion error. type Error; @@ -17,3 +22,35 @@ pub trait EventId { /// Returns the event ID fn event_id(&self) -> &str; } + +/// Trait for types that can build RequestOptions through fluent API +pub trait RequestOptionsBuilder: Sized { + /// Get mutable reference to RequestOptions (for building) + fn options_mut(&mut self) -> &mut RequestOptions; + + /// Get reference to RequestOptions + fn options(&self) -> &RequestOptions; + + /// Add headers to RequestOptions + fn headers(mut self, headers: HeaderMap) -> Self { + self.options_mut().with_headers(headers); + self + } + + /// Add a single header to RequestOptions + fn header(mut self, key: K, value: V) -> Result + where + K: reqwest::header::IntoHeaderName, + V: TryInto, + V::Error: Into, + { + self.options_mut().with_header(key, value)?; + Ok(self) + } + + /// Add query parameters to RequestOptions + fn query(mut self, query: &Q) -> Result { + self.options_mut().with_query(query)?; + Ok(self) + } +} diff --git a/async-openai/src/transcriptions.rs b/async-openai/src/transcriptions.rs index d2cf1f59..7a44d7ef 100644 --- a/async-openai/src/transcriptions.rs +++ b/async-openai/src/transcriptions.rs @@ -8,16 +8,20 @@ use crate::{ CreateTranscriptionResponseJson, CreateTranscriptionResponseVerboseJson, TranscriptionResponseStream, }, - Client, + Client, RequestOptions, }; pub struct Transcriptions<'c, C: Config> { client: &'c Client, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> Transcriptions<'c, C> { pub fn new(client: &'c Client) -> Self { - Self { client } + Self { + client, + request_options: RequestOptions::new(), + } } /// Transcribes audio into the input language. @@ -31,7 +35,7 @@ impl<'c, C: Config> Transcriptions<'c, C> { request: CreateTranscriptionRequest, ) -> Result { self.client - .post_form("/audio/transcriptions", request) + .post_form("/audio/transcriptions", request, &self.request_options) .await } @@ -59,7 +63,7 @@ impl<'c, C: Config> Transcriptions<'c, C> { } self.client - .post_form_stream("/audio/transcriptions", request) + .post_form_stream("/audio/transcriptions", request, &self.request_options) .await } @@ -74,7 +78,7 @@ impl<'c, C: Config> Transcriptions<'c, C> { request: CreateTranscriptionRequest, ) -> Result { self.client - .post_form("/audio/transcriptions", request) + .post_form("/audio/transcriptions", request, &self.request_options) .await } @@ -89,7 +93,7 @@ impl<'c, C: Config> Transcriptions<'c, C> { request: CreateTranscriptionRequest, ) -> Result { self.client - .post_form("/audio/transcriptions", request) + .post_form("/audio/transcriptions", request, &self.request_options) .await } @@ -100,7 +104,7 @@ impl<'c, C: Config> Transcriptions<'c, C> { ) -> Result { let (bytes, _headers) = self .client - .post_form_raw("/audio/transcriptions", request) + .post_form_raw("/audio/transcriptions", request, &self.request_options) .await?; Ok(bytes) } diff --git a/async-openai/src/translations.rs b/async-openai/src/translations.rs index 93260499..c2f1ae0f 100644 --- a/async-openai/src/translations.rs +++ b/async-openai/src/translations.rs @@ -7,16 +7,20 @@ use crate::{ CreateTranslationRequest, CreateTranslationResponseJson, CreateTranslationResponseVerboseJson, }, - Client, + Client, RequestOptions, }; pub struct Translations<'c, C: Config> { client: &'c Client, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> Translations<'c, C> { pub fn new(client: &'c Client) -> Self { - Self { client } + Self { + client, + request_options: RequestOptions::new(), + } } /// Translates audio into English. @@ -29,7 +33,7 @@ impl<'c, C: Config> Translations<'c, C> { &self, request: CreateTranslationRequest, ) -> Result { - self.client.post_form("/audio/translations", request).await + self.client.post_form("/audio/translations", request, &self.request_options).await } /// Translates audio into English. @@ -42,7 +46,7 @@ impl<'c, C: Config> Translations<'c, C> { &self, request: CreateTranslationRequest, ) -> Result { - self.client.post_form("/audio/translations", request).await + self.client.post_form("/audio/translations", request, &self.request_options).await } /// Transcribes audio into the input language. @@ -52,7 +56,7 @@ impl<'c, C: Config> Translations<'c, C> { ) -> Result { let (bytes, _headers) = self .client - .post_form_raw("/audio/translations", request) + .post_form_raw("/audio/translations", request, &self.request_options) .await?; Ok(bytes) } diff --git a/async-openai/src/types/impls.rs b/async-openai/src/types/impls.rs index b868d136..868e227a 100644 --- a/async-openai/src/types/impls.rs +++ b/async-openai/src/types/impls.rs @@ -1371,3 +1371,119 @@ impl From<&str> for EasyInputContent { Self::Text(value.to_owned()) } } + +// request builder impls macro + +/// Macro to implement `RequestOptionsBuilder` for wrapper types containing `RequestOptions` +macro_rules! impl_request_options_builder { + ($type:ident) => { + impl<'c, C: crate::config::Config> crate::traits::RequestOptionsBuilder for $type<'c, C> { + fn options_mut(&mut self) -> &mut crate::RequestOptions { + &mut self.request_options + } + + fn options(&self) -> &crate::RequestOptions { + &self.request_options + } + } + }; +} + +use crate::{ + admin_api_keys::AdminAPIKeys, + assistants::Assistants, + audio::Audio, + audit_logs::AuditLogs, + batches::Batches, + certificates::Certificates, + chat::Chat, + chatkit::{Chatkit, ChatkitSessions, ChatkitThreads}, + completion::Completions, + container_files::ContainerFiles, + containers::Containers, + conversation_items::ConversationItems, + conversations::Conversations, + embedding::Embeddings, + eval_run_output_items::EvalRunOutputItems, + eval_runs::EvalRuns, + evals::Evals, + file::Files, + fine_tuning::FineTuning, + image::Images, + invites::Invites, + messages::Messages, + model::Models, + moderation::Moderations, + project_api_keys::ProjectAPIKeys, + project_certificates::ProjectCertificates, + project_rate_limits::ProjectRateLimits, + project_service_accounts::ProjectServiceAccounts, + project_users::ProjectUsers, + projects::Projects, + responses::Responses, + runs::Runs, + speech::Speech, + steps::Steps, + threads::Threads, + transcriptions::Transcriptions, + translations::Translations, + uploads::Uploads, + usage::Usage, + users::Users, + vector_store_file_batches::VectorStoreFileBatches, + vector_store_files::VectorStoreFiles, + vector_stores::VectorStores, + video::Videos, +}; + +#[cfg(feature = "realtime")] +use crate::Realtime; + +impl_request_options_builder!(AdminAPIKeys); +impl_request_options_builder!(Assistants); +impl_request_options_builder!(Audio); +impl_request_options_builder!(AuditLogs); +impl_request_options_builder!(Batches); +impl_request_options_builder!(Certificates); +impl_request_options_builder!(Chat); +impl_request_options_builder!(Chatkit); +impl_request_options_builder!(ChatkitSessions); +impl_request_options_builder!(ChatkitThreads); +impl_request_options_builder!(Completions); +impl_request_options_builder!(ContainerFiles); +impl_request_options_builder!(Containers); +impl_request_options_builder!(ConversationItems); +impl_request_options_builder!(Conversations); +impl_request_options_builder!(Embeddings); +impl_request_options_builder!(Evals); +impl_request_options_builder!(EvalRunOutputItems); +impl_request_options_builder!(EvalRuns); +impl_request_options_builder!(Files); +impl_request_options_builder!(FineTuning); +impl_request_options_builder!(Images); +impl_request_options_builder!(Invites); +impl_request_options_builder!(Messages); +impl_request_options_builder!(Models); +impl_request_options_builder!(Moderations); +impl_request_options_builder!(Projects); +impl_request_options_builder!(ProjectUsers); +impl_request_options_builder!(ProjectServiceAccounts); +impl_request_options_builder!(ProjectAPIKeys); +impl_request_options_builder!(ProjectRateLimits); +impl_request_options_builder!(ProjectCertificates); +#[cfg(feature = "realtime")] +impl_request_options_builder!(Realtime); +impl_request_options_builder!(Responses); +impl_request_options_builder!(Runs); +impl_request_options_builder!(Speech); +impl_request_options_builder!(Steps); +impl_request_options_builder!(Threads); +impl_request_options_builder!(Transcriptions); +impl_request_options_builder!(Translations); +impl_request_options_builder!(Uploads); +impl_request_options_builder!(Usage); +impl_request_options_builder!(Users); +impl_request_options_builder!(VectorStoreFileBatches); +impl_request_options_builder!(VectorStoreFiles); +impl_request_options_builder!(VectorStores); +impl_request_options_builder!(Videos); diff --git a/async-openai/src/uploads.rs b/async-openai/src/uploads.rs index 8a3ef7f3..12d57b4d 100644 --- a/async-openai/src/uploads.rs +++ b/async-openai/src/uploads.rs @@ -4,17 +4,21 @@ use crate::{ types::uploads::{ AddUploadPartRequest, CompleteUploadRequest, CreateUploadRequest, Upload, UploadPart, }, - Client, + Client, RequestOptions, }; /// Allows you to upload large files in multiple parts. pub struct Uploads<'c, C: Config> { client: &'c Client, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> Uploads<'c, C> { pub fn new(client: &'c Client) -> Self { - Self { client } + Self { + client, + request_options: RequestOptions::new(), + } } /// Creates an intermediate [Upload](https://platform.openai.com/docs/api-reference/uploads/object) object that @@ -32,7 +36,7 @@ impl<'c, C: Config> Uploads<'c, C> { /// [creating a File](https://platform.openai.com/docs/api-reference/files/create). #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] pub async fn create(&self, request: CreateUploadRequest) -> Result { - self.client.post("/uploads", request).await + self.client.post("/uploads", request, &self.request_options).await } /// Adds a [Part](https://platform.openai.com/docs/api-reference/uploads/part-object) to an @@ -54,7 +58,7 @@ impl<'c, C: Config> Uploads<'c, C> { request: AddUploadPartRequest, ) -> Result { self.client - .post_form(&format!("/uploads/{upload_id}/parts"), request) + .post_form(&format!("/uploads/{upload_id}/parts"), request, &self.request_options) .await } @@ -75,7 +79,7 @@ impl<'c, C: Config> Uploads<'c, C> { request: CompleteUploadRequest, ) -> Result { self.client - .post(&format!("/uploads/{upload_id}/complete"), request) + .post(&format!("/uploads/{upload_id}/complete"), request, &self.request_options) .await } @@ -86,6 +90,7 @@ impl<'c, C: Config> Uploads<'c, C> { .post( &format!("/uploads/{upload_id}/cancel"), serde_json::json!({}), + &self.request_options, ) .await } diff --git a/async-openai/src/usage.rs b/async-openai/src/usage.rs index e6737c61..e6741b69 100644 --- a/async-openai/src/usage.rs +++ b/async-openai/src/usage.rs @@ -1,16 +1,20 @@ use serde::Serialize; -use crate::{config::Config, error::OpenAIError, types::admin::usage::UsageResponse, Client}; +use crate::{config::Config, error::OpenAIError, types::admin::usage::UsageResponse, Client, RequestOptions}; /// Manage organization usage data. Get usage details for various API endpoints including /// completions, embeddings, images, audio, moderations, vector stores, and code interpreter sessions. pub struct Usage<'c, C: Config> { client: &'c Client, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> Usage<'c, C> { pub fn new(client: &'c Client) -> Self { - Self { client } + Self { + client, + request_options: RequestOptions::new(), + } } /// Get audio speeches usage details for the organization. @@ -20,7 +24,7 @@ impl<'c, C: Config> Usage<'c, C> { Q: Serialize + ?Sized, { self.client - .get_with_query("/organization/usage/audio_speeches", &query) + .get_with_query("/organization/usage/audio_speeches", &query, &self.request_options) .await } @@ -31,7 +35,7 @@ impl<'c, C: Config> Usage<'c, C> { Q: Serialize + ?Sized, { self.client - .get_with_query("/organization/usage/audio_transcriptions", &query) + .get_with_query("/organization/usage/audio_transcriptions", &query, &self.request_options) .await } @@ -45,7 +49,7 @@ impl<'c, C: Config> Usage<'c, C> { Q: Serialize + ?Sized, { self.client - .get_with_query("/organization/usage/code_interpreter_sessions", &query) + .get_with_query("/organization/usage/code_interpreter_sessions", &query, &self.request_options) .await } @@ -56,7 +60,7 @@ impl<'c, C: Config> Usage<'c, C> { Q: Serialize + ?Sized, { self.client - .get_with_query("/organization/usage/completions", &query) + .get_with_query("/organization/usage/completions", &query, &self.request_options) .await } @@ -67,7 +71,7 @@ impl<'c, C: Config> Usage<'c, C> { Q: Serialize + ?Sized, { self.client - .get_with_query("/organization/usage/embeddings", &query) + .get_with_query("/organization/usage/embeddings", &query, &self.request_options) .await } @@ -78,7 +82,7 @@ impl<'c, C: Config> Usage<'c, C> { Q: Serialize + ?Sized, { self.client - .get_with_query("/organization/usage/images", &query) + .get_with_query("/organization/usage/images", &query, &self.request_options) .await } @@ -89,7 +93,7 @@ impl<'c, C: Config> Usage<'c, C> { Q: Serialize + ?Sized, { self.client - .get_with_query("/organization/usage/moderations", &query) + .get_with_query("/organization/usage/moderations", &query, &self.request_options) .await } @@ -100,7 +104,7 @@ impl<'c, C: Config> Usage<'c, C> { Q: Serialize + ?Sized, { self.client - .get_with_query("/organization/usage/vector_stores", &query) + .get_with_query("/organization/usage/vector_stores", &query, &self.request_options) .await } @@ -111,7 +115,7 @@ impl<'c, C: Config> Usage<'c, C> { Q: Serialize + ?Sized, { self.client - .get_with_query("/organization/costs", &query) + .get_with_query("/organization/costs", &query, &self.request_options) .await } } diff --git a/async-openai/src/users.rs b/async-openai/src/users.rs index a958acb3..8c1201f3 100644 --- a/async-openai/src/users.rs +++ b/async-openai/src/users.rs @@ -4,17 +4,21 @@ use crate::{ config::Config, error::OpenAIError, types::admin::users::{User, UserDeleteResponse, UserListResponse, UserRoleUpdateRequest}, - Client, + Client, RequestOptions, }; /// Manage users and their role in an organization. Users will be automatically added to the Default project. pub struct Users<'c, C: Config> { client: &'c Client, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> Users<'c, C> { pub fn new(client: &'c Client) -> Self { - Self { client } + Self { + client, + request_options: RequestOptions::new(), + } } /// Lists all of the users in the organization. @@ -24,7 +28,7 @@ impl<'c, C: Config> Users<'c, C> { Q: Serialize + ?Sized, { self.client - .get_with_query("/organization/users", &query) + .get_with_query("/organization/users", &query, &self.request_options) .await } @@ -36,7 +40,7 @@ impl<'c, C: Config> Users<'c, C> { request: UserRoleUpdateRequest, ) -> Result { self.client - .post(format!("/organization/users/{user_id}").as_str(), request) + .post(format!("/organization/users/{user_id}").as_str(), request, &self.request_options) .await } @@ -44,7 +48,7 @@ impl<'c, C: Config> Users<'c, C> { #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, user_id: &str) -> Result { self.client - .get(format!("/organization/users/{user_id}").as_str()) + .get(format!("/organization/users/{user_id}").as_str(), &self.request_options) .await } @@ -52,7 +56,7 @@ impl<'c, C: Config> Users<'c, C> { #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn delete(&self, user_id: &str) -> Result { self.client - .delete(format!("/organizations/users/{user_id}").as_str()) + .delete(format!("/organizations/users/{user_id}").as_str(), &self.request_options) .await } } diff --git a/async-openai/src/vector_store_file_batches.rs b/async-openai/src/vector_store_file_batches.rs index e7a34a33..e4e9e13b 100644 --- a/async-openai/src/vector_store_file_batches.rs +++ b/async-openai/src/vector_store_file_batches.rs @@ -6,7 +6,7 @@ use crate::{ types::vectorstores::{ CreateVectorStoreFileBatchRequest, ListVectorStoreFilesResponse, VectorStoreFileBatchObject, }, - Client, + Client, RequestOptions, }; /// Vector store file batches represent operations to add multiple files to a vector store. @@ -15,6 +15,7 @@ use crate::{ pub struct VectorStoreFileBatches<'c, C: Config> { client: &'c Client, pub vector_store_id: String, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> VectorStoreFileBatches<'c, C> { @@ -22,6 +23,7 @@ impl<'c, C: Config> VectorStoreFileBatches<'c, C> { Self { client, vector_store_id: vector_store_id.into(), + request_options: RequestOptions::new(), } } @@ -35,6 +37,7 @@ impl<'c, C: Config> VectorStoreFileBatches<'c, C> { .post( &format!("/vector_stores/{}/file_batches", &self.vector_store_id), request, + &self.request_options, ) .await } @@ -49,7 +52,7 @@ impl<'c, C: Config> VectorStoreFileBatches<'c, C> { .get(&format!( "/vector_stores/{}/file_batches/{batch_id}", &self.vector_store_id - )) + ), &self.request_options) .await } @@ -63,6 +66,7 @@ impl<'c, C: Config> VectorStoreFileBatches<'c, C> { &self.vector_store_id ), serde_json::json!({}), + &self.request_options, ) .await } @@ -84,6 +88,7 @@ impl<'c, C: Config> VectorStoreFileBatches<'c, C> { &self.vector_store_id ), &query, + &self.request_options, ) .await } diff --git a/async-openai/src/vector_store_files.rs b/async-openai/src/vector_store_files.rs index 1b72dc2c..edd5414a 100644 --- a/async-openai/src/vector_store_files.rs +++ b/async-openai/src/vector_store_files.rs @@ -8,7 +8,7 @@ use crate::{ UpdateVectorStoreFileAttributesRequest, VectorStoreFileContentResponse, VectorStoreFileObject, }, - Client, + Client, RequestOptions, }; /// Vector store files represent files inside a vector store. @@ -17,6 +17,7 @@ use crate::{ pub struct VectorStoreFiles<'c, C: Config> { client: &'c Client, pub vector_store_id: String, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> VectorStoreFiles<'c, C> { @@ -24,6 +25,7 @@ impl<'c, C: Config> VectorStoreFiles<'c, C> { Self { client, vector_store_id: vector_store_id.into(), + request_options: RequestOptions::new(), } } @@ -37,6 +39,7 @@ impl<'c, C: Config> VectorStoreFiles<'c, C> { .post( &format!("/vector_stores/{}/files", &self.vector_store_id), request, + &self.request_options, ) .await } @@ -48,7 +51,7 @@ impl<'c, C: Config> VectorStoreFiles<'c, C> { .get(&format!( "/vector_stores/{}/files/{file_id}", &self.vector_store_id - )) + ), &self.request_options) .await } @@ -62,7 +65,7 @@ impl<'c, C: Config> VectorStoreFiles<'c, C> { .delete(&format!( "/vector_stores/{}/files/{file_id}", &self.vector_store_id - )) + ), &self.request_options) .await } @@ -76,6 +79,7 @@ impl<'c, C: Config> VectorStoreFiles<'c, C> { .get_with_query( &format!("/vector_stores/{}/files", &self.vector_store_id), &query, + &self.request_options, ) .await } @@ -91,6 +95,7 @@ impl<'c, C: Config> VectorStoreFiles<'c, C> { .post( &format!("/vector_stores/{}/files/{file_id}", &self.vector_store_id), request, + &self.request_options, ) .await } @@ -105,7 +110,7 @@ impl<'c, C: Config> VectorStoreFiles<'c, C> { .get(&format!( "/vector_stores/{}/files/{file_id}/content", &self.vector_store_id - )) + ), &self.request_options) .await } } diff --git a/async-openai/src/vector_stores.rs b/async-openai/src/vector_stores.rs index 53764edd..c2af8342 100644 --- a/async-openai/src/vector_stores.rs +++ b/async-openai/src/vector_stores.rs @@ -9,16 +9,20 @@ use crate::{ VectorStoreSearchResultsPage, }, vector_store_file_batches::VectorStoreFileBatches, - Client, VectorStoreFiles, + Client, RequestOptions, VectorStoreFiles, }; pub struct VectorStores<'c, C: Config> { client: &'c Client, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> VectorStores<'c, C> { pub fn new(client: &'c Client) -> Self { - Self { client } + Self { + client, + request_options: RequestOptions::new(), + } } /// [VectorStoreFiles] API group @@ -37,14 +41,14 @@ impl<'c, C: Config> VectorStores<'c, C> { &self, request: CreateVectorStoreRequest, ) -> Result { - self.client.post("/vector_stores", request).await + self.client.post("/vector_stores", request, &self.request_options).await } /// Retrieves a vector store. #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, vector_store_id: &str) -> Result { self.client - .get(&format!("/vector_stores/{vector_store_id}")) + .get(&format!("/vector_stores/{vector_store_id}"), &self.request_options) .await } @@ -54,7 +58,7 @@ impl<'c, C: Config> VectorStores<'c, C> { where Q: Serialize + ?Sized, { - self.client.get_with_query("/vector_stores", &query).await + self.client.get_with_query("/vector_stores", &query, &self.request_options).await } /// Delete a vector store. @@ -64,7 +68,7 @@ impl<'c, C: Config> VectorStores<'c, C> { vector_store_id: &str, ) -> Result { self.client - .delete(&format!("/vector_stores/{vector_store_id}")) + .delete(&format!("/vector_stores/{vector_store_id}"), &self.request_options) .await } @@ -76,7 +80,7 @@ impl<'c, C: Config> VectorStores<'c, C> { request: UpdateVectorStoreRequest, ) -> Result { self.client - .post(&format!("/vector_stores/{vector_store_id}"), request) + .post(&format!("/vector_stores/{vector_store_id}"), request, &self.request_options) .await } @@ -88,7 +92,7 @@ impl<'c, C: Config> VectorStores<'c, C> { request: VectorStoreSearchRequest, ) -> Result { self.client - .post(&format!("/vector_stores/{vector_store_id}/search"), request) + .post(&format!("/vector_stores/{vector_store_id}/search"), request, &self.request_options) .await } } diff --git a/async-openai/src/video.rs b/async-openai/src/video.rs index 1c4df63e..c2eda7d3 100644 --- a/async-openai/src/video.rs +++ b/async-openai/src/video.rs @@ -5,7 +5,7 @@ use crate::{ CreateVideoRequest, ListVideosResponse, RemixVideoRequest, VideoJob, VideoJobMetadata, VideoVariant, }, - Client, + Client, RequestOptions, }; use bytes::Bytes; use serde::Serialize; @@ -14,11 +14,15 @@ use serde::Serialize; /// Related guide: [Video generation](https://platform.openai.com/docs/guides/video-generation) pub struct Videos<'c, C: Config> { client: &'c Client, + pub(crate) request_options: RequestOptions, } impl<'c, C: Config> Videos<'c, C> { pub fn new(client: &'c Client) -> Self { - Self { client } + Self { + client, + request_options: RequestOptions::new(), + } } /// Create a video @@ -28,7 +32,7 @@ impl<'c, C: Config> Videos<'c, C> { where_clause = "reqwest::multipart::Form: crate::traits::AsyncTryFrom", )] pub async fn create(&self, request: CreateVideoRequest) -> Result { - self.client.post_form("/videos", request).await + self.client.post_form("/videos", request, &self.request_options).await } /// Create a video remix @@ -39,20 +43,20 @@ impl<'c, C: Config> Videos<'c, C> { request: RemixVideoRequest, ) -> Result { self.client - .post(&format!("/videos/{video_id}/remix"), request) + .post(&format!("/videos/{video_id}/remix"), request, &self.request_options) .await } /// Retrieves a video by its ID. #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, video_id: &str) -> Result { - self.client.get(&format!("/videos/{}", video_id)).await + self.client.get(&format!("/videos/{}", video_id), &self.request_options).await } /// Delete a Video #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn delete(&self, video_id: &str) -> Result { - self.client.delete(&format!("/videos/{}", video_id)).await + self.client.delete(&format!("/videos/{}", video_id), &self.request_options).await } /// List Videos @@ -61,7 +65,7 @@ impl<'c, C: Config> Videos<'c, C> { where Q: Serialize + ?Sized, { - self.client.get_with_query("/videos", &query).await + self.client.get_with_query("/videos", &query, &self.request_options).await } /// Download video content diff --git a/examples/chat/src/main.rs b/examples/chat/src/main.rs index 0c529bfc..07b3b63c 100644 --- a/examples/chat/src/main.rs +++ b/examples/chat/src/main.rs @@ -1,6 +1,7 @@ use std::error::Error; use async_openai::{ + traits::RequestOptionsBuilder, types::chat::{ ChatCompletionRequestAssistantMessageArgs, ChatCompletionRequestSystemMessageArgs, ChatCompletionRequestUserMessageArgs, CreateChatCompletionRequestArgs, @@ -37,7 +38,11 @@ async fn main() -> Result<(), Box> { println!("{}", serde_json::to_string(&request).unwrap()); - let response = client.chat().create(request).await?; + let response = client + .chat() + .query(&vec![("limit", 10)])? + .create(request) + .await?; println!("\nResponse:\n"); for choice in response.choices { From 914e622999db6639af71c115b8254f21a3c33d50 Mon Sep 17 00:00:00 2001 From: Himanshu Neema Date: Mon, 17 Nov 2025 16:28:44 -0800 Subject: [PATCH 02/22] cargo fmt --- async-openai/src/assistants.rs | 24 ++++++++-- async-openai/src/audit_logs.rs | 3 +- async-openai/src/batches.rs | 12 +++-- async-openai/src/certificates.rs | 22 +++++++-- async-openai/src/chatkit.rs | 24 ++++++++-- async-openai/src/completion.rs | 9 +++- async-openai/src/container_files.rs | 22 +++++++-- async-openai/src/containers.rs | 18 ++++++-- async-openai/src/conversation_items.rs | 16 +++---- async-openai/src/conversations.rs | 20 ++++++-- async-openai/src/embedding.rs | 8 +++- async-openai/src/eval_run_output_items.rs | 11 +++-- async-openai/src/eval_runs.rs | 22 +++++++-- async-openai/src/evals.rs | 16 +++++-- async-openai/src/file.rs | 12 +++-- async-openai/src/fine_tuning.rs | 9 +++- async-openai/src/image.rs | 16 +++++-- async-openai/src/invites.rs | 14 ++++-- async-openai/src/messages.rs | 28 +++++++---- async-openai/src/model.rs | 4 +- async-openai/src/moderation.rs | 4 +- async-openai/src/project_users.rs | 10 +++- async-openai/src/projects.rs | 9 +++- async-openai/src/responses.rs | 30 +++++++++--- async-openai/src/runs.rs | 17 +++++-- async-openai/src/speech.rs | 10 +++- async-openai/src/threads.rs | 29 +++++++++--- async-openai/src/translations.rs | 8 +++- async-openai/src/uploads.rs | 16 +++++-- async-openai/src/usage.rs | 46 +++++++++++++++---- async-openai/src/users.rs | 16 +++++-- async-openai/src/vector_store_file_batches.rs | 11 +++-- async-openai/src/vector_store_files.rs | 27 ++++++----- async-openai/src/vector_stores.rs | 30 +++++++++--- async-openai/src/video.rs | 22 +++++++-- 35 files changed, 453 insertions(+), 142 deletions(-) diff --git a/async-openai/src/assistants.rs b/async-openai/src/assistants.rs index 196b3524..573dbb65 100644 --- a/async-openai/src/assistants.rs +++ b/async-openai/src/assistants.rs @@ -32,14 +32,19 @@ impl<'c, C: Config> Assistants<'c, C> { &self, request: CreateAssistantRequest, ) -> Result { - self.client.post("/assistants", request, &self.request_options).await + self.client + .post("/assistants", request, &self.request_options) + .await } /// Retrieves an assistant. #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, assistant_id: &str) -> Result { self.client - .get(&format!("/assistants/{assistant_id}"), &self.request_options) + .get( + &format!("/assistants/{assistant_id}"), + &self.request_options, + ) .await } @@ -51,7 +56,11 @@ impl<'c, C: Config> Assistants<'c, C> { request: ModifyAssistantRequest, ) -> Result { self.client - .post(&format!("/assistants/{assistant_id}"), request, &self.request_options) + .post( + &format!("/assistants/{assistant_id}"), + request, + &self.request_options, + ) .await } @@ -59,7 +68,10 @@ impl<'c, C: Config> Assistants<'c, C> { #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn delete(&self, assistant_id: &str) -> Result { self.client - .delete(&format!("/assistants/{assistant_id}"), &self.request_options) + .delete( + &format!("/assistants/{assistant_id}"), + &self.request_options, + ) .await } @@ -69,6 +81,8 @@ impl<'c, C: Config> Assistants<'c, C> { where Q: Serialize + ?Sized, { - self.client.get_with_query("/assistants", &query, &self.request_options).await + self.client + .get_with_query("/assistants", &query, &self.request_options) + .await } } diff --git a/async-openai/src/audit_logs.rs b/async-openai/src/audit_logs.rs index e170db90..a5169b0a 100644 --- a/async-openai/src/audit_logs.rs +++ b/async-openai/src/audit_logs.rs @@ -1,7 +1,8 @@ use serde::Serialize; use crate::{ - config::Config, error::OpenAIError, types::admin::audit_logs::ListAuditLogsResponse, Client, RequestOptions, + config::Config, error::OpenAIError, types::admin::audit_logs::ListAuditLogsResponse, Client, + RequestOptions, }; /// Logs of user actions and configuration changes within this organization. diff --git a/async-openai/src/batches.rs b/async-openai/src/batches.rs index df62ca9c..c0485778 100644 --- a/async-openai/src/batches.rs +++ b/async-openai/src/batches.rs @@ -26,7 +26,9 @@ impl<'c, C: Config> Batches<'c, C> { /// Creates and executes a batch from an uploaded file of requests #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] pub async fn create(&self, request: BatchRequest) -> Result { - self.client.post("/batches", request, &self.request_options).await + self.client + .post("/batches", request, &self.request_options) + .await } /// List your organization's batches. @@ -35,13 +37,17 @@ impl<'c, C: Config> Batches<'c, C> { where Q: Serialize + ?Sized, { - self.client.get_with_query("/batches", &query, &self.request_options).await + self.client + .get_with_query("/batches", &query, &self.request_options) + .await } /// Retrieves a batch. #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, batch_id: &str) -> Result { - self.client.get(&format!("/batches/{batch_id}"), &self.request_options).await + self.client + .get(&format!("/batches/{batch_id}"), &self.request_options) + .await } /// Cancels an in-progress batch. The batch will be in status `cancelling` for up to 10 minutes, before changing to `cancelled`, where it will have partial results (if any) available in the output file. diff --git a/async-openai/src/certificates.rs b/async-openai/src/certificates.rs index 9eee1c0e..8e4fb092 100644 --- a/async-openai/src/certificates.rs +++ b/async-openai/src/certificates.rs @@ -59,7 +59,11 @@ impl<'c, C: Config> Certificates<'c, C> { request: ToggleCertificatesRequest, ) -> Result { self.client - .post("/organization/certificates/activate", request, &self.request_options) + .post( + "/organization/certificates/activate", + request, + &self.request_options, + ) .await } @@ -70,7 +74,11 @@ impl<'c, C: Config> Certificates<'c, C> { request: ToggleCertificatesRequest, ) -> Result { self.client - .post("/organization/certificates/deactivate", request, &self.request_options) + .post( + "/organization/certificates/deactivate", + request, + &self.request_options, + ) .await } @@ -78,7 +86,10 @@ impl<'c, C: Config> Certificates<'c, C> { #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, certificate_id: &str) -> Result { self.client - .get(format!("/organization/certificates/{certificate_id}").as_str(), &self.request_options) + .get( + format!("/organization/certificates/{certificate_id}").as_str(), + &self.request_options, + ) .await } @@ -124,7 +135,10 @@ impl<'c, C: Config> Certificates<'c, C> { certificate_id: &str, ) -> Result { self.client - .delete(format!("/organization/certificates/{certificate_id}").as_str(), &self.request_options) + .delete( + format!("/organization/certificates/{certificate_id}").as_str(), + &self.request_options, + ) .await } } diff --git a/async-openai/src/chatkit.rs b/async-openai/src/chatkit.rs index 17161108..0c899ca2 100644 --- a/async-openai/src/chatkit.rs +++ b/async-openai/src/chatkit.rs @@ -57,7 +57,9 @@ impl<'c, C: Config> ChatkitSessions<'c, C> { &self, request: CreateChatSessionBody, ) -> Result { - self.client.post("/chatkit/sessions", request, &self.request_options).await + self.client + .post("/chatkit/sessions", request, &self.request_options) + .await } /// Cancel a ChatKit session. @@ -93,14 +95,19 @@ impl<'c, C: Config> ChatkitThreads<'c, C> { where Q: Serialize + ?Sized, { - self.client.get_with_query("/chatkit/threads", &query, &self.request_options).await + self.client + .get_with_query("/chatkit/threads", &query, &self.request_options) + .await } /// Retrieve a ChatKit thread. #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, thread_id: &str) -> Result { self.client - .get(&format!("/chatkit/threads/{thread_id}"), &self.request_options) + .get( + &format!("/chatkit/threads/{thread_id}"), + &self.request_options, + ) .await } @@ -108,7 +115,10 @@ impl<'c, C: Config> ChatkitThreads<'c, C> { #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn delete(&self, thread_id: &str) -> Result { self.client - .delete(&format!("/chatkit/threads/{thread_id}"), &self.request_options) + .delete( + &format!("/chatkit/threads/{thread_id}"), + &self.request_options, + ) .await } @@ -123,7 +133,11 @@ impl<'c, C: Config> ChatkitThreads<'c, C> { Q: Serialize + ?Sized, { self.client - .get_with_query(&format!("/chatkit/threads/{thread_id}/items"), &query, &self.request_options) + .get_with_query( + &format!("/chatkit/threads/{thread_id}/items"), + &query, + &self.request_options, + ) .await } } diff --git a/async-openai/src/completion.rs b/async-openai/src/completion.rs index 56fc02a3..2d21b9cc 100644 --- a/async-openai/src/completion.rs +++ b/async-openai/src/completion.rs @@ -44,7 +44,9 @@ impl<'c, C: Config> Completions<'c, C> { )); } } - self.client.post("/completions", request, &self.request_options).await + self.client + .post("/completions", request, &self.request_options) + .await } /// Creates a completion request for the provided prompt and parameters @@ -77,6 +79,9 @@ impl<'c, C: Config> Completions<'c, C> { request.stream = Some(true); } - Ok(self.client.post_stream("/completions", request, &self.request_options).await) + Ok(self + .client + .post_stream("/completions", request, &self.request_options) + .await) } } diff --git a/async-openai/src/container_files.rs b/async-openai/src/container_files.rs index 7a25fe51..43502275 100644 --- a/async-openai/src/container_files.rs +++ b/async-openai/src/container_files.rs @@ -38,7 +38,11 @@ impl<'c, C: Config> ContainerFiles<'c, C> { request: CreateContainerFileRequest, ) -> Result { self.client - .post_form(&format!("/containers/{}/files", self.container_id), request, &self.request_options) + .post_form( + &format!("/containers/{}/files", self.container_id), + request, + &self.request_options, + ) .await } @@ -49,7 +53,11 @@ impl<'c, C: Config> ContainerFiles<'c, C> { Q: Serialize + ?Sized, { self.client - .get_with_query(&format!("/containers/{}/files", self.container_id), &query, &self.request_options) + .get_with_query( + &format!("/containers/{}/files", self.container_id), + &query, + &self.request_options, + ) .await } @@ -57,7 +65,10 @@ impl<'c, C: Config> ContainerFiles<'c, C> { #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, file_id: &str) -> Result { self.client - .get(format!("/containers/{}/files/{file_id}", self.container_id).as_str(), &self.request_options) + .get( + format!("/containers/{}/files/{file_id}", self.container_id).as_str(), + &self.request_options, + ) .await } @@ -65,7 +76,10 @@ impl<'c, C: Config> ContainerFiles<'c, C> { #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn delete(&self, file_id: &str) -> Result { self.client - .delete(format!("/containers/{}/files/{file_id}", self.container_id).as_str(), &self.request_options) + .delete( + format!("/containers/{}/files/{file_id}", self.container_id).as_str(), + &self.request_options, + ) .await } diff --git a/async-openai/src/containers.rs b/async-openai/src/containers.rs index 3871f8b9..46c28944 100644 --- a/async-openai/src/containers.rs +++ b/async-openai/src/containers.rs @@ -34,7 +34,9 @@ impl<'c, C: Config> Containers<'c, C> { &self, request: CreateContainerRequest, ) -> Result { - self.client.post("/containers", request, &self.request_options).await + self.client + .post("/containers", request, &self.request_options) + .await } /// List containers. @@ -43,14 +45,19 @@ impl<'c, C: Config> Containers<'c, C> { where Q: Serialize + ?Sized, { - self.client.get_with_query("/containers", &query, &self.request_options).await + self.client + .get_with_query("/containers", &query, &self.request_options) + .await } /// Retrieve a container. #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, container_id: &str) -> Result { self.client - .get(format!("/containers/{container_id}").as_str(), &self.request_options) + .get( + format!("/containers/{container_id}").as_str(), + &self.request_options, + ) .await } @@ -58,7 +65,10 @@ impl<'c, C: Config> Containers<'c, C> { #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn delete(&self, container_id: &str) -> Result { self.client - .delete(format!("/containers/{container_id}").as_str(), &self.request_options) + .delete( + format!("/containers/{container_id}").as_str(), + &self.request_options, + ) .await } } diff --git a/async-openai/src/conversation_items.rs b/async-openai/src/conversation_items.rs index a86e77d8..823ba6b9 100644 --- a/async-openai/src/conversation_items.rs +++ b/async-openai/src/conversation_items.rs @@ -60,10 +60,10 @@ impl<'c, C: Config> ConversationItems<'c, C> { #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, item_id: &str) -> Result { self.client - .get(&format!( - "/conversations/{}/items/{item_id}", - &self.conversation_id - ), &self.request_options) + .get( + &format!("/conversations/{}/items/{item_id}", &self.conversation_id), + &self.request_options, + ) .await } @@ -71,10 +71,10 @@ impl<'c, C: Config> ConversationItems<'c, C> { #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn delete(&self, item_id: &str) -> Result { self.client - .delete(&format!( - "/conversations/{}/items/{item_id}", - &self.conversation_id - ), &self.request_options) + .delete( + &format!("/conversations/{}/items/{item_id}", &self.conversation_id), + &self.request_options, + ) .await } } diff --git a/async-openai/src/conversations.rs b/async-openai/src/conversations.rs index 1f2bbf10..87598ef6 100644 --- a/async-openai/src/conversations.rs +++ b/async-openai/src/conversations.rs @@ -33,7 +33,9 @@ impl<'c, C: Config> Conversations<'c, C> { &self, request: CreateConversationRequest, ) -> Result { - self.client.post("/conversations", request, &self.request_options).await + self.client + .post("/conversations", request, &self.request_options) + .await } /// Retrieves a conversation. @@ -43,7 +45,10 @@ impl<'c, C: Config> Conversations<'c, C> { conversation_id: &str, ) -> Result { self.client - .get(&format!("/conversations/{conversation_id}"), &self.request_options) + .get( + &format!("/conversations/{conversation_id}"), + &self.request_options, + ) .await } @@ -54,7 +59,10 @@ impl<'c, C: Config> Conversations<'c, C> { conversation_id: &str, ) -> Result { self.client - .delete(&format!("/conversations/{conversation_id}"), &self.request_options) + .delete( + &format!("/conversations/{conversation_id}"), + &self.request_options, + ) .await } @@ -66,7 +74,11 @@ impl<'c, C: Config> Conversations<'c, C> { request: UpdateConversationRequest, ) -> Result { self.client - .post(&format!("/conversations/{conversation_id}"), request, &self.request_options) + .post( + &format!("/conversations/{conversation_id}"), + request, + &self.request_options, + ) .await } } diff --git a/async-openai/src/embedding.rs b/async-openai/src/embedding.rs index 9044c312..a1975a77 100644 --- a/async-openai/src/embedding.rs +++ b/async-openai/src/embedding.rs @@ -43,7 +43,9 @@ impl<'c, C: Config> Embeddings<'c, C> { )); } } - self.client.post("/embeddings", request, &self.request_options).await + self.client + .post("/embeddings", request, &self.request_options) + .await } /// Creates an embedding vector representing the input text. @@ -64,7 +66,9 @@ impl<'c, C: Config> Embeddings<'c, C> { )); } } - self.client.post("/embeddings", request, &self.request_options).await + self.client + .post("/embeddings", request, &self.request_options) + .await } } diff --git a/async-openai/src/eval_run_output_items.rs b/async-openai/src/eval_run_output_items.rs index fe3d8072..a30fd7e0 100644 --- a/async-openai/src/eval_run_output_items.rs +++ b/async-openai/src/eval_run_output_items.rs @@ -43,10 +43,13 @@ impl<'c, C: Config> EvalRunOutputItems<'c, C> { #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, output_item_id: &str) -> Result { self.client - .get(&format!( - "/evals/{}/runs/{}/output_items/{}", - self.eval_id, self.run_id, output_item_id - ), &self.request_options) + .get( + &format!( + "/evals/{}/runs/{}/output_items/{}", + self.eval_id, self.run_id, output_item_id + ), + &self.request_options, + ) .await } } diff --git a/async-openai/src/eval_runs.rs b/async-openai/src/eval_runs.rs index 8415335c..907599a1 100644 --- a/async-openai/src/eval_runs.rs +++ b/async-openai/src/eval_runs.rs @@ -35,7 +35,11 @@ impl<'c, C: Config> EvalRuns<'c, C> { Q: Serialize + ?Sized, { self.client - .get_with_query(&format!("/evals/{}/runs", self.eval_id), &query, &self.request_options) + .get_with_query( + &format!("/evals/{}/runs", self.eval_id), + &query, + &self.request_options, + ) .await } @@ -43,7 +47,11 @@ impl<'c, C: Config> EvalRuns<'c, C> { #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] pub async fn create(&self, request: CreateEvalRunRequest) -> Result { self.client - .post(&format!("/evals/{}/runs", self.eval_id), request, &self.request_options) + .post( + &format!("/evals/{}/runs", self.eval_id), + request, + &self.request_options, + ) .await } @@ -51,7 +59,10 @@ impl<'c, C: Config> EvalRuns<'c, C> { #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, run_id: &str) -> Result { self.client - .get(&format!("/evals/{}/runs/{}", self.eval_id, run_id), &self.request_options) + .get( + &format!("/evals/{}/runs/{}", self.eval_id, run_id), + &self.request_options, + ) .await } @@ -71,7 +82,10 @@ impl<'c, C: Config> EvalRuns<'c, C> { #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn delete(&self, run_id: &str) -> Result { self.client - .delete(&format!("/evals/{}/runs/{}", self.eval_id, run_id), &self.request_options) + .delete( + &format!("/evals/{}/runs/{}", self.eval_id, run_id), + &self.request_options, + ) .await } } diff --git a/async-openai/src/evals.rs b/async-openai/src/evals.rs index f5ea2d37..6f307bdd 100644 --- a/async-openai/src/evals.rs +++ b/async-openai/src/evals.rs @@ -34,7 +34,9 @@ impl<'c, C: Config> Evals<'c, C> { where Q: Serialize + ?Sized, { - self.client.get_with_query("/evals", &query, &self.request_options).await + self.client + .get_with_query("/evals", &query, &self.request_options) + .await } /// Create the structure of an evaluation that can be used to test a model's performance. @@ -44,13 +46,17 @@ impl<'c, C: Config> Evals<'c, C> { /// datasources. For more information, see the [Evals guide](https://platform.openai.com/docs/guides/evals). #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] pub async fn create(&self, request: CreateEvalRequest) -> Result { - self.client.post("/evals", request, &self.request_options).await + self.client + .post("/evals", request, &self.request_options) + .await } /// Get an evaluation by ID. #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, eval_id: &str) -> Result { - self.client.get(&format!("/evals/{eval_id}"), &self.request_options).await + self.client + .get(&format!("/evals/{eval_id}"), &self.request_options) + .await } /// Update certain properties of an evaluation. @@ -68,6 +74,8 @@ impl<'c, C: Config> Evals<'c, C> { /// Delete an evaluation. #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn delete(&self, eval_id: &str) -> Result { - self.client.delete(&format!("/evals/{eval_id}"), &self.request_options).await + self.client + .delete(&format!("/evals/{eval_id}"), &self.request_options) + .await } } diff --git a/async-openai/src/file.rs b/async-openai/src/file.rs index 6d142dcc..6d760677 100644 --- a/async-openai/src/file.rs +++ b/async-openai/src/file.rs @@ -37,7 +37,9 @@ impl<'c, C: Config> Files<'c, C> { where_clause = "reqwest::multipart::Form: crate::traits::AsyncTryFrom", )] pub async fn create(&self, request: CreateFileRequest) -> Result { - self.client.post_form("/files", request, &self.request_options).await + self.client + .post_form("/files", request, &self.request_options) + .await } /// Returns a list of files that belong to the user's organization. @@ -46,13 +48,17 @@ impl<'c, C: Config> Files<'c, C> { where Q: Serialize + ?Sized, { - self.client.get_with_query("/files", &query, &self.request_options).await + self.client + .get_with_query("/files", &query, &self.request_options) + .await } /// Returns information about a specific file. #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, file_id: &str) -> Result { - self.client.get(format!("/files/{file_id}").as_str(), &self.request_options).await + self.client + .get(format!("/files/{file_id}").as_str(), &self.request_options) + .await } /// Delete a file. diff --git a/async-openai/src/fine_tuning.rs b/async-openai/src/fine_tuning.rs index 7c0a1a93..39d02554 100644 --- a/async-openai/src/fine_tuning.rs +++ b/async-openai/src/fine_tuning.rs @@ -39,7 +39,9 @@ impl<'c, C: Config> FineTuning<'c, C> { &self, request: CreateFineTuningJobRequest, ) -> Result { - self.client.post("/fine_tuning/jobs", request, &self.request_options).await + self.client + .post("/fine_tuning/jobs", request, &self.request_options) + .await } /// List your organization's fine-tuning jobs @@ -62,7 +64,10 @@ impl<'c, C: Config> FineTuning<'c, C> { #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, fine_tuning_job_id: &str) -> Result { self.client - .get(format!("/fine_tuning/jobs/{fine_tuning_job_id}").as_str(), &self.request_options) + .get( + format!("/fine_tuning/jobs/{fine_tuning_job_id}").as_str(), + &self.request_options, + ) .await } diff --git a/async-openai/src/image.rs b/async-openai/src/image.rs index c7297ee1..f7586cfd 100644 --- a/async-openai/src/image.rs +++ b/async-openai/src/image.rs @@ -30,7 +30,9 @@ impl<'c, C: Config> Images<'c, C> { &self, request: CreateImageRequest, ) -> Result { - self.client.post("/images/generations", request, &self.request_options).await + self.client + .post("/images/generations", request, &self.request_options) + .await } /// Creates an image given a prompt. @@ -73,7 +75,9 @@ impl<'c, C: Config> Images<'c, C> { &self, request: CreateImageEditRequest, ) -> Result { - self.client.post_form("/images/edits", request, &self.request_options).await + self.client + .post_form("/images/edits", request, &self.request_options) + .await } /// Creates an edited or extended image given one or more source images and a prompt. @@ -100,7 +104,9 @@ impl<'c, C: Config> Images<'c, C> { } request.stream = Some(true); } - self.client.post_form_stream("/images/edits", request, &self.request_options).await + self.client + .post_form_stream("/images/edits", request, &self.request_options) + .await } /// Creates a variation of a given image. This endpoint only supports dall-e-2. @@ -113,6 +119,8 @@ impl<'c, C: Config> Images<'c, C> { &self, request: CreateImageVariationRequest, ) -> Result { - self.client.post_form("/images/variations", request, &self.request_options).await + self.client + .post_form("/images/variations", request, &self.request_options) + .await } } diff --git a/async-openai/src/invites.rs b/async-openai/src/invites.rs index 62cb31f3..7e5e19ec 100644 --- a/async-openai/src/invites.rs +++ b/async-openai/src/invites.rs @@ -36,21 +36,29 @@ impl<'c, C: Config> Invites<'c, C> { #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, invite_id: &str) -> Result { self.client - .get(format!("/organization/invites/{invite_id}").as_str(), &self.request_options) + .get( + format!("/organization/invites/{invite_id}").as_str(), + &self.request_options, + ) .await } /// Create an invite for a user to the organization. The invite must be accepted by the user before they have access to the organization. #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] pub async fn create(&self, request: InviteRequest) -> Result { - self.client.post("/organization/invites", request, &self.request_options).await + self.client + .post("/organization/invites", request, &self.request_options) + .await } /// Delete an invite. If the invite has already been accepted, it cannot be deleted. #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn delete(&self, invite_id: &str) -> Result { self.client - .delete(format!("/organization/invites/{invite_id}").as_str(), &self.request_options) + .delete( + format!("/organization/invites/{invite_id}").as_str(), + &self.request_options, + ) .await } } diff --git a/async-openai/src/messages.rs b/async-openai/src/messages.rs index 4d0693fd..45d645c3 100644 --- a/async-openai/src/messages.rs +++ b/async-openai/src/messages.rs @@ -34,7 +34,11 @@ impl<'c, C: Config> Messages<'c, C> { request: CreateMessageRequest, ) -> Result { self.client - .post(&format!("/threads/{}/messages", self.thread_id), request, &self.request_options) + .post( + &format!("/threads/{}/messages", self.thread_id), + request, + &self.request_options, + ) .await } @@ -42,10 +46,10 @@ impl<'c, C: Config> Messages<'c, C> { #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, message_id: &str) -> Result { self.client - .get(&format!( - "/threads/{}/messages/{message_id}", - self.thread_id - ), &self.request_options) + .get( + &format!("/threads/{}/messages/{message_id}", self.thread_id), + &self.request_options, + ) .await } @@ -72,17 +76,21 @@ impl<'c, C: Config> Messages<'c, C> { Q: Serialize + ?Sized, { self.client - .get_with_query(&format!("/threads/{}/messages", self.thread_id), &query, &self.request_options) + .get_with_query( + &format!("/threads/{}/messages", self.thread_id), + &query, + &self.request_options, + ) .await } #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn delete(&self, message_id: &str) -> Result { self.client - .delete(&format!( - "/threads/{}/messages/{message_id}", - self.thread_id - ), &self.request_options) + .delete( + &format!("/threads/{}/messages/{message_id}", self.thread_id), + &self.request_options, + ) .await } } diff --git a/async-openai/src/model.rs b/async-openai/src/model.rs index 6a51795b..13f861ce 100644 --- a/async-openai/src/model.rs +++ b/async-openai/src/model.rs @@ -32,7 +32,9 @@ impl<'c, C: Config> Models<'c, C> { /// such as the owner and permissioning. #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, model: &str) -> Result { - self.client.get(format!("/models/{model}").as_str(), &self.request_options).await + self.client + .get(format!("/models/{model}").as_str(), &self.request_options) + .await } /// Delete a fine-tuned model. You must have the Owner role in your organization. diff --git a/async-openai/src/moderation.rs b/async-openai/src/moderation.rs index 29dde159..d20f5d0e 100644 --- a/async-openai/src/moderation.rs +++ b/async-openai/src/moderation.rs @@ -28,6 +28,8 @@ impl<'c, C: Config> Moderations<'c, C> { &self, request: CreateModerationRequest, ) -> Result { - self.client.post("/moderations", request, &self.request_options).await + self.client + .post("/moderations", request, &self.request_options) + .await } } diff --git a/async-openai/src/project_users.rs b/async-openai/src/project_users.rs index abef3320..98d4abc1 100644 --- a/async-openai/src/project_users.rs +++ b/async-openai/src/project_users.rs @@ -61,7 +61,10 @@ impl<'c, C: Config> ProjectUsers<'c, C> { #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, user_id: &str) -> Result { self.client - .get(format!("/organization/projects/{}/users/{user_id}", self.project_id).as_str(), &self.request_options) + .get( + format!("/organization/projects/{}/users/{user_id}", self.project_id).as_str(), + &self.request_options, + ) .await } @@ -85,7 +88,10 @@ impl<'c, C: Config> ProjectUsers<'c, C> { #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn delete(&self, user_id: &str) -> Result { self.client - .delete(format!("/organization/projects/{}/users/{user_id}", self.project_id).as_str(), &self.request_options) + .delete( + format!("/organization/projects/{}/users/{user_id}", self.project_id).as_str(), + &self.request_options, + ) .await } } diff --git a/async-openai/src/projects.rs b/async-openai/src/projects.rs index 7fc6b6a0..1c6b37e3 100644 --- a/async-openai/src/projects.rs +++ b/async-openai/src/projects.rs @@ -66,14 +66,19 @@ impl<'c, C: Config> Projects<'c, C> { /// Create a new project in the organization. Projects can be created and archived, but cannot be deleted. #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] pub async fn create(&self, request: ProjectCreateRequest) -> Result { - self.client.post("/organization/projects", request, &self.request_options).await + self.client + .post("/organization/projects", request, &self.request_options) + .await } /// Retrieves a project. #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, project_id: String) -> Result { self.client - .get(format!("/organization/projects/{project_id}").as_str(), &self.request_options) + .get( + format!("/organization/projects/{project_id}").as_str(), + &self.request_options, + ) .await } diff --git a/async-openai/src/responses.rs b/async-openai/src/responses.rs index 4cb6ebd9..389b9323 100644 --- a/async-openai/src/responses.rs +++ b/async-openai/src/responses.rs @@ -38,7 +38,9 @@ impl<'c, C: Config> Responses<'c, C> { R = serde::de::DeserializeOwned )] pub async fn create(&self, request: CreateResponse) -> Result { - self.client.post("/responses", request, &self.request_options).await + self.client + .post("/responses", request, &self.request_options) + .await } /// Creates a model response for the given input with streaming. @@ -64,7 +66,10 @@ impl<'c, C: Config> Responses<'c, C> { } request.stream = Some(true); } - Ok(self.client.post_stream("/responses", request, &self.request_options).await) + Ok(self + .client + .post_stream("/responses", request, &self.request_options) + .await) } /// Retrieves a model response with the given ID. @@ -74,7 +79,11 @@ impl<'c, C: Config> Responses<'c, C> { Q: Serialize + ?Sized, { self.client - .get_with_query(&format!("/responses/{}", response_id), &query, &self.request_options) + .get_with_query( + &format!("/responses/{}", response_id), + &query, + &self.request_options, + ) .await } @@ -82,7 +91,10 @@ impl<'c, C: Config> Responses<'c, C> { #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn delete(&self, response_id: &str) -> Result { self.client - .delete(&format!("/responses/{}", response_id), &self.request_options) + .delete( + &format!("/responses/{}", response_id), + &self.request_options, + ) .await } @@ -111,7 +123,11 @@ impl<'c, C: Config> Responses<'c, C> { Q: Serialize + ?Sized, { self.client - .get_with_query(&format!("/responses/{}/input_items", response_id), &query, &self.request_options) + .get_with_query( + &format!("/responses/{}/input_items", response_id), + &query, + &self.request_options, + ) .await } @@ -121,6 +137,8 @@ impl<'c, C: Config> Responses<'c, C> { &self, request: TokenCountsBody, ) -> Result { - self.client.post("/responses/input_tokens", request, &self.request_options).await + self.client + .post("/responses/input_tokens", request, &self.request_options) + .await } } diff --git a/async-openai/src/runs.rs b/async-openai/src/runs.rs index a81d8d47..d7b7f457 100644 --- a/async-openai/src/runs.rs +++ b/async-openai/src/runs.rs @@ -38,7 +38,11 @@ impl<'c, C: Config> Runs<'c, C> { #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] pub async fn create(&self, request: CreateRunRequest) -> Result { self.client - .post(&format!("/threads/{}/runs", self.thread_id), request, &self.request_options) + .post( + &format!("/threads/{}/runs", self.thread_id), + request, + &self.request_options, + ) .await } @@ -82,7 +86,10 @@ impl<'c, C: Config> Runs<'c, C> { #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, run_id: &str) -> Result { self.client - .get(&format!("/threads/{}/runs/{run_id}", self.thread_id), &self.request_options) + .get( + &format!("/threads/{}/runs/{run_id}", self.thread_id), + &self.request_options, + ) .await } @@ -109,7 +116,11 @@ impl<'c, C: Config> Runs<'c, C> { Q: Serialize + ?Sized, { self.client - .get_with_query(&format!("/threads/{}/runs", self.thread_id), &query, &self.request_options) + .get_with_query( + &format!("/threads/{}/runs", self.thread_id), + &query, + &self.request_options, + ) .await } diff --git a/async-openai/src/speech.rs b/async-openai/src/speech.rs index e0408c23..ea0bbc74 100644 --- a/async-openai/src/speech.rs +++ b/async-openai/src/speech.rs @@ -23,7 +23,10 @@ impl<'c, C: Config> Speech<'c, C> { &self, request: CreateSpeechRequest, ) -> Result { - let (bytes, _headers) = self.client.post_raw("/audio/speech", request, &self.request_options).await?; + let (bytes, _headers) = self + .client + .post_raw("/audio/speech", request, &self.request_options) + .await?; Ok(CreateSpeechResponse { bytes }) } @@ -53,6 +56,9 @@ impl<'c, C: Config> Speech<'c, C> { request.stream_format = Some(StreamFormat::SSE); } - Ok(self.client.post_stream("/audio/speech", request, &self.request_options).await) + Ok(self + .client + .post_stream("/audio/speech", request, &self.request_options) + .await) } } diff --git a/async-openai/src/threads.rs b/async-openai/src/threads.rs index 106e1e2e..d6bfec34 100644 --- a/async-openai/src/threads.rs +++ b/async-openai/src/threads.rs @@ -40,7 +40,9 @@ impl<'c, C: Config> Threads<'c, C> { &self, request: CreateThreadAndRunRequest, ) -> Result { - self.client.post("/threads/runs", request, &self.request_options).await + self.client + .post("/threads/runs", request, &self.request_options) + .await } /// Create a thread and run it in one request (streaming). @@ -69,20 +71,29 @@ impl<'c, C: Config> Threads<'c, C> { } Ok(self .client - .post_stream_mapped_raw_events("/threads/runs", request, &self.request_options, TryFrom::try_from) + .post_stream_mapped_raw_events( + "/threads/runs", + request, + &self.request_options, + TryFrom::try_from, + ) .await) } /// Create a thread. #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] pub async fn create(&self, request: CreateThreadRequest) -> Result { - self.client.post("/threads", request, &self.request_options).await + self.client + .post("/threads", request, &self.request_options) + .await } /// Retrieves a thread. #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, thread_id: &str) -> Result { - self.client.get(&format!("/threads/{thread_id}"), &self.request_options).await + self.client + .get(&format!("/threads/{thread_id}"), &self.request_options) + .await } /// Modifies a thread. @@ -93,13 +104,19 @@ impl<'c, C: Config> Threads<'c, C> { request: ModifyThreadRequest, ) -> Result { self.client - .post(&format!("/threads/{thread_id}"), request, &self.request_options) + .post( + &format!("/threads/{thread_id}"), + request, + &self.request_options, + ) .await } /// Delete a thread. #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn delete(&self, thread_id: &str) -> Result { - self.client.delete(&format!("/threads/{thread_id}"), &self.request_options).await + self.client + .delete(&format!("/threads/{thread_id}"), &self.request_options) + .await } } diff --git a/async-openai/src/translations.rs b/async-openai/src/translations.rs index c2f1ae0f..636423de 100644 --- a/async-openai/src/translations.rs +++ b/async-openai/src/translations.rs @@ -33,7 +33,9 @@ impl<'c, C: Config> Translations<'c, C> { &self, request: CreateTranslationRequest, ) -> Result { - self.client.post_form("/audio/translations", request, &self.request_options).await + self.client + .post_form("/audio/translations", request, &self.request_options) + .await } /// Translates audio into English. @@ -46,7 +48,9 @@ impl<'c, C: Config> Translations<'c, C> { &self, request: CreateTranslationRequest, ) -> Result { - self.client.post_form("/audio/translations", request, &self.request_options).await + self.client + .post_form("/audio/translations", request, &self.request_options) + .await } /// Transcribes audio into the input language. diff --git a/async-openai/src/uploads.rs b/async-openai/src/uploads.rs index 12d57b4d..4000a961 100644 --- a/async-openai/src/uploads.rs +++ b/async-openai/src/uploads.rs @@ -36,7 +36,9 @@ impl<'c, C: Config> Uploads<'c, C> { /// [creating a File](https://platform.openai.com/docs/api-reference/files/create). #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] pub async fn create(&self, request: CreateUploadRequest) -> Result { - self.client.post("/uploads", request, &self.request_options).await + self.client + .post("/uploads", request, &self.request_options) + .await } /// Adds a [Part](https://platform.openai.com/docs/api-reference/uploads/part-object) to an @@ -58,7 +60,11 @@ impl<'c, C: Config> Uploads<'c, C> { request: AddUploadPartRequest, ) -> Result { self.client - .post_form(&format!("/uploads/{upload_id}/parts"), request, &self.request_options) + .post_form( + &format!("/uploads/{upload_id}/parts"), + request, + &self.request_options, + ) .await } @@ -79,7 +85,11 @@ impl<'c, C: Config> Uploads<'c, C> { request: CompleteUploadRequest, ) -> Result { self.client - .post(&format!("/uploads/{upload_id}/complete"), request, &self.request_options) + .post( + &format!("/uploads/{upload_id}/complete"), + request, + &self.request_options, + ) .await } diff --git a/async-openai/src/usage.rs b/async-openai/src/usage.rs index e6741b69..66e07ec5 100644 --- a/async-openai/src/usage.rs +++ b/async-openai/src/usage.rs @@ -1,6 +1,8 @@ use serde::Serialize; -use crate::{config::Config, error::OpenAIError, types::admin::usage::UsageResponse, Client, RequestOptions}; +use crate::{ + config::Config, error::OpenAIError, types::admin::usage::UsageResponse, Client, RequestOptions, +}; /// Manage organization usage data. Get usage details for various API endpoints including /// completions, embeddings, images, audio, moderations, vector stores, and code interpreter sessions. @@ -24,7 +26,11 @@ impl<'c, C: Config> Usage<'c, C> { Q: Serialize + ?Sized, { self.client - .get_with_query("/organization/usage/audio_speeches", &query, &self.request_options) + .get_with_query( + "/organization/usage/audio_speeches", + &query, + &self.request_options, + ) .await } @@ -35,7 +41,11 @@ impl<'c, C: Config> Usage<'c, C> { Q: Serialize + ?Sized, { self.client - .get_with_query("/organization/usage/audio_transcriptions", &query, &self.request_options) + .get_with_query( + "/organization/usage/audio_transcriptions", + &query, + &self.request_options, + ) .await } @@ -49,7 +59,11 @@ impl<'c, C: Config> Usage<'c, C> { Q: Serialize + ?Sized, { self.client - .get_with_query("/organization/usage/code_interpreter_sessions", &query, &self.request_options) + .get_with_query( + "/organization/usage/code_interpreter_sessions", + &query, + &self.request_options, + ) .await } @@ -60,7 +74,11 @@ impl<'c, C: Config> Usage<'c, C> { Q: Serialize + ?Sized, { self.client - .get_with_query("/organization/usage/completions", &query, &self.request_options) + .get_with_query( + "/organization/usage/completions", + &query, + &self.request_options, + ) .await } @@ -71,7 +89,11 @@ impl<'c, C: Config> Usage<'c, C> { Q: Serialize + ?Sized, { self.client - .get_with_query("/organization/usage/embeddings", &query, &self.request_options) + .get_with_query( + "/organization/usage/embeddings", + &query, + &self.request_options, + ) .await } @@ -93,7 +115,11 @@ impl<'c, C: Config> Usage<'c, C> { Q: Serialize + ?Sized, { self.client - .get_with_query("/organization/usage/moderations", &query, &self.request_options) + .get_with_query( + "/organization/usage/moderations", + &query, + &self.request_options, + ) .await } @@ -104,7 +130,11 @@ impl<'c, C: Config> Usage<'c, C> { Q: Serialize + ?Sized, { self.client - .get_with_query("/organization/usage/vector_stores", &query, &self.request_options) + .get_with_query( + "/organization/usage/vector_stores", + &query, + &self.request_options, + ) .await } diff --git a/async-openai/src/users.rs b/async-openai/src/users.rs index 8c1201f3..97714d72 100644 --- a/async-openai/src/users.rs +++ b/async-openai/src/users.rs @@ -40,7 +40,11 @@ impl<'c, C: Config> Users<'c, C> { request: UserRoleUpdateRequest, ) -> Result { self.client - .post(format!("/organization/users/{user_id}").as_str(), request, &self.request_options) + .post( + format!("/organization/users/{user_id}").as_str(), + request, + &self.request_options, + ) .await } @@ -48,7 +52,10 @@ impl<'c, C: Config> Users<'c, C> { #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, user_id: &str) -> Result { self.client - .get(format!("/organization/users/{user_id}").as_str(), &self.request_options) + .get( + format!("/organization/users/{user_id}").as_str(), + &self.request_options, + ) .await } @@ -56,7 +63,10 @@ impl<'c, C: Config> Users<'c, C> { #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn delete(&self, user_id: &str) -> Result { self.client - .delete(format!("/organizations/users/{user_id}").as_str(), &self.request_options) + .delete( + format!("/organizations/users/{user_id}").as_str(), + &self.request_options, + ) .await } } diff --git a/async-openai/src/vector_store_file_batches.rs b/async-openai/src/vector_store_file_batches.rs index e4e9e13b..1d11a77b 100644 --- a/async-openai/src/vector_store_file_batches.rs +++ b/async-openai/src/vector_store_file_batches.rs @@ -49,10 +49,13 @@ impl<'c, C: Config> VectorStoreFileBatches<'c, C> { batch_id: &str, ) -> Result { self.client - .get(&format!( - "/vector_stores/{}/file_batches/{batch_id}", - &self.vector_store_id - ), &self.request_options) + .get( + &format!( + "/vector_stores/{}/file_batches/{batch_id}", + &self.vector_store_id + ), + &self.request_options, + ) .await } diff --git a/async-openai/src/vector_store_files.rs b/async-openai/src/vector_store_files.rs index edd5414a..d635f8e0 100644 --- a/async-openai/src/vector_store_files.rs +++ b/async-openai/src/vector_store_files.rs @@ -48,10 +48,10 @@ impl<'c, C: Config> VectorStoreFiles<'c, C> { #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, file_id: &str) -> Result { self.client - .get(&format!( - "/vector_stores/{}/files/{file_id}", - &self.vector_store_id - ), &self.request_options) + .get( + &format!("/vector_stores/{}/files/{file_id}", &self.vector_store_id), + &self.request_options, + ) .await } @@ -62,10 +62,10 @@ impl<'c, C: Config> VectorStoreFiles<'c, C> { file_id: &str, ) -> Result { self.client - .delete(&format!( - "/vector_stores/{}/files/{file_id}", - &self.vector_store_id - ), &self.request_options) + .delete( + &format!("/vector_stores/{}/files/{file_id}", &self.vector_store_id), + &self.request_options, + ) .await } @@ -107,10 +107,13 @@ impl<'c, C: Config> VectorStoreFiles<'c, C> { file_id: &str, ) -> Result { self.client - .get(&format!( - "/vector_stores/{}/files/{file_id}/content", - &self.vector_store_id - ), &self.request_options) + .get( + &format!( + "/vector_stores/{}/files/{file_id}/content", + &self.vector_store_id + ), + &self.request_options, + ) .await } } diff --git a/async-openai/src/vector_stores.rs b/async-openai/src/vector_stores.rs index c2af8342..64d9ac8e 100644 --- a/async-openai/src/vector_stores.rs +++ b/async-openai/src/vector_stores.rs @@ -41,14 +41,19 @@ impl<'c, C: Config> VectorStores<'c, C> { &self, request: CreateVectorStoreRequest, ) -> Result { - self.client.post("/vector_stores", request, &self.request_options).await + self.client + .post("/vector_stores", request, &self.request_options) + .await } /// Retrieves a vector store. #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, vector_store_id: &str) -> Result { self.client - .get(&format!("/vector_stores/{vector_store_id}"), &self.request_options) + .get( + &format!("/vector_stores/{vector_store_id}"), + &self.request_options, + ) .await } @@ -58,7 +63,9 @@ impl<'c, C: Config> VectorStores<'c, C> { where Q: Serialize + ?Sized, { - self.client.get_with_query("/vector_stores", &query, &self.request_options).await + self.client + .get_with_query("/vector_stores", &query, &self.request_options) + .await } /// Delete a vector store. @@ -68,7 +75,10 @@ impl<'c, C: Config> VectorStores<'c, C> { vector_store_id: &str, ) -> Result { self.client - .delete(&format!("/vector_stores/{vector_store_id}"), &self.request_options) + .delete( + &format!("/vector_stores/{vector_store_id}"), + &self.request_options, + ) .await } @@ -80,7 +90,11 @@ impl<'c, C: Config> VectorStores<'c, C> { request: UpdateVectorStoreRequest, ) -> Result { self.client - .post(&format!("/vector_stores/{vector_store_id}"), request, &self.request_options) + .post( + &format!("/vector_stores/{vector_store_id}"), + request, + &self.request_options, + ) .await } @@ -92,7 +106,11 @@ impl<'c, C: Config> VectorStores<'c, C> { request: VectorStoreSearchRequest, ) -> Result { self.client - .post(&format!("/vector_stores/{vector_store_id}/search"), request, &self.request_options) + .post( + &format!("/vector_stores/{vector_store_id}/search"), + request, + &self.request_options, + ) .await } } diff --git a/async-openai/src/video.rs b/async-openai/src/video.rs index c2eda7d3..545a9fec 100644 --- a/async-openai/src/video.rs +++ b/async-openai/src/video.rs @@ -32,7 +32,9 @@ impl<'c, C: Config> Videos<'c, C> { where_clause = "reqwest::multipart::Form: crate::traits::AsyncTryFrom", )] pub async fn create(&self, request: CreateVideoRequest) -> Result { - self.client.post_form("/videos", request, &self.request_options).await + self.client + .post_form("/videos", request, &self.request_options) + .await } /// Create a video remix @@ -43,20 +45,28 @@ impl<'c, C: Config> Videos<'c, C> { request: RemixVideoRequest, ) -> Result { self.client - .post(&format!("/videos/{video_id}/remix"), request, &self.request_options) + .post( + &format!("/videos/{video_id}/remix"), + request, + &self.request_options, + ) .await } /// Retrieves a video by its ID. #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, video_id: &str) -> Result { - self.client.get(&format!("/videos/{}", video_id), &self.request_options).await + self.client + .get(&format!("/videos/{}", video_id), &self.request_options) + .await } /// Delete a Video #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn delete(&self, video_id: &str) -> Result { - self.client.delete(&format!("/videos/{}", video_id), &self.request_options).await + self.client + .delete(&format!("/videos/{}", video_id), &self.request_options) + .await } /// List Videos @@ -65,7 +75,9 @@ impl<'c, C: Config> Videos<'c, C> { where Q: Serialize + ?Sized, { - self.client.get_with_query("/videos", &query, &self.request_options).await + self.client + .get_with_query("/videos", &query, &self.request_options) + .await } /// Download video content From 8bf8a8e4b36ad5fccc01639482bc442fe2df5c5c Mon Sep 17 00:00:00 2001 From: Himanshu Neema Date: Mon, 17 Nov 2025 16:29:48 -0800 Subject: [PATCH 03/22] cargo clippy fix --- async-openai/src/request_options.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/async-openai/src/request_options.rs b/async-openai/src/request_options.rs index 05641e0d..eb9ee63b 100644 --- a/async-openai/src/request_options.rs +++ b/async-openai/src/request_options.rs @@ -20,7 +20,7 @@ impl RequestOptions { pub fn with_headers(&mut self, headers: HeaderMap) { // merge with existing headers or update with new headers if let Some(existing_headers) = &mut self.headers { - existing_headers.extend(headers.into_iter()); + existing_headers.extend(headers); } else { self.headers = Some(headers); } @@ -39,7 +39,7 @@ impl RequestOptions { headers.insert(key, value); } else { let mut headers = HeaderMap::new(); - headers.insert(key, value.into()); + headers.insert(key, value); self.headers = Some(headers); } Ok(()) From eeeaa564f5f3dda19527f74290b2ae7984bde997 Mon Sep 17 00:00:00 2001 From: Himanshu Neema Date: Mon, 17 Nov 2025 16:33:51 -0800 Subject: [PATCH 04/22] make RequestOptions methods as pub(crate) --- async-openai/src/request_options.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/async-openai/src/request_options.rs b/async-openai/src/request_options.rs index eb9ee63b..50e48781 100644 --- a/async-openai/src/request_options.rs +++ b/async-openai/src/request_options.rs @@ -10,14 +10,14 @@ pub struct RequestOptions { } impl RequestOptions { - pub fn new() -> Self { + pub(crate) fn new() -> Self { Self { query: None, headers: None, } } - pub fn with_headers(&mut self, headers: HeaderMap) { + pub(crate) fn with_headers(&mut self, headers: HeaderMap) { // merge with existing headers or update with new headers if let Some(existing_headers) = &mut self.headers { existing_headers.extend(headers); @@ -26,7 +26,7 @@ impl RequestOptions { } } - pub fn with_header(&mut self, key: K, value: V) -> Result<(), OpenAIError> + pub(crate) fn with_header(&mut self, key: K, value: V) -> Result<(), OpenAIError> where K: reqwest::header::IntoHeaderName, V: TryInto, @@ -45,7 +45,10 @@ impl RequestOptions { Ok(()) } - pub fn with_query(&mut self, query: &Q) -> Result<(), OpenAIError> { + pub(crate) fn with_query( + &mut self, + query: &Q, + ) -> Result<(), OpenAIError> { let new_query = serde_urlencoded::to_string(query) .map_err(|e| OpenAIError::InvalidArgument(format!("Invalid query: {}", e)))?; if let Some(existing_query) = &self.query { @@ -56,11 +59,11 @@ impl RequestOptions { Ok(()) } - pub fn query(&self) -> Option<&str> { + pub(crate) fn query(&self) -> Option<&str> { self.query.as_deref() } - pub fn headers(&self) -> Option<&HeaderMap> { + pub(crate) fn headers(&self) -> Option<&HeaderMap> { self.headers.as_ref() } } From 8c57de4de45b785095ea661f264371dd353f313d Mon Sep 17 00:00:00 2001 From: Himanshu Neema Date: Mon, 17 Nov 2025 16:59:11 -0800 Subject: [PATCH 05/22] remove query parameters from individual methods --- async-openai/src/admin_api_keys.rs | 15 +-- async-openai/src/assistants.rs | 13 +- async-openai/src/audit_logs.rs | 11 +- async-openai/src/batches.rs | 11 +- async-openai/src/certificates.rs | 32 +---- async-openai/src/chat.rs | 9 +- async-openai/src/chatkit.rs | 25 +--- async-openai/src/container_files.rs | 11 +- async-openai/src/containers.rs | 11 +- async-openai/src/conversation_items.rs | 12 +- async-openai/src/eval_run_output_items.rs | 12 +- async-openai/src/eval_runs.rs | 15 +-- async-openai/src/evals.rs | 13 +- async-openai/src/file.rs | 12 +- async-openai/src/invites.rs | 11 +- async-openai/src/messages.rs | 15 +-- async-openai/src/project_api_keys.rs | 12 +- async-openai/src/project_certificates.rs | 10 +- async-openai/src/project_rate_limits.rs | 12 +- async-openai/src/project_service_accounts.rs | 12 +- async-openai/src/project_users.rs | 12 +- async-openai/src/projects.rs | 11 +- async-openai/src/responses.rs | 29 +---- async-openai/src/runs.rs | 15 +-- async-openai/src/steps.rs | 12 +- async-openai/src/usage.rs | 114 +++++------------- async-openai/src/users.rs | 11 +- async-openai/src/vector_store_file_batches.rs | 16 +-- async-openai/src/vector_store_files.rs | 12 +- async-openai/src/vector_stores.rs | 11 +- async-openai/src/video.rs | 10 +- 31 files changed, 122 insertions(+), 405 deletions(-) diff --git a/async-openai/src/admin_api_keys.rs b/async-openai/src/admin_api_keys.rs index 96ceff93..ce90b4a3 100644 --- a/async-openai/src/admin_api_keys.rs +++ b/async-openai/src/admin_api_keys.rs @@ -1,5 +1,3 @@ -use serde::Serialize; - use crate::{ config::Config, error::OpenAIError, @@ -26,17 +24,10 @@ impl<'c, C: Config> AdminAPIKeys<'c, C> { } /// List all organization and project API keys. - #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn list(&self, query: &Q) -> Result - where - Q: Serialize + ?Sized, - { + #[crate::byot(R = serde::de::DeserializeOwned)] + pub async fn list(&self) -> Result { self.client - .get_with_query( - "/organization/admin_api_keys", - &query, - &self.request_options, - ) + .get("/organization/admin_api_keys", &self.request_options) .await } diff --git a/async-openai/src/assistants.rs b/async-openai/src/assistants.rs index 573dbb65..44672381 100644 --- a/async-openai/src/assistants.rs +++ b/async-openai/src/assistants.rs @@ -1,5 +1,3 @@ -use serde::Serialize; - use crate::{ config::Config, error::OpenAIError, @@ -76,13 +74,8 @@ impl<'c, C: Config> Assistants<'c, C> { } /// Returns a list of assistants. - #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn list(&self, query: &Q) -> Result - where - Q: Serialize + ?Sized, - { - self.client - .get_with_query("/assistants", &query, &self.request_options) - .await + #[crate::byot(R = serde::de::DeserializeOwned)] + pub async fn list(&self) -> Result { + self.client.get("/assistants", &self.request_options).await } } diff --git a/async-openai/src/audit_logs.rs b/async-openai/src/audit_logs.rs index a5169b0a..95ac7e10 100644 --- a/async-openai/src/audit_logs.rs +++ b/async-openai/src/audit_logs.rs @@ -1,5 +1,3 @@ -use serde::Serialize; - use crate::{ config::Config, error::OpenAIError, types::admin::audit_logs::ListAuditLogsResponse, Client, RequestOptions, @@ -22,13 +20,10 @@ impl<'c, C: Config> AuditLogs<'c, C> { } /// List user actions and configuration changes within this organization. - #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn get(&self, query: &Q) -> Result - where - Q: Serialize + ?Sized, - { + #[crate::byot(R = serde::de::DeserializeOwned)] + pub async fn get(&self) -> Result { self.client - .get_with_query("/organization/audit_logs", &query, &self.request_options) + .get("/organization/audit_logs", &self.request_options) .await } } diff --git a/async-openai/src/batches.rs b/async-openai/src/batches.rs index c0485778..c4bb9f87 100644 --- a/async-openai/src/batches.rs +++ b/async-openai/src/batches.rs @@ -1,5 +1,3 @@ -use serde::Serialize; - use crate::{ config::Config, error::OpenAIError, @@ -32,13 +30,10 @@ impl<'c, C: Config> Batches<'c, C> { } /// List your organization's batches. - #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn list(&self, query: &Q) -> Result - where - Q: Serialize + ?Sized, - { + #[crate::byot(R = serde::de::DeserializeOwned)] + pub async fn list(&self) -> Result { self.client - .get_with_query("/batches", &query, &self.request_options) + .get("/batches", &self.request_options) .await } diff --git a/async-openai/src/certificates.rs b/async-openai/src/certificates.rs index 8e4fb092..be6b2b2d 100644 --- a/async-openai/src/certificates.rs +++ b/async-openai/src/certificates.rs @@ -1,5 +1,3 @@ -use serde::Serialize; - use crate::{ config::Config, error::OpenAIError, @@ -28,16 +26,10 @@ impl<'c, C: Config> Certificates<'c, C> { // Organization-level certificate operations /// List all certificates for the organization. - #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn list_organization( - &self, - query: &Q, - ) -> Result - where - Q: Serialize + ?Sized, - { + #[crate::byot(R = serde::de::DeserializeOwned)] + pub async fn list_organization(&self) -> Result { self.client - .get_with_query("/organization/certificates", &query, &self.request_options) + .get("/organization/certificates", &self.request_options) .await } @@ -93,24 +85,6 @@ impl<'c, C: Config> Certificates<'c, C> { .await } - /// Retrieve a single certificate with optional include parameters. - pub async fn retrieve_with_query( - &self, - certificate_id: &str, - query: &Q, - ) -> Result - where - Q: Serialize + ?Sized, - { - self.client - .get_with_query( - format!("/organization/certificates/{certificate_id}").as_str(), - query, - &self.request_options, - ) - .await - } - /// Modify a certificate. Note that only the name can be modified. #[crate::byot(T0 = std::fmt::Display, T1 = serde::Serialize, R = serde::de::DeserializeOwned)] pub async fn modify( diff --git a/async-openai/src/chat.rs b/async-openai/src/chat.rs index fde09594..d37d4d05 100644 --- a/async-openai/src/chat.rs +++ b/async-openai/src/chat.rs @@ -95,13 +95,10 @@ impl<'c, C: Config> Chat<'c, C> { /// List stored Chat Completions. Only Chat Completions that have been stored /// with the `store` parameter set to `true` will be returned. - #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn list(&self, query: &Q) -> Result - where - Q: Serialize + ?Sized, - { + #[crate::byot(R = serde::de::DeserializeOwned)] + pub async fn list(&self) -> Result { self.client - .get_with_query("/chat/completions", &query, &self.request_options) + .get("/chat/completions", &self.request_options) .await } diff --git a/async-openai/src/chatkit.rs b/async-openai/src/chatkit.rs index 0c899ca2..57a362fd 100644 --- a/async-openai/src/chatkit.rs +++ b/async-openai/src/chatkit.rs @@ -1,5 +1,3 @@ -use serde::Serialize; - use crate::{ config::Config, error::OpenAIError, @@ -90,13 +88,10 @@ impl<'c, C: Config> ChatkitThreads<'c, C> { } /// List ChatKit threads. - #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn list(&self, query: &Q) -> Result - where - Q: Serialize + ?Sized, - { + #[crate::byot(R = serde::de::DeserializeOwned)] + pub async fn list(&self) -> Result { self.client - .get_with_query("/chatkit/threads", &query, &self.request_options) + .get("/chatkit/threads", &self.request_options) .await } @@ -123,19 +118,11 @@ impl<'c, C: Config> ChatkitThreads<'c, C> { } /// List ChatKit thread items. - #[crate::byot(T0 = std::fmt::Display, T1 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn list_items( - &self, - thread_id: &str, - query: &Q, - ) -> Result - where - Q: Serialize + ?Sized, - { + #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] + pub async fn list_items(&self, thread_id: &str) -> Result { self.client - .get_with_query( + .get( &format!("/chatkit/threads/{thread_id}/items"), - &query, &self.request_options, ) .await diff --git a/async-openai/src/container_files.rs b/async-openai/src/container_files.rs index 43502275..2da942d8 100644 --- a/async-openai/src/container_files.rs +++ b/async-openai/src/container_files.rs @@ -1,5 +1,4 @@ use bytes::Bytes; -use serde::Serialize; use crate::{ config::Config, @@ -47,15 +46,11 @@ impl<'c, C: Config> ContainerFiles<'c, C> { } /// List container files. - #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn list(&self, query: &Q) -> Result - where - Q: Serialize + ?Sized, - { + #[crate::byot(R = serde::de::DeserializeOwned)] + pub async fn list(&self) -> Result { self.client - .get_with_query( + .get( &format!("/containers/{}/files", self.container_id), - &query, &self.request_options, ) .await diff --git a/async-openai/src/containers.rs b/async-openai/src/containers.rs index 46c28944..cff8631d 100644 --- a/async-openai/src/containers.rs +++ b/async-openai/src/containers.rs @@ -1,5 +1,3 @@ -use serde::Serialize; - use crate::{ config::Config, container_files::ContainerFiles, @@ -40,13 +38,10 @@ impl<'c, C: Config> Containers<'c, C> { } /// List containers. - #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn list(&self, query: &Q) -> Result - where - Q: Serialize + ?Sized, - { + #[crate::byot(R = serde::de::DeserializeOwned)] + pub async fn list(&self) -> Result { self.client - .get_with_query("/containers", &query, &self.request_options) + .get("/containers", &self.request_options) .await } diff --git a/async-openai/src/conversation_items.rs b/async-openai/src/conversation_items.rs index 823ba6b9..e018e034 100644 --- a/async-openai/src/conversation_items.rs +++ b/async-openai/src/conversation_items.rs @@ -1,5 +1,3 @@ -use serde::Serialize; - use crate::{ config::Config, error::OpenAIError, @@ -42,15 +40,11 @@ impl<'c, C: Config> ConversationItems<'c, C> { } /// List all items for a conversation. - #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn list(&self, query: &Q) -> Result - where - Q: Serialize + ?Sized, - { + #[crate::byot(R = serde::de::DeserializeOwned)] + pub async fn list(&self) -> Result { self.client - .get_with_query( + .get( &format!("/conversations/{}/items", &self.conversation_id), - &query, &self.request_options, ) .await diff --git a/async-openai/src/eval_run_output_items.rs b/async-openai/src/eval_run_output_items.rs index a30fd7e0..e9dc14c0 100644 --- a/async-openai/src/eval_run_output_items.rs +++ b/async-openai/src/eval_run_output_items.rs @@ -1,5 +1,3 @@ -use serde::Serialize; - use crate::{ config::Config, error::OpenAIError, @@ -25,15 +23,11 @@ impl<'c, C: Config> EvalRunOutputItems<'c, C> { } /// Get a list of output items for an evaluation run. - #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn list(&self, query: &Q) -> Result - where - Q: Serialize + ?Sized, - { + #[crate::byot(R = serde::de::DeserializeOwned)] + pub async fn list(&self) -> Result { self.client - .get_with_query( + .get( &format!("/evals/{}/runs/{}/output_items", self.eval_id, self.run_id), - &query, &self.request_options, ) .await diff --git a/async-openai/src/eval_runs.rs b/async-openai/src/eval_runs.rs index 907599a1..0d840245 100644 --- a/async-openai/src/eval_runs.rs +++ b/async-openai/src/eval_runs.rs @@ -1,5 +1,3 @@ -use serde::Serialize; - use crate::{ config::Config, error::OpenAIError, @@ -29,17 +27,10 @@ impl<'c, C: Config> EvalRuns<'c, C> { } /// Get a list of runs for an evaluation. - #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn list(&self, query: &Q) -> Result - where - Q: Serialize + ?Sized, - { + #[crate::byot(R = serde::de::DeserializeOwned)] + pub async fn list(&self) -> Result { self.client - .get_with_query( - &format!("/evals/{}/runs", self.eval_id), - &query, - &self.request_options, - ) + .get(&format!("/evals/{}/runs", self.eval_id), &self.request_options) .await } diff --git a/async-openai/src/evals.rs b/async-openai/src/evals.rs index 6f307bdd..00e8ac5c 100644 --- a/async-openai/src/evals.rs +++ b/async-openai/src/evals.rs @@ -1,5 +1,3 @@ -use serde::Serialize; - use crate::{ config::Config, error::OpenAIError, @@ -29,14 +27,9 @@ impl<'c, C: Config> Evals<'c, C> { } /// List evaluations for a project. - #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn list(&self, query: &Q) -> Result - where - Q: Serialize + ?Sized, - { - self.client - .get_with_query("/evals", &query, &self.request_options) - .await + #[crate::byot(R = serde::de::DeserializeOwned)] + pub async fn list(&self) -> Result { + self.client.get("/evals", &self.request_options).await } /// Create the structure of an evaluation that can be used to test a model's performance. diff --git a/async-openai/src/file.rs b/async-openai/src/file.rs index 6d760677..ccd54e1a 100644 --- a/async-openai/src/file.rs +++ b/async-openai/src/file.rs @@ -1,5 +1,4 @@ use bytes::Bytes; -use serde::Serialize; use crate::{ config::Config, @@ -43,14 +42,9 @@ impl<'c, C: Config> Files<'c, C> { } /// Returns a list of files that belong to the user's organization. - #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn list(&self, query: &Q) -> Result - where - Q: Serialize + ?Sized, - { - self.client - .get_with_query("/files", &query, &self.request_options) - .await + #[crate::byot(R = serde::de::DeserializeOwned)] + pub async fn list(&self) -> Result { + self.client.get("/files", &self.request_options).await } /// Returns information about a specific file. diff --git a/async-openai/src/invites.rs b/async-openai/src/invites.rs index 7e5e19ec..be28166d 100644 --- a/async-openai/src/invites.rs +++ b/async-openai/src/invites.rs @@ -1,5 +1,3 @@ -use serde::Serialize; - use crate::{ config::Config, error::OpenAIError, @@ -22,13 +20,10 @@ impl<'c, C: Config> Invites<'c, C> { } /// Returns a list of invites in the organization. - #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn list(&self, query: &Q) -> Result - where - Q: Serialize + ?Sized, - { + #[crate::byot(R = serde::de::DeserializeOwned)] + pub async fn list(&self) -> Result { self.client - .get_with_query("/organization/invites", &query, &self.request_options) + .get("/organization/invites", &self.request_options) .await } diff --git a/async-openai/src/messages.rs b/async-openai/src/messages.rs index 45d645c3..6ed02101 100644 --- a/async-openai/src/messages.rs +++ b/async-openai/src/messages.rs @@ -1,5 +1,3 @@ -use serde::Serialize; - use crate::{ config::Config, error::OpenAIError, @@ -70,17 +68,10 @@ impl<'c, C: Config> Messages<'c, C> { } /// Returns a list of messages for a given thread. - #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn list(&self, query: &Q) -> Result - where - Q: Serialize + ?Sized, - { + #[crate::byot(R = serde::de::DeserializeOwned)] + pub async fn list(&self) -> Result { self.client - .get_with_query( - &format!("/threads/{}/messages", self.thread_id), - &query, - &self.request_options, - ) + .get(&format!("/threads/{}/messages", self.thread_id), &self.request_options) .await } diff --git a/async-openai/src/project_api_keys.rs b/async-openai/src/project_api_keys.rs index ed15e070..f1143697 100644 --- a/async-openai/src/project_api_keys.rs +++ b/async-openai/src/project_api_keys.rs @@ -1,5 +1,3 @@ -use serde::Serialize; - use crate::{ config::Config, error::OpenAIError, @@ -27,15 +25,11 @@ impl<'c, C: Config> ProjectAPIKeys<'c, C> { } /// Returns a list of API keys in the project. - #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn list(&self, query: &Q) -> Result - where - Q: Serialize + ?Sized, - { + #[crate::byot(R = serde::de::DeserializeOwned)] + pub async fn list(&self) -> Result { self.client - .get_with_query( + .get( format!("/organization/projects/{}/api_keys", self.project_id).as_str(), - &query, &self.request_options, ) .await diff --git a/async-openai/src/project_certificates.rs b/async-openai/src/project_certificates.rs index 1b6a3d13..ec89e08f 100644 --- a/async-openai/src/project_certificates.rs +++ b/async-openai/src/project_certificates.rs @@ -1,5 +1,3 @@ -use serde::Serialize; - use crate::{ config::Config, error::OpenAIError, @@ -24,14 +22,10 @@ impl<'c, C: Config> ProjectCertificates<'c, C> { } /// List all certificates for this project. - pub async fn list(&self, query: &Q) -> Result - where - Q: Serialize + ?Sized, - { + pub async fn list(&self) -> Result { self.client - .get_with_query( + .get( format!("/organization/projects/{}/certificates", self.project_id).as_str(), - query, &self.request_options, ) .await diff --git a/async-openai/src/project_rate_limits.rs b/async-openai/src/project_rate_limits.rs index 6eb27b83..c01e59d0 100644 --- a/async-openai/src/project_rate_limits.rs +++ b/async-openai/src/project_rate_limits.rs @@ -1,5 +1,3 @@ -use serde::Serialize; - use crate::{ config::Config, error::OpenAIError, @@ -26,15 +24,11 @@ impl<'c, C: Config> ProjectRateLimits<'c, C> { } /// Returns the rate limits per model for a project. - #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn list(&self, query: &Q) -> Result - where - Q: Serialize + ?Sized, - { + #[crate::byot(R = serde::de::DeserializeOwned)] + pub async fn list(&self) -> Result { self.client - .get_with_query( + .get( format!("/organization/projects/{}/rate_limits", self.project_id).as_str(), - &query, &self.request_options, ) .await diff --git a/async-openai/src/project_service_accounts.rs b/async-openai/src/project_service_accounts.rs index 9b2f41d7..cacb349c 100644 --- a/async-openai/src/project_service_accounts.rs +++ b/async-openai/src/project_service_accounts.rs @@ -1,5 +1,3 @@ -use serde::Serialize; - use crate::{ config::Config, error::OpenAIError, @@ -31,19 +29,15 @@ impl<'c, C: Config> ProjectServiceAccounts<'c, C> { } /// Returns a list of service accounts in the project. - #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn list(&self, query: &Q) -> Result - where - Q: Serialize + ?Sized, - { + #[crate::byot(R = serde::de::DeserializeOwned)] + pub async fn list(&self) -> Result { self.client - .get_with_query( + .get( format!( "/organization/projects/{}/service_accounts", self.project_id ) .as_str(), - &query, &self.request_options, ) .await diff --git a/async-openai/src/project_users.rs b/async-openai/src/project_users.rs index 98d4abc1..2769daa0 100644 --- a/async-openai/src/project_users.rs +++ b/async-openai/src/project_users.rs @@ -1,5 +1,3 @@ -use serde::Serialize; - use crate::{ config::Config, error::OpenAIError, @@ -28,15 +26,11 @@ impl<'c, C: Config> ProjectUsers<'c, C> { } /// Returns a list of users in the project. - #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn list(&self, query: &Q) -> Result - where - Q: Serialize + ?Sized, - { + #[crate::byot(R = serde::de::DeserializeOwned)] + pub async fn list(&self) -> Result { self.client - .get_with_query( + .get( format!("/organization/projects/{}/users", self.project_id).as_str(), - &query, &self.request_options, ) .await diff --git a/async-openai/src/projects.rs b/async-openai/src/projects.rs index 1c6b37e3..6874775d 100644 --- a/async-openai/src/projects.rs +++ b/async-openai/src/projects.rs @@ -1,5 +1,3 @@ -use serde::Serialize; - use crate::{ config::Config, error::OpenAIError, @@ -53,13 +51,10 @@ impl<'c, C: Config> Projects<'c, C> { } /// Returns a list of projects. - #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn list(&self, query: &Q) -> Result - where - Q: Serialize + ?Sized, - { + #[crate::byot(R = serde::de::DeserializeOwned)] + pub async fn list(&self) -> Result { self.client - .get_with_query("/organization/projects", &query, &self.request_options) + .get("/organization/projects", &self.request_options) .await } diff --git a/async-openai/src/responses.rs b/async-openai/src/responses.rs index 389b9323..2772fff8 100644 --- a/async-openai/src/responses.rs +++ b/async-openai/src/responses.rs @@ -1,5 +1,3 @@ -use serde::Serialize; - use crate::{ config::Config, error::OpenAIError, @@ -73,17 +71,10 @@ impl<'c, C: Config> Responses<'c, C> { } /// Retrieves a model response with the given ID. - #[crate::byot(T0 = std::fmt::Display, T1 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn retrieve(&self, response_id: &str, query: &Q) -> Result - where - Q: Serialize + ?Sized, - { + #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] + pub async fn retrieve(&self, response_id: &str) -> Result { self.client - .get_with_query( - &format!("/responses/{}", response_id), - &query, - &self.request_options, - ) + .get(&format!("/responses/{}", response_id), &self.request_options) .await } @@ -113,19 +104,11 @@ impl<'c, C: Config> Responses<'c, C> { } /// Returns a list of input items for a given response. - #[crate::byot(T0 = std::fmt::Display, T1 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn list_input_items( - &self, - response_id: &str, - query: &Q, - ) -> Result - where - Q: Serialize + ?Sized, - { + #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] + pub async fn list_input_items(&self, response_id: &str) -> Result { self.client - .get_with_query( + .get( &format!("/responses/{}/input_items", response_id), - &query, &self.request_options, ) .await diff --git a/async-openai/src/runs.rs b/async-openai/src/runs.rs index d7b7f457..dc69e8ce 100644 --- a/async-openai/src/runs.rs +++ b/async-openai/src/runs.rs @@ -1,5 +1,3 @@ -use serde::Serialize; - use crate::{ config::Config, error::OpenAIError, @@ -110,17 +108,10 @@ impl<'c, C: Config> Runs<'c, C> { } /// Returns a list of runs belonging to a thread. - #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn list(&self, query: &Q) -> Result - where - Q: Serialize + ?Sized, - { + #[crate::byot(R = serde::de::DeserializeOwned)] + pub async fn list(&self) -> Result { self.client - .get_with_query( - &format!("/threads/{}/runs", self.thread_id), - &query, - &self.request_options, - ) + .get(&format!("/threads/{}/runs", self.thread_id), &self.request_options) .await } diff --git a/async-openai/src/steps.rs b/async-openai/src/steps.rs index c80f85f8..e0f8cde5 100644 --- a/async-openai/src/steps.rs +++ b/async-openai/src/steps.rs @@ -1,5 +1,3 @@ -use serde::Serialize; - use crate::{ config::Config, error::OpenAIError, @@ -40,15 +38,11 @@ impl<'c, C: Config> Steps<'c, C> { } /// Returns a list of run steps belonging to a run. - #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn list(&self, query: &Q) -> Result - where - Q: Serialize + ?Sized, - { + #[crate::byot(R = serde::de::DeserializeOwned)] + pub async fn list(&self) -> Result { self.client - .get_with_query( + .get( &format!("/threads/{}/runs/{}/steps", self.thread_id, self.run_id), - &query, &self.request_options, ) .await diff --git a/async-openai/src/usage.rs b/async-openai/src/usage.rs index 66e07ec5..1be36536 100644 --- a/async-openai/src/usage.rs +++ b/async-openai/src/usage.rs @@ -1,5 +1,3 @@ -use serde::Serialize; - use crate::{ config::Config, error::OpenAIError, types::admin::usage::UsageResponse, Client, RequestOptions, }; @@ -20,132 +18,74 @@ impl<'c, C: Config> Usage<'c, C> { } /// Get audio speeches usage details for the organization. - #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn audio_speeches(&self, query: &Q) -> Result - where - Q: Serialize + ?Sized, - { + #[crate::byot(R = serde::de::DeserializeOwned)] + pub async fn audio_speeches(&self) -> Result { self.client - .get_with_query( - "/organization/usage/audio_speeches", - &query, - &self.request_options, - ) + .get("/organization/usage/audio_speeches", &self.request_options) .await } /// Get audio transcriptions usage details for the organization. - #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn audio_transcriptions(&self, query: &Q) -> Result - where - Q: Serialize + ?Sized, - { + #[crate::byot(R = serde::de::DeserializeOwned)] + pub async fn audio_transcriptions(&self) -> Result { self.client - .get_with_query( - "/organization/usage/audio_transcriptions", - &query, - &self.request_options, - ) + .get("/organization/usage/audio_transcriptions", &self.request_options) .await } /// Get code interpreter sessions usage details for the organization. - #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn code_interpreter_sessions( - &self, - query: &Q, - ) -> Result - where - Q: Serialize + ?Sized, - { + #[crate::byot(R = serde::de::DeserializeOwned)] + pub async fn code_interpreter_sessions(&self) -> Result { self.client - .get_with_query( - "/organization/usage/code_interpreter_sessions", - &query, - &self.request_options, - ) + .get("/organization/usage/code_interpreter_sessions", &self.request_options) .await } /// Get completions usage details for the organization. - #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn completions(&self, query: &Q) -> Result - where - Q: Serialize + ?Sized, - { + #[crate::byot(R = serde::de::DeserializeOwned)] + pub async fn completions(&self) -> Result { self.client - .get_with_query( - "/organization/usage/completions", - &query, - &self.request_options, - ) + .get("/organization/usage/completions", &self.request_options) .await } /// Get embeddings usage details for the organization. - #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn embeddings(&self, query: &Q) -> Result - where - Q: Serialize + ?Sized, - { + #[crate::byot(R = serde::de::DeserializeOwned)] + pub async fn embeddings(&self) -> Result { self.client - .get_with_query( - "/organization/usage/embeddings", - &query, - &self.request_options, - ) + .get("/organization/usage/embeddings", &self.request_options) .await } /// Get images usage details for the organization. - #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn images(&self, query: &Q) -> Result - where - Q: Serialize + ?Sized, - { + #[crate::byot(R = serde::de::DeserializeOwned)] + pub async fn images(&self) -> Result { self.client - .get_with_query("/organization/usage/images", &query, &self.request_options) + .get("/organization/usage/images", &self.request_options) .await } /// Get moderations usage details for the organization. - #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn moderations(&self, query: &Q) -> Result - where - Q: Serialize + ?Sized, - { + #[crate::byot(R = serde::de::DeserializeOwned)] + pub async fn moderations(&self) -> Result { self.client - .get_with_query( - "/organization/usage/moderations", - &query, - &self.request_options, - ) + .get("/organization/usage/moderations", &self.request_options) .await } /// Get vector stores usage details for the organization. - #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn vector_stores(&self, query: &Q) -> Result - where - Q: Serialize + ?Sized, - { + #[crate::byot(R = serde::de::DeserializeOwned)] + pub async fn vector_stores(&self) -> Result { self.client - .get_with_query( - "/organization/usage/vector_stores", - &query, - &self.request_options, - ) + .get("/organization/usage/vector_stores", &self.request_options) .await } /// Get costs details for the organization. - #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn costs(&self, query: &Q) -> Result - where - Q: Serialize + ?Sized, - { + #[crate::byot(R = serde::de::DeserializeOwned)] + pub async fn costs(&self) -> Result { self.client - .get_with_query("/organization/costs", &query, &self.request_options) + .get("/organization/costs", &self.request_options) .await } } diff --git a/async-openai/src/users.rs b/async-openai/src/users.rs index 97714d72..66fba4aa 100644 --- a/async-openai/src/users.rs +++ b/async-openai/src/users.rs @@ -1,5 +1,3 @@ -use serde::Serialize; - use crate::{ config::Config, error::OpenAIError, @@ -22,13 +20,10 @@ impl<'c, C: Config> Users<'c, C> { } /// Lists all of the users in the organization. - #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn list(&self, query: &Q) -> Result - where - Q: Serialize + ?Sized, - { + #[crate::byot(R = serde::de::DeserializeOwned)] + pub async fn list(&self) -> Result { self.client - .get_with_query("/organization/users", &query, &self.request_options) + .get("/organization/users", &self.request_options) .await } diff --git a/async-openai/src/vector_store_file_batches.rs b/async-openai/src/vector_store_file_batches.rs index 1d11a77b..9c0f2868 100644 --- a/async-openai/src/vector_store_file_batches.rs +++ b/async-openai/src/vector_store_file_batches.rs @@ -1,5 +1,3 @@ -use serde::Serialize; - use crate::{ config::Config, error::OpenAIError, @@ -75,22 +73,14 @@ impl<'c, C: Config> VectorStoreFileBatches<'c, C> { } /// Returns a list of vector store files in a batch. - #[crate::byot(T0 = std::fmt::Display, T1 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn list_files( - &self, - batch_id: &str, - query: &Q, - ) -> Result - where - Q: Serialize + ?Sized, - { + #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] + pub async fn list_files(&self, batch_id: &str) -> Result { self.client - .get_with_query( + .get( &format!( "/vector_stores/{}/file_batches/{batch_id}/files", &self.vector_store_id ), - &query, &self.request_options, ) .await diff --git a/async-openai/src/vector_store_files.rs b/async-openai/src/vector_store_files.rs index d635f8e0..164f7b09 100644 --- a/async-openai/src/vector_store_files.rs +++ b/async-openai/src/vector_store_files.rs @@ -1,5 +1,3 @@ -use serde::Serialize; - use crate::{ config::Config, error::OpenAIError, @@ -70,15 +68,11 @@ impl<'c, C: Config> VectorStoreFiles<'c, C> { } /// Returns a list of vector store files. - #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn list(&self, query: &Q) -> Result - where - Q: Serialize + ?Sized, - { + #[crate::byot(R = serde::de::DeserializeOwned)] + pub async fn list(&self) -> Result { self.client - .get_with_query( + .get( &format!("/vector_stores/{}/files", &self.vector_store_id), - &query, &self.request_options, ) .await diff --git a/async-openai/src/vector_stores.rs b/async-openai/src/vector_stores.rs index 64d9ac8e..57d75586 100644 --- a/async-openai/src/vector_stores.rs +++ b/async-openai/src/vector_stores.rs @@ -1,5 +1,3 @@ -use serde::Serialize; - use crate::{ config::Config, error::OpenAIError, @@ -58,13 +56,10 @@ impl<'c, C: Config> VectorStores<'c, C> { } /// Returns a list of vector stores. - #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn list(&self, query: &Q) -> Result - where - Q: Serialize + ?Sized, - { + #[crate::byot(R = serde::de::DeserializeOwned)] + pub async fn list(&self) -> Result { self.client - .get_with_query("/vector_stores", &query, &self.request_options) + .get("/vector_stores", &self.request_options) .await } diff --git a/async-openai/src/video.rs b/async-openai/src/video.rs index 545a9fec..734081a6 100644 --- a/async-openai/src/video.rs +++ b/async-openai/src/video.rs @@ -8,7 +8,6 @@ use crate::{ Client, RequestOptions, }; use bytes::Bytes; -use serde::Serialize; /// Video generation with Sora /// Related guide: [Video generation](https://platform.openai.com/docs/guides/video-generation) @@ -70,13 +69,10 @@ impl<'c, C: Config> Videos<'c, C> { } /// List Videos - #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn list(&self, query: &Q) -> Result - where - Q: Serialize + ?Sized, - { + #[crate::byot(R = serde::de::DeserializeOwned)] + pub async fn list(&self) -> Result { self.client - .get_with_query("/videos", &query, &self.request_options) + .get("/videos", &self.request_options) .await } From aca31573497d59a142e8506e687fa1827fd8cb6a Mon Sep 17 00:00:00 2001 From: Himanshu Neema Date: Mon, 17 Nov 2025 17:06:14 -0800 Subject: [PATCH 06/22] update tests and examples to use RequestOptionsBuilder trait --- async-openai/src/file.rs | 3 ++- .../assistants-code-interpreter/src/main.rs | 4 +++- examples/assistants-file-search/src/main.rs | 4 +++- examples/assistants/src/main.rs | 8 ++++++- examples/chat-store/src/main.rs | 3 ++- examples/containers/src/main.rs | 6 +++-- examples/conversations/src/main.rs | 4 +++- examples/usage/src/main.rs | 24 ++++++++++++------- examples/video/src/main.rs | 3 ++- 9 files changed, 41 insertions(+), 18 deletions(-) diff --git a/async-openai/src/file.rs b/async-openai/src/file.rs index ccd54e1a..47c37b33 100644 --- a/async-openai/src/file.rs +++ b/async-openai/src/file.rs @@ -76,6 +76,7 @@ impl<'c, C: Config> Files<'c, C> { #[cfg(test)] mod tests { use crate::{ + traits::RequestOptionsBuilder, types::files::{ CreateFileRequestArgs, FileExpirationAfter, FileExpirationAfterAnchor, FilePurpose, }, @@ -113,7 +114,7 @@ mod tests { //assert_eq!(openai_file.status, Some("processed".to_owned())); // uploaded or processed let query = [("purpose", "fine-tune")]; - let list_files = client.files().list(&query).await.unwrap(); + let list_files = client.files().query(&query).unwrap().list().await.unwrap(); assert_eq!(list_files.data.into_iter().last().unwrap(), openai_file); diff --git a/examples/assistants-code-interpreter/src/main.rs b/examples/assistants-code-interpreter/src/main.rs index 48fe6d7a..58848c84 100644 --- a/examples/assistants-code-interpreter/src/main.rs +++ b/examples/assistants-code-interpreter/src/main.rs @@ -1,6 +1,7 @@ use std::error::Error; use async_openai::{ + traits::RequestOptionsBuilder, types::assistants::{ AssistantToolCodeInterpreterResources, AssistantTools, CreateAssistantRequestArgs, CreateMessageRequestArgs, CreateRunRequest, CreateThreadRequest, MessageContent, @@ -82,7 +83,8 @@ async fn main() -> Result<(), Box> { let messages = client .threads() .messages(&thread.id) - .list(&[("limit", "10")]) + .query(&[("limit", "10")])? + .list() .await?; for message_obj in messages.data { diff --git a/examples/assistants-file-search/src/main.rs b/examples/assistants-file-search/src/main.rs index 3c84f808..0ac1907f 100644 --- a/examples/assistants-file-search/src/main.rs +++ b/examples/assistants-file-search/src/main.rs @@ -1,6 +1,7 @@ use std::error::Error; use async_openai::{ + traits::RequestOptionsBuilder, types::assistants::{ AssistantToolFileSearchResources, AssistantToolsFileSearch, CreateAssistantRequestArgs, CreateMessageRequestArgs, CreateRunRequest, CreateThreadRequest, MessageAttachment, @@ -131,7 +132,8 @@ async fn main() -> Result<(), Box> { let messages = client .threads() .messages(&thread.id) - .list(&[("limit", "10")]) + .query(&[("limit", "10")])? + .list() .await?; for message_obj in messages.data { diff --git a/examples/assistants/src/main.rs b/examples/assistants/src/main.rs index 07bb2731..370937f1 100644 --- a/examples/assistants/src/main.rs +++ b/examples/assistants/src/main.rs @@ -1,4 +1,5 @@ use async_openai::{ + traits::RequestOptionsBuilder, types::assistants::{ CreateAssistantRequestArgs, CreateMessageRequestArgs, CreateRunRequestArgs, CreateThreadRequestArgs, MessageContent, MessageRole, RunStatus, @@ -98,7 +99,12 @@ async fn main() -> Result<(), Box> { // in the thread //retrieve the response from the run - let response = client.threads().messages(&thread.id).list(&query).await?; + let response = client + .threads() + .messages(&thread.id) + .query(&query)? + .list() + .await?; //get the message id from the response let message_id = response.data.first().unwrap().id.clone(); //get the message from the response diff --git a/examples/chat-store/src/main.rs b/examples/chat-store/src/main.rs index ea6e21f6..d16bd151 100644 --- a/examples/chat-store/src/main.rs +++ b/examples/chat-store/src/main.rs @@ -1,4 +1,5 @@ use async_openai::{ + traits::RequestOptionsBuilder, types::chat::{ ChatCompletionRequestSystemMessageArgs, ChatCompletionRequestUserMessageArgs, CreateChatCompletionRequestArgs, @@ -60,7 +61,7 @@ async fn main() -> Result<(), Box> { println!("{:#?}", chat_completion_messages); // list all chat completions - let chat_completions = client.chat().list(&[("limit", 10)]).await?; + let chat_completions = client.chat().query(&[("limit", 10)])?.list().await?; println!("--------------------------------"); println!("Retrieved chat completions:\n"); diff --git a/examples/containers/src/main.rs b/examples/containers/src/main.rs index f3c54e81..6a65e799 100644 --- a/examples/containers/src/main.rs +++ b/examples/containers/src/main.rs @@ -1,4 +1,5 @@ use async_openai::{ + traits::RequestOptionsBuilder, types::containers::{ ContainerExpiresAfter, ContainerExpiresAfterAnchor, CreateContainerFileRequest, CreateContainerRequestArgs, @@ -30,7 +31,7 @@ async fn main() -> Result<(), Box> { // List all containers println!("\nListing all containers..."); let query = [("limit", "10")]; - let list_response = client.containers().list(&query).await?; + let list_response = client.containers().query(&query)?.list().await?; println!("Found {} containers", list_response.data.len()); for c in &list_response.data { println!(" - {} ({})", c.name, c.id); @@ -67,7 +68,8 @@ async fn main() -> Result<(), Box> { let files_list = client .containers() .files(&container.id) - .list(&files_query) + .query(&files_query)? + .list() .await?; println!("Found {} files", files_list.data.len()); for f in &files_list.data { diff --git a/examples/conversations/src/main.rs b/examples/conversations/src/main.rs index c62e27f3..88306882 100644 --- a/examples/conversations/src/main.rs +++ b/examples/conversations/src/main.rs @@ -1,4 +1,5 @@ use async_openai::{ + traits::RequestOptionsBuilder, types::responses::{ ConversationItem, CreateConversationItemsRequestArgs, CreateConversationRequestArgs, EasyInputContent, EasyInputMessage, InputItem, ListConversationItemsQuery, MessageType, @@ -77,7 +78,8 @@ async fn main() -> Result<(), Box> { let all_items = client .conversations() .items(&conversation.id) - .list(&query) + .query(&query)? + .list() .await?; println!("Total items retrieved: {}", all_items.data.len()); diff --git a/examples/usage/src/main.rs b/examples/usage/src/main.rs index a9a9b304..a589f16e 100644 --- a/examples/usage/src/main.rs +++ b/examples/usage/src/main.rs @@ -2,6 +2,7 @@ use std::error::Error; use std::time::{SystemTime, UNIX_EPOCH}; use async_openai::{ + traits::RequestOptionsBuilder, types::admin::usage::{UsageQueryParams, UsageResult}, Client, }; @@ -36,7 +37,7 @@ async fn main() -> Result<(), Box> { // Audio Speeches println!("=== Audio Speeches Usage ==="); - match client.usage().audio_speeches(&query).await { + match client.usage().query(&query)?.audio_speeches().await { Ok(response) => { println!("Found {} time buckets", response.data.len()); for bucket in &response.data { @@ -77,7 +78,7 @@ async fn main() -> Result<(), Box> { // Audio Transcriptions println!("=== Audio Transcriptions Usage ==="); - match client.usage().audio_transcriptions(&query).await { + match client.usage().query(&query)?.audio_transcriptions().await { Ok(response) => { println!("Found {} time buckets", response.data.len()); for bucket in &response.data { @@ -118,7 +119,12 @@ async fn main() -> Result<(), Box> { // Code Interpreter Sessions println!("=== Code Interpreter Sessions Usage ==="); - match client.usage().code_interpreter_sessions(&query).await { + match client + .usage() + .query(&query)? + .code_interpreter_sessions() + .await + { Ok(response) => { println!("Found {} time buckets", response.data.len()); for bucket in &response.data { @@ -156,7 +162,7 @@ async fn main() -> Result<(), Box> { // Completions println!("=== Completions Usage ==="); - match client.usage().completions(&query).await { + match client.usage().query(&query)?.completions().await { Ok(response) => { println!("Found {} time buckets", response.data.len()); for bucket in &response.data { @@ -221,7 +227,7 @@ async fn main() -> Result<(), Box> { // Embeddings println!("=== Embeddings Usage ==="); - match client.usage().embeddings(&query).await { + match client.usage().query(&query)?.embeddings().await { Ok(response) => { println!("Found {} time buckets", response.data.len()); for bucket in &response.data { @@ -262,7 +268,7 @@ async fn main() -> Result<(), Box> { // Images println!("=== Images Usage ==="); - match client.usage().images(&query).await { + match client.usage().query(&query)?.images().await { Ok(response) => { println!("Found {} time buckets", response.data.len()); for bucket in &response.data { @@ -309,7 +315,7 @@ async fn main() -> Result<(), Box> { // Moderations println!("=== Moderations Usage ==="); - match client.usage().moderations(&query).await { + match client.usage().query(&query)?.moderations().await { Ok(response) => { println!("Found {} time buckets", response.data.len()); for bucket in &response.data { @@ -350,7 +356,7 @@ async fn main() -> Result<(), Box> { // Vector Stores println!("=== Vector Stores Usage ==="); - match client.usage().vector_stores(&query).await { + match client.usage().query(&query)?.vector_stores().await { Ok(response) => { println!("Found {} time buckets", response.data.len()); for bucket in &response.data { @@ -389,7 +395,7 @@ async fn main() -> Result<(), Box> { // Costs println!("=== Costs ==="); - match client.usage().costs(&query).await { + match client.usage().query(&query)?.costs().await { Ok(response) => { println!("Found {} time buckets", response.data.len()); let mut total_cost = 0.0; diff --git a/examples/video/src/main.rs b/examples/video/src/main.rs index 5f66248e..979c0727 100644 --- a/examples/video/src/main.rs +++ b/examples/video/src/main.rs @@ -1,5 +1,6 @@ use async_openai::{ config::OpenAIConfig, + traits::RequestOptionsBuilder, types::videos::{CreateVideoRequestArgs, VideoJob, VideoSize, VideoVariant}, Client, }; @@ -72,7 +73,7 @@ async fn main() -> Result<(), Box> { let video = create_video(&client).await?; // wait for above video to be "completed" tokio::time::sleep(tokio::time::Duration::from_secs(5)).await; - let videos = client.videos().list(&[("limit", "100")]).await?; + let videos = client.videos().query(&[("limit", "100")])?.list().await?; for video in &videos.data { println!("Video: {:#?}", video); From 241ded387adcd66688981f25bd647b8f52824fa7 Mon Sep 17 00:00:00 2001 From: Himanshu Neema Date: Mon, 17 Nov 2025 17:06:32 -0800 Subject: [PATCH 07/22] cargo fmt --- async-openai/src/batches.rs | 4 +--- async-openai/src/containers.rs | 4 +--- async-openai/src/eval_runs.rs | 5 ++++- async-openai/src/messages.rs | 5 ++++- async-openai/src/responses.rs | 10 ++++++++-- async-openai/src/runs.rs | 5 ++++- async-openai/src/usage.rs | 10 ++++++++-- async-openai/src/vector_store_file_batches.rs | 5 ++++- async-openai/src/video.rs | 4 +--- 9 files changed, 35 insertions(+), 17 deletions(-) diff --git a/async-openai/src/batches.rs b/async-openai/src/batches.rs index c4bb9f87..968ed6e6 100644 --- a/async-openai/src/batches.rs +++ b/async-openai/src/batches.rs @@ -32,9 +32,7 @@ impl<'c, C: Config> Batches<'c, C> { /// List your organization's batches. #[crate::byot(R = serde::de::DeserializeOwned)] pub async fn list(&self) -> Result { - self.client - .get("/batches", &self.request_options) - .await + self.client.get("/batches", &self.request_options).await } /// Retrieves a batch. diff --git a/async-openai/src/containers.rs b/async-openai/src/containers.rs index cff8631d..c5b58bff 100644 --- a/async-openai/src/containers.rs +++ b/async-openai/src/containers.rs @@ -40,9 +40,7 @@ impl<'c, C: Config> Containers<'c, C> { /// List containers. #[crate::byot(R = serde::de::DeserializeOwned)] pub async fn list(&self) -> Result { - self.client - .get("/containers", &self.request_options) - .await + self.client.get("/containers", &self.request_options).await } /// Retrieve a container. diff --git a/async-openai/src/eval_runs.rs b/async-openai/src/eval_runs.rs index 0d840245..590e4ec9 100644 --- a/async-openai/src/eval_runs.rs +++ b/async-openai/src/eval_runs.rs @@ -30,7 +30,10 @@ impl<'c, C: Config> EvalRuns<'c, C> { #[crate::byot(R = serde::de::DeserializeOwned)] pub async fn list(&self) -> Result { self.client - .get(&format!("/evals/{}/runs", self.eval_id), &self.request_options) + .get( + &format!("/evals/{}/runs", self.eval_id), + &self.request_options, + ) .await } diff --git a/async-openai/src/messages.rs b/async-openai/src/messages.rs index 6ed02101..30c14e1d 100644 --- a/async-openai/src/messages.rs +++ b/async-openai/src/messages.rs @@ -71,7 +71,10 @@ impl<'c, C: Config> Messages<'c, C> { #[crate::byot(R = serde::de::DeserializeOwned)] pub async fn list(&self) -> Result { self.client - .get(&format!("/threads/{}/messages", self.thread_id), &self.request_options) + .get( + &format!("/threads/{}/messages", self.thread_id), + &self.request_options, + ) .await } diff --git a/async-openai/src/responses.rs b/async-openai/src/responses.rs index 2772fff8..73933db2 100644 --- a/async-openai/src/responses.rs +++ b/async-openai/src/responses.rs @@ -74,7 +74,10 @@ impl<'c, C: Config> Responses<'c, C> { #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] pub async fn retrieve(&self, response_id: &str) -> Result { self.client - .get(&format!("/responses/{}", response_id), &self.request_options) + .get( + &format!("/responses/{}", response_id), + &self.request_options, + ) .await } @@ -105,7 +108,10 @@ impl<'c, C: Config> Responses<'c, C> { /// Returns a list of input items for a given response. #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] - pub async fn list_input_items(&self, response_id: &str) -> Result { + pub async fn list_input_items( + &self, + response_id: &str, + ) -> Result { self.client .get( &format!("/responses/{}/input_items", response_id), diff --git a/async-openai/src/runs.rs b/async-openai/src/runs.rs index dc69e8ce..39ca5b23 100644 --- a/async-openai/src/runs.rs +++ b/async-openai/src/runs.rs @@ -111,7 +111,10 @@ impl<'c, C: Config> Runs<'c, C> { #[crate::byot(R = serde::de::DeserializeOwned)] pub async fn list(&self) -> Result { self.client - .get(&format!("/threads/{}/runs", self.thread_id), &self.request_options) + .get( + &format!("/threads/{}/runs", self.thread_id), + &self.request_options, + ) .await } diff --git a/async-openai/src/usage.rs b/async-openai/src/usage.rs index 1be36536..9e31af29 100644 --- a/async-openai/src/usage.rs +++ b/async-openai/src/usage.rs @@ -29,7 +29,10 @@ impl<'c, C: Config> Usage<'c, C> { #[crate::byot(R = serde::de::DeserializeOwned)] pub async fn audio_transcriptions(&self) -> Result { self.client - .get("/organization/usage/audio_transcriptions", &self.request_options) + .get( + "/organization/usage/audio_transcriptions", + &self.request_options, + ) .await } @@ -37,7 +40,10 @@ impl<'c, C: Config> Usage<'c, C> { #[crate::byot(R = serde::de::DeserializeOwned)] pub async fn code_interpreter_sessions(&self) -> Result { self.client - .get("/organization/usage/code_interpreter_sessions", &self.request_options) + .get( + "/organization/usage/code_interpreter_sessions", + &self.request_options, + ) .await } diff --git a/async-openai/src/vector_store_file_batches.rs b/async-openai/src/vector_store_file_batches.rs index 9c0f2868..72d3ee82 100644 --- a/async-openai/src/vector_store_file_batches.rs +++ b/async-openai/src/vector_store_file_batches.rs @@ -74,7 +74,10 @@ impl<'c, C: Config> VectorStoreFileBatches<'c, C> { /// Returns a list of vector store files in a batch. #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] - pub async fn list_files(&self, batch_id: &str) -> Result { + pub async fn list_files( + &self, + batch_id: &str, + ) -> Result { self.client .get( &format!( diff --git a/async-openai/src/video.rs b/async-openai/src/video.rs index 734081a6..3e30040f 100644 --- a/async-openai/src/video.rs +++ b/async-openai/src/video.rs @@ -71,9 +71,7 @@ impl<'c, C: Config> Videos<'c, C> { /// List Videos #[crate::byot(R = serde::de::DeserializeOwned)] pub async fn list(&self) -> Result { - self.client - .get("/videos", &self.request_options) - .await + self.client.get("/videos", &self.request_options).await } /// Download video content From edc6886f75d15dca27a4a622a5bbb8e054e4b262 Mon Sep 17 00:00:00 2001 From: Himanshu Neema Date: Mon, 17 Nov 2025 17:17:55 -0800 Subject: [PATCH 08/22] remove query params from all other methods --- async-openai/src/chat.rs | 13 ++----- async-openai/src/client.rs | 59 +++++------------------------ async-openai/src/container_files.rs | 5 ++- async-openai/src/file.rs | 5 ++- async-openai/src/fine_tuning.rs | 51 ++++++++----------------- async-openai/src/video.rs | 14 +++---- 6 files changed, 41 insertions(+), 106 deletions(-) diff --git a/async-openai/src/chat.rs b/async-openai/src/chat.rs index d37d4d05..8bcb7644 100644 --- a/async-openai/src/chat.rs +++ b/async-openai/src/chat.rs @@ -152,19 +152,14 @@ impl<'c, C: Config> Chat<'c, C> { } /// Get a list of messages for the specified chat completion. - #[crate::byot(T0 = std::fmt::Display, T1 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn messages( + #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] + pub async fn messages( &self, completion_id: &str, - query: &Q, - ) -> Result - where - Q: Serialize + ?Sized, - { + ) -> Result { self.client - .get_with_query( + .get( &format!("/chat/completions/{completion_id}/messages"), - &query, &self.request_options, ) .await diff --git a/async-openai/src/client.rs b/async-openai/src/client.rs index b9ca1f3a..056799e8 100644 --- a/async-openai/src/client.rs +++ b/async-openai/src/client.rs @@ -227,31 +227,28 @@ impl Client { self.execute(request_maker).await } - /// Make a GET request to {path} with given Query and deserialize the response body - pub(crate) async fn get_with_query( + /// Make a DELETE request to {path} and deserialize the response body + pub(crate) async fn delete( &self, path: &str, - query: &Q, request_options: &RequestOptions, ) -> Result where O: DeserializeOwned, - Q: Serialize + ?Sized, { let request_maker = || async { let mut request_builder = self .http_client - .get(self.config.url(path)) + .delete(self.config.url(path)) .query(&self.config.query()) - .query(query) .headers(self.config.headers()); if let Some(headers) = request_options.headers() { request_builder = request_builder.headers(headers.clone()); } - if let Some(query_str) = request_options.query() { - request_builder = request_builder.query(query_str); + if let Some(query) = request_options.query() { + request_builder = request_builder.query(query); } Ok(request_builder.build()?) @@ -260,19 +257,16 @@ impl Client { self.execute(request_maker).await } - /// Make a DELETE request to {path} and deserialize the response body - pub(crate) async fn delete( + /// Make a GET request to {path} and return the response body + pub(crate) async fn get_raw( &self, path: &str, request_options: &RequestOptions, - ) -> Result - where - O: DeserializeOwned, - { + ) -> Result<(Bytes, HeaderMap), OpenAIError> { let request_maker = || async { let mut request_builder = self .http_client - .delete(self.config.url(path)) + .get(self.config.url(path)) .query(&self.config.query()) .headers(self.config.headers()); @@ -287,41 +281,6 @@ impl Client { Ok(request_builder.build()?) }; - self.execute(request_maker).await - } - - /// Make a GET request to {path} and return the response body - pub(crate) async fn get_raw(&self, path: &str) -> Result<(Bytes, HeaderMap), OpenAIError> { - let request_maker = || async { - Ok(self - .http_client - .get(self.config.url(path)) - .query(&self.config.query()) - .headers(self.config.headers()) - .build()?) - }; - - self.execute_raw(request_maker).await - } - - pub(crate) async fn get_raw_with_query( - &self, - path: &str, - query: &Q, - ) -> Result<(Bytes, HeaderMap), OpenAIError> - where - Q: Serialize + ?Sized, - { - let request_maker = || async { - Ok(self - .http_client - .get(self.config.url(path)) - .query(&self.config.query()) - .query(query) - .headers(self.config.headers()) - .build()?) - }; - self.execute_raw(request_maker).await } diff --git a/async-openai/src/container_files.rs b/async-openai/src/container_files.rs index 2da942d8..541a691e 100644 --- a/async-openai/src/container_files.rs +++ b/async-openai/src/container_files.rs @@ -82,7 +82,10 @@ impl<'c, C: Config> ContainerFiles<'c, C> { pub async fn content(&self, file_id: &str) -> Result { let (bytes, _headers) = self .client - .get_raw(format!("/containers/{}/files/{file_id}/content", self.container_id).as_str()) + .get_raw( + format!("/containers/{}/files/{file_id}/content", self.container_id).as_str(), + &self.request_options, + ) .await?; Ok(bytes) } diff --git a/async-openai/src/file.rs b/async-openai/src/file.rs index 47c37b33..f959b7cc 100644 --- a/async-openai/src/file.rs +++ b/async-openai/src/file.rs @@ -67,7 +67,10 @@ impl<'c, C: Config> Files<'c, C> { pub async fn content(&self, file_id: &str) -> Result { let (bytes, _headers) = self .client - .get_raw(format!("/files/{file_id}/content").as_str()) + .get_raw( + format!("/files/{file_id}/content").as_str(), + &self.request_options, + ) .await?; Ok(bytes) } diff --git a/async-openai/src/fine_tuning.rs b/async-openai/src/fine_tuning.rs index 39d02554..ddc51765 100644 --- a/async-openai/src/fine_tuning.rs +++ b/async-openai/src/fine_tuning.rs @@ -45,16 +45,10 @@ impl<'c, C: Config> FineTuning<'c, C> { } /// List your organization's fine-tuning jobs - #[crate::byot(T0 = serde::Serialize, T1 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn list_paginated( - &self, - query: &Q, - ) -> Result - where - Q: Serialize + ?Sized, - { + #[crate::byot(R = serde::de::DeserializeOwned)] + pub async fn list_paginated(&self) -> Result { self.client - .get_with_query("/fine_tuning/jobs", &query, &self.request_options) + .get("/fine_tuning/jobs", &self.request_options) .await } @@ -108,38 +102,28 @@ impl<'c, C: Config> FineTuning<'c, C> { } /// Get status updates for a fine-tuning job. - #[crate::byot(T0 = std::fmt::Display, T1 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn list_events( + #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] + pub async fn list_events( &self, fine_tuning_job_id: &str, - query: &Q, - ) -> Result - where - Q: Serialize + ?Sized, - { + ) -> Result { self.client - .get_with_query( + .get( format!("/fine_tuning/jobs/{fine_tuning_job_id}/events").as_str(), - &query, &self.request_options, ) .await } /// List checkpoints for a fine-tuning job. - #[crate::byot(T0 = std::fmt::Display, T1 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn list_checkpoints( + #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] + pub async fn list_checkpoints( &self, fine_tuning_job_id: &str, - query: &Q, - ) -> Result - where - Q: Serialize + ?Sized, - { + ) -> Result { self.client - .get_with_query( + .get( format!("/fine_tuning/jobs/{fine_tuning_job_id}/checkpoints").as_str(), - &query, &self.request_options, ) .await @@ -161,20 +145,15 @@ impl<'c, C: Config> FineTuning<'c, C> { .await } - #[crate::byot(T0 = std::fmt::Display, T1 = serde::Serialize, R = serde::de::DeserializeOwned)] - pub async fn list_checkpoint_permissions( + #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)] + pub async fn list_checkpoint_permissions( &self, fine_tuned_model_checkpoint: &str, - query: &Q, - ) -> Result - where - Q: Serialize + ?Sized, - { + ) -> Result { self.client - .get_with_query( + .get( format!("/fine_tuning/checkpoints/{fine_tuned_model_checkpoint}/permissions") .as_str(), - &query, &self.request_options, ) .await diff --git a/async-openai/src/video.rs b/async-openai/src/video.rs index 3e30040f..fcab4a8c 100644 --- a/async-openai/src/video.rs +++ b/async-openai/src/video.rs @@ -3,7 +3,6 @@ use crate::{ error::OpenAIError, types::videos::{ CreateVideoRequest, ListVideosResponse, RemixVideoRequest, VideoJob, VideoJobMetadata, - VideoVariant, }, Client, RequestOptions, }; @@ -74,17 +73,14 @@ impl<'c, C: Config> Videos<'c, C> { self.client.get("/videos", &self.request_options).await } - /// Download video content - pub async fn download_content( - &self, - video_id: &str, - variant: VideoVariant, - ) -> Result { + /// Download video content. + /// Variant can be provided as query parameter + pub async fn download_content(&self, video_id: &str) -> Result { let (bytes, _headers) = self .client - .get_raw_with_query( + .get_raw( &format!("/videos/{video_id}/content"), - &[("variant", variant)], + &self.request_options, ) .await?; Ok(bytes) From aed91807587c1b8bdad704066005dfc02089b73e Mon Sep 17 00:00:00 2001 From: Himanshu Neema Date: Mon, 17 Nov 2025 17:19:42 -0800 Subject: [PATCH 09/22] update examples to use query chain method --- examples/chat-store/src/main.rs | 3 ++- examples/video/src/main.rs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/chat-store/src/main.rs b/examples/chat-store/src/main.rs index d16bd151..3de297a7 100644 --- a/examples/chat-store/src/main.rs +++ b/examples/chat-store/src/main.rs @@ -53,7 +53,8 @@ async fn main() -> Result<(), Box> { let chat_completion_messages = client .chat() - .messages(&response.id, &[("limit", 10)]) + .query(&[("limit", 10)])? + .messages(&response.id) .await?; println!("--------------------------------"); diff --git a/examples/video/src/main.rs b/examples/video/src/main.rs index 979c0727..0c4e8fab 100644 --- a/examples/video/src/main.rs +++ b/examples/video/src/main.rs @@ -81,7 +81,8 @@ async fn main() -> Result<(), Box> { if video.status == "completed" { let content = client .videos() - .download_content(&video.id, VideoVariant::Video) + .query(&[("variant", VideoVariant::Video)])? + .download_content(&video.id) .await; if let Ok(content) = content { let output_path = &format!("./data/{}.mp4", video.id); From 3b2627df943dd96c0f4792d5debe180a33a6f736 Mon Sep 17 00:00:00 2001 From: Himanshu Neema Date: Mon, 17 Nov 2025 17:20:49 -0800 Subject: [PATCH 10/22] cargo clippy fix --- async-openai/src/chat.rs | 1 - async-openai/src/fine_tuning.rs | 1 - 2 files changed, 2 deletions(-) diff --git a/async-openai/src/chat.rs b/async-openai/src/chat.rs index 8bcb7644..1cd12cb0 100644 --- a/async-openai/src/chat.rs +++ b/async-openai/src/chat.rs @@ -1,4 +1,3 @@ -use serde::Serialize; use crate::{ config::Config, diff --git a/async-openai/src/fine_tuning.rs b/async-openai/src/fine_tuning.rs index ddc51765..75eaea7a 100644 --- a/async-openai/src/fine_tuning.rs +++ b/async-openai/src/fine_tuning.rs @@ -1,4 +1,3 @@ -use serde::Serialize; use crate::{ config::Config, From 5955d14b8b48c9199e7fa81d74136e28929a45a0 Mon Sep 17 00:00:00 2001 From: Himanshu Neema Date: Mon, 17 Nov 2025 17:22:06 -0800 Subject: [PATCH 11/22] cargo fmt --- async-openai/src/chat.rs | 1 - async-openai/src/fine_tuning.rs | 1 - 2 files changed, 2 deletions(-) diff --git a/async-openai/src/chat.rs b/async-openai/src/chat.rs index 1cd12cb0..74b15914 100644 --- a/async-openai/src/chat.rs +++ b/async-openai/src/chat.rs @@ -1,4 +1,3 @@ - use crate::{ config::Config, error::OpenAIError, diff --git a/async-openai/src/fine_tuning.rs b/async-openai/src/fine_tuning.rs index 75eaea7a..0ad89672 100644 --- a/async-openai/src/fine_tuning.rs +++ b/async-openai/src/fine_tuning.rs @@ -1,4 +1,3 @@ - use crate::{ config::Config, error::OpenAIError, From cc56c117f3d9ee973695ae552589d3a19974fcb7 Mon Sep 17 00:00:00 2001 From: Himanshu Neema Date: Mon, 17 Nov 2025 17:59:31 -0800 Subject: [PATCH 12/22] handle query properly --- async-openai/Cargo.toml | 1 + async-openai/src/client.rs | 40 ++++++++++++++--------------- async-openai/src/request_options.rs | 36 ++++++++++++++++++-------- 3 files changed, 46 insertions(+), 31 deletions(-) diff --git a/async-openai/Cargo.toml b/async-openai/Cargo.toml index d38ae00d..a05644c0 100644 --- a/async-openai/Cargo.toml +++ b/async-openai/Cargo.toml @@ -51,6 +51,7 @@ secrecy = { version = "0.10.3", features = ["serde"] } bytes = "1.9.0" eventsource-stream = "0.2.3" serde_urlencoded = "0.7.1" +url = "2.5" tokio-tungstenite = { version = "0.26.1", optional = true, default-features = false } hmac = { version = "0.12", optional = true, default-features = false} sha2 = { version = "0.10", optional = true, default-features = false } diff --git a/async-openai/src/client.rs b/async-openai/src/client.rs index 056799e8..7f0e0a4e 100644 --- a/async-openai/src/client.rs +++ b/async-openai/src/client.rs @@ -217,8 +217,8 @@ impl Client { request_builder = request_builder.headers(headers.clone()); } - if let Some(query) = request_options.query() { - request_builder = request_builder.query(query); + if !request_options.query().is_empty() { + request_builder = request_builder.query(request_options.query()); } Ok(request_builder.build()?) @@ -247,8 +247,8 @@ impl Client { request_builder = request_builder.headers(headers.clone()); } - if let Some(query) = request_options.query() { - request_builder = request_builder.query(query); + if !request_options.query().is_empty() { + request_builder = request_builder.query(request_options.query()); } Ok(request_builder.build()?) @@ -274,8 +274,8 @@ impl Client { request_builder = request_builder.headers(headers.clone()); } - if let Some(query) = request_options.query() { - request_builder = request_builder.query(query); + if !request_options.query().is_empty() { + request_builder = request_builder.query(request_options.query()); } Ok(request_builder.build()?) @@ -306,8 +306,8 @@ impl Client { request_builder = request_builder.headers(headers.clone()); } - if let Some(query) = request_options.query() { - request_builder = request_builder.query(query); + if !request_options.query().is_empty() { + request_builder = request_builder.query(request_options.query()); } Ok(request_builder.build()?) @@ -339,8 +339,8 @@ impl Client { request_builder = request_builder.headers(headers.clone()); } - if let Some(query) = request_options.query() { - request_builder = request_builder.query(query); + if !request_options.query().is_empty() { + request_builder = request_builder.query(request_options.query()); } Ok(request_builder.build()?) @@ -372,8 +372,8 @@ impl Client { request_builder = request_builder.headers(headers.clone()); } - if let Some(query) = request_options.query() { - request_builder = request_builder.query(query); + if !request_options.query().is_empty() { + request_builder = request_builder.query(request_options.query()); } Ok(request_builder.build()?) @@ -406,8 +406,8 @@ impl Client { request_builder = request_builder.headers(headers.clone()); } - if let Some(query) = request_options.query() { - request_builder = request_builder.query(query); + if !request_options.query().is_empty() { + request_builder = request_builder.query(request_options.query()); } Ok(request_builder.build()?) @@ -440,8 +440,8 @@ impl Client { request_builder = request_builder.headers(headers.clone()); } - if let Some(query) = request_options.query() { - request_builder = request_builder.query(query); + if !request_options.query().is_empty() { + request_builder = request_builder.query(request_options.query()); } let response = request_builder.send().await.map_err(OpenAIError::Reqwest)?; @@ -591,8 +591,8 @@ impl Client { request_builder = request_builder.headers(headers.clone()); } - if let Some(query) = request_options.query() { - request_builder = request_builder.query(query); + if !request_options.query().is_empty() { + request_builder = request_builder.query(request_options.query()); } let event_source = request_builder.eventsource().unwrap(); @@ -622,8 +622,8 @@ impl Client { request_builder = request_builder.headers(headers.clone()); } - if let Some(query) = request_options.query() { - request_builder = request_builder.query(query); + if !request_options.query().is_empty() { + request_builder = request_builder.query(request_options.query()); } let event_source = request_builder.eventsource().unwrap(); diff --git a/async-openai/src/request_options.rs b/async-openai/src/request_options.rs index 50e48781..e9a3530c 100644 --- a/async-openai/src/request_options.rs +++ b/async-openai/src/request_options.rs @@ -1,18 +1,19 @@ use reqwest::header::HeaderMap; use serde::Serialize; +use url::Url; -use crate::error::OpenAIError; +use crate::{config::OPENAI_API_BASE, error::OpenAIError}; #[derive(Clone, Debug, Default)] pub struct RequestOptions { - query: Option, + query: Vec<(String, String)>, headers: Option, } impl RequestOptions { pub(crate) fn new() -> Self { Self { - query: None, + query: Vec::new(), headers: None, } } @@ -49,18 +50,31 @@ impl RequestOptions { &mut self, query: &Q, ) -> Result<(), OpenAIError> { - let new_query = serde_urlencoded::to_string(query) - .map_err(|e| OpenAIError::InvalidArgument(format!("Invalid query: {}", e)))?; - if let Some(existing_query) = &self.query { - self.query = Some(format!("{}&{}", existing_query, new_query)); - } else { - self.query = Some(new_query); + // Use serde_urlencoded::Serializer directly to handle any serializable type + // similar to how reqwest does it. We create a temporary URL to use query_pairs_mut() + // which allows us to handle any serializable type, not just top-level maps/structs. + let mut url = Url::parse(OPENAI_API_BASE) + .map_err(|e| OpenAIError::InvalidArgument(format!("Failed to create URL: {}", e)))?; + + { + let mut pairs = url.query_pairs_mut(); + let serializer = serde_urlencoded::Serializer::new(&mut pairs); + + query + .serialize(serializer) + .map_err(|e| OpenAIError::InvalidArgument(format!("Invalid query: {}", e)))?; } + + // Extract query pairs from the URL and append to our vec + for (key, value) in url.query_pairs() { + self.query.push((key.to_string(), value.to_string())); + } + Ok(()) } - pub(crate) fn query(&self) -> Option<&str> { - self.query.as_deref() + pub(crate) fn query(&self) -> &[(String, String)] { + &self.query } pub(crate) fn headers(&self) -> Option<&HeaderMap> { From e8bc8b51ccb803817f6820a9666eaa9a22e12e9f Mon Sep 17 00:00:00 2001 From: Himanshu Neema Date: Mon, 17 Nov 2025 18:09:52 -0800 Subject: [PATCH 13/22] fix bring-your-own-type tests --- async-openai/tests/bring-your-own-type.rs | 240 +++++++++++++++++----- 1 file changed, 193 insertions(+), 47 deletions(-) diff --git a/async-openai/tests/bring-your-own-type.rs b/async-openai/tests/bring-your-own-type.rs index b8e8287f..f9628c8e 100644 --- a/async-openai/tests/bring-your-own-type.rs +++ b/async-openai/tests/bring-your-own-type.rs @@ -2,7 +2,7 @@ //! The purpose of this test to make sure that all _byot methods compiles with custom types. use std::pin::Pin; -use async_openai::{error::OpenAIError, Client}; +use async_openai::{error::OpenAIError, traits::RequestOptionsBuilder, Client}; use futures::Stream; use serde_json::{json, Value}; @@ -23,7 +23,12 @@ async fn test_byot_files() { let client = Client::new(); let _r: Result = client.files().create_byot(MyJson(json!({}))).await; - let _r: Result = client.files().list_byot([("limit", "2")]).await; + let _r: Result = client + .files() + .query(&[("limit", "2")]) + .unwrap() + .list_byot() + .await; let _r: Result = client.files().retrieve_byot("file_id").await; let _r: Result = client.files().delete_byot("file_id").await; } @@ -35,7 +40,12 @@ async fn test_byot_assistants() { let _r: Result = client.assistants().create_byot(json!({})).await; let _r: Result = client.assistants().retrieve_byot("aid").await; let _r: Result = client.assistants().update_byot("aid", json!({})).await; - let _r: Result = client.assistants().list_byot([("limit", 2)]).await; + let _r: Result = client + .assistants() + .query(&[("limit", 2)]) + .unwrap() + .list_byot() + .await; } #[tokio::test] @@ -125,7 +135,9 @@ async fn test_byot_fine_tunning() { let _r: Result = client.fine_tuning().create_byot(json!({})).await; let _r: Result = client .fine_tuning() - .list_paginated_byot([("limit", "2")]) + .query(&[("limit", "2")]) + .unwrap() + .list_paginated_byot() .await; let _r: Result = client .fine_tuning() @@ -135,11 +147,15 @@ async fn test_byot_fine_tunning() { client.fine_tuning().cancel_byot("fine_tuning_job_id").await; let _r: Result = client .fine_tuning() - .list_events_byot("fine_tuning_job_id", [("limit", "2")]) + .query(&[("limit", "2")]) + .unwrap() + .list_events_byot("fine_tuning_job_id") .await; let _r: Result = client .fine_tuning() - .list_checkpoints_byot("fine_tuning_job_id", [("limit", "2")]) + .query(&[("limit", "2")]) + .unwrap() + .list_checkpoints_byot("fine_tuning_job_id") .await; } @@ -190,7 +206,9 @@ async fn test_byot_messages() { let _r: Result = client .threads() .messages("thread_id") - .list_byot([("limit", "2")]) + .query(&[("limit", "2")]) + .unwrap() + .list_byot() .await; let _r: Result = client .threads() @@ -226,7 +244,9 @@ async fn test_byot_runs() { let _r: Result = client .threads() .runs("thread_id") - .list_byot([("limit", "2")]) + .query(&[("limit", "2")]) + .unwrap() + .list_byot() .await; let _r: Result = client .threads() @@ -259,7 +279,9 @@ async fn test_byot_run_steps() { .threads() .runs("thread_id") .steps("run_id") - .list_byot([("limit", "2")]) + .query(&[("limit", "2")]) + .unwrap() + .list_byot() .await; } @@ -284,7 +306,9 @@ async fn test_byot_vector_store_files() { let _r: Result = client .vector_stores() .files("vector_store_id") - .list_byot([("limit", "2")]) + .query(&[("limit", "2")]) + .unwrap() + .list_byot() .await; } @@ -309,7 +333,9 @@ async fn test_byot_vector_store_file_batches() { let _r: Result = client .vector_stores() .file_batches("vector_store_id") - .list_files_byot("batch_id", [("limit", "2")]) + .query(&[("limit", "2")]) + .unwrap() + .list_files_byot("batch_id") .await; } @@ -317,7 +343,12 @@ async fn test_byot_vector_store_file_batches() { async fn test_byot_batches() { let client = Client::new(); let _r: Result = client.batches().create_byot(json!({})).await; - let _r: Result = client.batches().list_byot([("limit", "2")]).await; + let _r: Result = client + .batches() + .query(&[("limit", "2")]) + .unwrap() + .list_byot() + .await; let _r: Result = client.batches().retrieve_byot("batch_id").await; let _r: Result = client.batches().cancel_byot("batch_id").await; } @@ -325,8 +356,13 @@ async fn test_byot_batches() { #[tokio::test] async fn test_byot_audit_logs() { let client = Client::new(); - let _r: Result = - client.admin().audit_logs().get_byot([("limit", "2")]).await; + let _r: Result = client + .admin() + .audit_logs() + .query(&[("limit", "2")]) + .unwrap() + .get_byot() + .await; } #[tokio::test] @@ -335,15 +371,26 @@ async fn test_byot_invites() { let _r: Result = client.admin().invites().create_byot(json!({})).await; let _r: Result = client.admin().invites().retrieve_byot("invite_id").await; let _r: Result = client.admin().invites().delete_byot("invite_id").await; - let _r: Result = client.admin().invites().list_byot([("limit", "2")]).await; + let _r: Result = client + .admin() + .invites() + .query(&[("limit", "2")]) + .unwrap() + .list_byot() + .await; } #[tokio::test] async fn test_byot_projects() { let client = Client::new(); - let _r: Result = - client.admin().projects().list_byot([("limit", "2")]).await; + let _r: Result = client + .admin() + .projects() + .query(&[("limit", "2")]) + .unwrap() + .list_byot() + .await; let _r: Result = client.admin().projects().create_byot(json!({})).await; let _r: Result = client.admin().projects().retrieve_byot("project_id").await; @@ -363,7 +410,9 @@ async fn test_byot_project_api_keys() { .admin() .projects() .api_keys("project_id") - .list_byot([("query", "2")]) + .query(&[("query", "2")]) + .unwrap() + .list_byot() .await; let _r: Result = client @@ -410,7 +459,9 @@ async fn test_byot_project_service_accounts() { .admin() .projects() .service_accounts("project_id") - .list_byot([("limit", "2")]) + .query(&[("limit", "2")]) + .unwrap() + .list_byot() .await; } @@ -435,7 +486,9 @@ async fn test_byot_project_users() { .admin() .projects() .users("project_id") - .list_byot([("limit", "2")]) + .query(&[("limit", "2")]) + .unwrap() + .list_byot() .await; let _r: Result = client @@ -464,7 +517,13 @@ async fn test_byot_uploads() { async fn test_byot_users() { let client = Client::new(); - let _r: Result = client.admin().users().list_byot([("limit", "2")]).await; + let _r: Result = client + .admin() + .users() + .query(&[("limit", "2")]) + .unwrap() + .list_byot() + .await; let _r: Result = client .admin() .users() @@ -483,7 +542,12 @@ async fn test_byot_vector_stores() { .vector_stores() .retrieve_byot("vector_store_id") .await; - let _r: Result = client.vector_stores().list_byot([("limit", "2")]).await; + let _r: Result = client + .vector_stores() + .query(&[("limit", "2")]) + .unwrap() + .list_byot() + .await; let _r: Result = client.vector_stores().delete_byot("vector_store_id").await; let _r: Result = client @@ -513,13 +577,17 @@ async fn test_byot_responses() { client.responses().create_stream_byot(json!({})).await; let _r: Result = client .responses() - .retrieve_byot("response_id", [("limit", "2")]) + .query(&[("limit", "2")]) + .unwrap() + .retrieve_byot("response_id") .await; let _r: Result = client.responses().delete_byot("response_id").await; let _r: Result = client.responses().cancel_byot("response_id").await; let _r: Result = client .responses() - .list_input_items_byot("response_id", [("limit", "2")]) + .query(&[("limit", "2")]) + .unwrap() + .list_input_items_byot("response_id") .await; let _r: Result = client .responses() @@ -556,7 +624,9 @@ async fn test_byot_conversation_items() { let _r: Result = client .conversations() .items("conversation_id") - .list_byot([("limit", "2")]) + .query(&[("limit", "2")]) + .unwrap() + .list_byot() .await; let _r: Result = client .conversations() @@ -574,21 +644,60 @@ async fn test_byot_conversation_items() { async fn test_byot_usage() { let client = Client::new(); - let _r: Result = client.usage().audio_speeches_byot([("limit", "2")]).await; let _r: Result = client .usage() - .audio_transcriptions_byot([("limit", "2")]) + .query(&[("limit", "2")]) + .unwrap() + .audio_speeches_byot() + .await; + let _r: Result = client + .usage() + .query(&[("limit", "2")]) + .unwrap() + .audio_transcriptions_byot() .await; let _r: Result = client .usage() - .code_interpreter_sessions_byot([("limit", "2")]) + .query(&[("limit", "2")]) + .unwrap() + .code_interpreter_sessions_byot() + .await; + let _r: Result = client + .usage() + .query(&[("limit", "2")]) + .unwrap() + .completions_byot() + .await; + let _r: Result = client + .usage() + .query(&[("limit", "2")]) + .unwrap() + .embeddings_byot() + .await; + let _r: Result = client + .usage() + .query(&[("limit", "2")]) + .unwrap() + .images_byot() + .await; + let _r: Result = client + .usage() + .query(&[("limit", "2")]) + .unwrap() + .moderations_byot() + .await; + let _r: Result = client + .usage() + .query(&[("limit", "2")]) + .unwrap() + .vector_stores_byot() + .await; + let _r: Result = client + .usage() + .query(&[("limit", "2")]) + .unwrap() + .costs_byot() .await; - let _r: Result = client.usage().completions_byot([("limit", "2")]).await; - let _r: Result = client.usage().embeddings_byot([("limit", "2")]).await; - let _r: Result = client.usage().images_byot([("limit", "2")]).await; - let _r: Result = client.usage().moderations_byot([("limit", "2")]).await; - let _r: Result = client.usage().vector_stores_byot([("limit", "2")]).await; - let _r: Result = client.usage().costs_byot([("limit", "2")]).await; } #[tokio::test] @@ -598,15 +707,22 @@ async fn test_byot_chatkit() { let _r: Result = client.chatkit().sessions().create_byot(json!({})).await; let _r: Result = client.chatkit().sessions().cancel_byot("session_id").await; - let _r: Result = - client.chatkit().threads().list_byot([("limit", "2")]).await; + let _r: Result = client + .chatkit() + .threads() + .query(&[("limit", "2")]) + .unwrap() + .list_byot() + .await; let _r: Result = client.chatkit().threads().retrieve_byot("thread_id").await; let _r: Result = client.chatkit().threads().delete_byot("thread_id").await; let _r: Result = client .chatkit() .threads() - .list_items_byot("thread_id", [("limit", "2")]) + .query(&[("limit", "2")]) + .unwrap() + .list_items_byot("thread_id") .await; } @@ -615,7 +731,12 @@ async fn test_byot_containers() { let client = Client::new(); let _r: Result = client.containers().create_byot(json!({})).await; - let _r: Result = client.containers().list_byot([("limit", "2")]).await; + let _r: Result = client + .containers() + .query(&[("limit", "2")]) + .unwrap() + .list_byot() + .await; let _r: Result = client.containers().retrieve_byot("container_id").await; let _r: Result = client.containers().delete_byot("container_id").await; } @@ -632,7 +753,9 @@ async fn test_byot_container_files() { let _r: Result = client .containers() .files("container_id") - .list_byot([("limit", "2")]) + .query(&[("limit", "2")]) + .unwrap() + .list_byot() .await; let _r: Result = client .containers() @@ -650,8 +773,13 @@ async fn test_byot_container_files() { async fn test_byot_admin_api_keys() { let client = Client::new(); - let _r: Result = - client.admin().api_keys().list_byot([("limit", "2")]).await; + let _r: Result = client + .admin() + .api_keys() + .query(&[("limit", "2")]) + .unwrap() + .list_byot() + .await; let _r: Result = client.admin().api_keys().retrieve_byot("key_id").await; let _r: Result = client.admin().api_keys().delete_byot("key_id").await; } @@ -663,7 +791,9 @@ async fn test_byot_certificates() { let _r: Result = client .admin() .certificates() - .list_organization_byot([("limit", "2")]) + .query(&[("limit", "2")]) + .unwrap() + .list_organization_byot() .await; let _r: Result = client .admin() @@ -690,7 +820,9 @@ async fn test_byot_project_rate_limits() { .admin() .projects() .rate_limits("project_id") - .list_byot([("limit", "2")]) + .query(&[("limit", "2")]) + .unwrap() + .list_byot() .await; let _r: Result = client .admin() @@ -704,7 +836,12 @@ async fn test_byot_project_rate_limits() { async fn test_byot_evals() { let client = Client::new(); - let _r: Result = client.evals().list_byot([("limit", "2")]).await; + let _r: Result = client + .evals() + .query(&[("limit", "2")]) + .unwrap() + .list_byot() + .await; let _r: Result = client.evals().create_byot(json!({})).await; let _r: Result = client.evals().retrieve_byot("eval_id").await; let _r: Result = client.evals().update_byot("eval_id", json!({})).await; @@ -718,7 +855,9 @@ async fn test_byot_eval_runs() { let _r: Result = client .evals() .runs("eval_id") - .list_byot([("limit", "2")]) + .query(&[("limit", "2")]) + .unwrap() + .list_byot() .await; let _r: Result = client.evals().runs("eval_id").create_byot(json!({})).await; @@ -736,7 +875,9 @@ async fn test_byot_eval_run_output_items() { .evals() .runs("eval_id") .output_items("run_id") - .list_byot([("limit", "2")]) + .query(&[("limit", "2")]) + .unwrap() + .list_byot() .await; let _r: Result = client .evals() @@ -754,5 +895,10 @@ async fn test_byot_videos() { let _r: Result = client.videos().remix_byot("video_id", json!({})).await; let _r: Result = client.videos().retrieve_byot("video_id").await; let _r: Result = client.videos().delete_byot("video_id").await; - let _r: Result = client.videos().list_byot([("limit", "2")]).await; + let _r: Result = client + .videos() + .query(&[("limit", "2")]) + .unwrap() + .list_byot() + .await; } From ac0a620850d1f68bc170417a2abb3037c96440d6 Mon Sep 17 00:00:00 2001 From: Himanshu Neema Date: Tue, 18 Nov 2025 12:44:42 -0800 Subject: [PATCH 14/22] query parameters for all APIs --- .gitignore | 2 + async-openai/src/types/admin/api.rs | 301 ++++++++++++++++++ async-openai/src/types/admin/mod.rs | 3 + async-openai/src/types/admin/usage.rs | 36 --- async-openai/src/types/assistants/api.rs | 118 +++++++ async-openai/src/types/assistants/mod.rs | 2 + async-openai/src/types/batches/api.rs | 20 ++ async-openai/src/types/batches/mod.rs | 2 + async-openai/src/types/chat/api.rs | 67 ++++ async-openai/src/types/chat/mod.rs | 2 + async-openai/src/types/chatkit/api.rs | 71 +++++ async-openai/src/types/chatkit/mod.rs | 2 + async-openai/src/types/containers/api.rs | 62 ++++ .../src/types/containers/container.rs | 36 --- async-openai/src/types/containers/mod.rs | 2 + async-openai/src/types/evals/api.rs | 135 ++++++++ async-openai/src/types/evals/mod.rs | 2 + async-openai/src/types/files/api.rs | 36 +++ async-openai/src/types/files/mod.rs | 2 + async-openai/src/types/finetuning/api.rs | 110 +++++++ async-openai/src/types/finetuning/mod.rs | 2 + async-openai/src/types/responses/api.rs | 107 +++++++ .../src/types/responses/conversation.rs | 25 -- async-openai/src/types/responses/mod.rs | 2 + async-openai/src/types/vectorstores/api.rs | 134 ++++++++ async-openai/src/types/vectorstores/mod.rs | 2 + async-openai/src/types/videos/api.rs | 32 ++ async-openai/src/types/videos/mod.rs | 2 + 28 files changed, 1220 insertions(+), 97 deletions(-) create mode 100644 async-openai/src/types/admin/api.rs create mode 100644 async-openai/src/types/assistants/api.rs create mode 100644 async-openai/src/types/batches/api.rs create mode 100644 async-openai/src/types/chat/api.rs create mode 100644 async-openai/src/types/chatkit/api.rs create mode 100644 async-openai/src/types/containers/api.rs create mode 100644 async-openai/src/types/evals/api.rs create mode 100644 async-openai/src/types/files/api.rs create mode 100644 async-openai/src/types/finetuning/api.rs create mode 100644 async-openai/src/types/responses/api.rs create mode 100644 async-openai/src/types/vectorstores/api.rs create mode 100644 async-openai/src/types/videos/api.rs diff --git a/.gitignore b/.gitignore index 0d4aa54e..4ece9319 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ Cargo.lock data *.mp3 + +*.py \ No newline at end of file diff --git a/async-openai/src/types/admin/api.rs b/async-openai/src/types/admin/api.rs new file mode 100644 index 00000000..ffdbd399 --- /dev/null +++ b/async-openai/src/types/admin/api.rs @@ -0,0 +1,301 @@ +use crate::error::OpenAIError; +use derive_builder::Builder; +use serde::{Deserialize, Serialize}; + +use super::usage::{UsageBucketWidth, UsageGroupBy}; + +/// Sort order for listing admin API keys. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "lowercase")] +pub enum ListAdminApiKeysOrder { + /// Ascending order + Asc, + /// Descending order + Desc, +} + +/// Query parameters for listing admin API keys. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "ListAdminApiKeysQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct ListAdminApiKeysQuery { + /// Return keys with IDs that come after this ID in the pagination order. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, + /// Order results by creation time, ascending or descending. + #[serde(skip_serializing_if = "Option::is_none")] + pub order: Option, + /// Maximum number of keys to return. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, +} + +/// Query parameters for listing audit logs. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "ListAuditLogsQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct ListAuditLogsQuery { + /// Return only events whose `effective_at` (Unix seconds) is in this range. + #[serde(skip_serializing_if = "Option::is_none")] + pub effective_at: Option, + /// Return only events for these projects. + #[serde(skip_serializing_if = "Option::is_none")] + pub project_ids: Option>, + /// Return only events with a `type` in one of these values. + #[serde(skip_serializing_if = "Option::is_none")] + pub event_types: Option>, + /// Return only events performed by these actors. + #[serde(skip_serializing_if = "Option::is_none")] + pub actor_ids: Option>, + /// Return only events performed by users with these emails. + #[serde(skip_serializing_if = "Option::is_none")] + pub actor_emails: Option>, + /// Return only events performed on these targets. + #[serde(skip_serializing_if = "Option::is_none")] + pub resource_ids: Option>, + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, + /// A cursor for use in pagination. `before` is an object ID that defines your place in the list. + #[serde(skip_serializing_if = "Option::is_none")] + pub before: Option, +} + +/// Sort order for listing organization certificates. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "lowercase")] +pub enum ListOrganizationCertificatesOrder { + /// Ascending order + Asc, + /// Descending order + Desc, +} + +/// Query parameters for listing organization certificates. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "ListOrganizationCertificatesQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct ListOrganizationCertificatesQuery { + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, + /// Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` for descending order. + #[serde(skip_serializing_if = "Option::is_none")] + pub order: Option, +} + +/// Query parameters for listing invites. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "ListInvitesQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct ListInvitesQuery { + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, +} + +/// Query parameters for listing projects. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "ListProjectsQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct ListProjectsQuery { + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, + /// If `true` returns all projects including those that have been `archived`. Archived projects are not included by default. + #[serde(skip_serializing_if = "Option::is_none")] + pub include_archived: Option, +} + +/// Query parameters for listing project API keys. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "ListProjectApiKeysQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct ListProjectApiKeysQuery { + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, +} + +/// Sort order for listing project certificates. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "lowercase")] +pub enum ListProjectCertificatesOrder { + /// Ascending order + Asc, + /// Descending order + Desc, +} + +/// Query parameters for listing project certificates. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "ListProjectCertificatesQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct ListProjectCertificatesQuery { + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, + /// Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` for descending order. + #[serde(skip_serializing_if = "Option::is_none")] + pub order: Option, +} + +/// Query parameters for listing project rate limits. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "ListProjectRateLimitsQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct ListProjectRateLimitsQuery { + /// A limit on the number of objects to be returned. The default is 100. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, + /// A cursor for use in pagination. `before` is an object ID that defines your place in the list. + #[serde(skip_serializing_if = "Option::is_none")] + pub before: Option, +} + +/// Query parameters for listing project service accounts. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "ListProjectServiceAccountsQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct ListProjectServiceAccountsQuery { + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, +} + +/// Query parameters for listing project users. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "ListProjectUsersQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct ListProjectUsersQuery { + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, +} + +/// Query parameters for listing users. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "ListUsersQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct ListUsersQuery { + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, + /// Filter by the email address of users. + #[serde(skip_serializing_if = "Option::is_none")] + pub emails: Option>, +} + +/// Query parameters for organization usage endpoints. +#[derive(Debug, Clone, Serialize, Default)] +pub struct UsageQueryParams { + /// Start time (Unix seconds) of the query time range, inclusive. + pub start_time: u64, + /// End time (Unix seconds) of the query time range, exclusive. + #[serde(skip_serializing_if = "Option::is_none")] + pub end_time: Option, + /// Width of each time bucket in response. Currently `1m`, `1h` and `1d` are supported, default to `1d`. + #[serde(skip_serializing_if = "Option::is_none")] + pub bucket_width: Option, + /// Return only usage for these projects. + #[serde(skip_serializing_if = "Option::is_none")] + pub project_ids: Option>, + /// Return only usage for these users. + #[serde(skip_serializing_if = "Option::is_none")] + pub user_ids: Option>, + /// Return only usage for these API keys. + #[serde(skip_serializing_if = "Option::is_none")] + pub api_key_ids: Option>, + /// Return only usage for these models. + #[serde(skip_serializing_if = "Option::is_none")] + pub models: Option>, + /// If `true`, return batch jobs only. If `false`, return non-batch jobs only. By default, return both. + #[serde(skip_serializing_if = "Option::is_none")] + pub batch: Option, + /// Group the usage data by the specified fields. + #[serde(skip_serializing_if = "Option::is_none")] + pub group_by: Option>, + /// Specifies the number of buckets to return. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// A cursor for use in pagination. Corresponding to the `next_page` field from the previous response. + #[serde(skip_serializing_if = "Option::is_none")] + pub page: Option, +} + +/// Query parameters for getting a certificate. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "GetCertificateQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct GetCertificateQuery { + /// A list of additional fields to include in the response. Currently the only supported value is `content` to fetch the PEM content of the certificate. + #[serde(skip_serializing_if = "Option::is_none")] + pub include: Option>, +} + diff --git a/async-openai/src/types/admin/mod.rs b/async-openai/src/types/admin/mod.rs index 396f3ca5..99977db4 100644 --- a/async-openai/src/types/admin/mod.rs +++ b/async-openai/src/types/admin/mod.rs @@ -1,5 +1,6 @@ //! Admin-related types for organization management APIs. +pub mod api; pub mod api_keys; pub mod audit_logs; pub mod certificates; @@ -11,3 +12,5 @@ pub mod project_users; pub mod projects; pub mod usage; pub mod users; + +pub use api::*; diff --git a/async-openai/src/types/admin/usage.rs b/async-openai/src/types/admin/usage.rs index dfdb8da1..ef24e7e7 100644 --- a/async-openai/src/types/admin/usage.rs +++ b/async-openai/src/types/admin/usage.rs @@ -24,42 +24,6 @@ pub enum UsageGroupBy { ServiceTier, } -/// Query parameters for organization usage endpoints. -#[derive(Debug, Clone, Serialize, Default)] -pub struct UsageQueryParams { - /// Start time (Unix seconds) of the query time range, inclusive. - pub start_time: u64, - /// End time (Unix seconds) of the query time range, exclusive. - #[serde(skip_serializing_if = "Option::is_none")] - pub end_time: Option, - /// Width of each time bucket in response. Currently `1m`, `1h` and `1d` are supported, default to `1d`. - #[serde(skip_serializing_if = "Option::is_none")] - pub bucket_width: Option, - /// Return only usage for these projects. - #[serde(skip_serializing_if = "Option::is_none")] - pub project_ids: Option>, - /// Return only usage for these users. - #[serde(skip_serializing_if = "Option::is_none")] - pub user_ids: Option>, - /// Return only usage for these API keys. - #[serde(skip_serializing_if = "Option::is_none")] - pub api_key_ids: Option>, - /// Return only usage for these models. - #[serde(skip_serializing_if = "Option::is_none")] - pub models: Option>, - /// If `true`, return batch jobs only. If `false`, return non-batch jobs only. By default, return both. - #[serde(skip_serializing_if = "Option::is_none")] - pub batch: Option, - /// Group the usage data by the specified fields. - #[serde(skip_serializing_if = "Option::is_none")] - pub group_by: Option>, - /// Specifies the number of buckets to return. - #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, - /// A cursor for use in pagination. Corresponding to the `next_page` field from the previous response. - #[serde(skip_serializing_if = "Option::is_none")] - pub page: Option, -} /// Response structure for organization usage endpoints. #[derive(Debug, Clone, Deserialize)] diff --git a/async-openai/src/types/assistants/api.rs b/async-openai/src/types/assistants/api.rs new file mode 100644 index 00000000..d422fc48 --- /dev/null +++ b/async-openai/src/types/assistants/api.rs @@ -0,0 +1,118 @@ +use crate::error::OpenAIError; +use derive_builder::Builder; +use serde::{Deserialize, Serialize}; + +/// Sort order for listing messages. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "lowercase")] +pub enum ListMessagesOrder { + /// Ascending order + Asc, + /// Descending order + Desc, +} + +/// Query parameters for listing messages. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "ListMessagesQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct ListMessagesQuery { + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` for descending order. + #[serde(skip_serializing_if = "Option::is_none")] + pub order: Option, + /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, + /// A cursor for use in pagination. `before` is an object ID that defines your place in the list. + #[serde(skip_serializing_if = "Option::is_none")] + pub before: Option, + /// Filter messages by the run ID that generated them. + #[serde(skip_serializing_if = "Option::is_none")] + pub run_id: Option, +} + +/// Sort order for listing runs. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "lowercase")] +pub enum ListRunsOrder { + /// Ascending order + Asc, + /// Descending order + Desc, +} + +/// Query parameters for listing runs. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "ListRunsQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct ListRunsQuery { + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` for descending order. + #[serde(skip_serializing_if = "Option::is_none")] + pub order: Option, + /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, + /// A cursor for use in pagination. `before` is an object ID that defines your place in the list. + #[serde(skip_serializing_if = "Option::is_none")] + pub before: Option, +} + +/// Sort order for listing run steps. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "lowercase")] +pub enum ListRunStepsOrder { + /// Ascending order + Asc, + /// Descending order + Desc, +} + +/// Query parameters for listing run steps. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "ListRunStepsQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct ListRunStepsQuery { + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` for descending order. + #[serde(skip_serializing_if = "Option::is_none")] + pub order: Option, + /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, + /// A cursor for use in pagination. `before` is an object ID that defines your place in the list. + #[serde(skip_serializing_if = "Option::is_none")] + pub before: Option, + /// A list of additional fields to include in the response. Currently the only supported value is `step_details.tool_calls[*].file_search.results[*].content` to fetch the file search result content. + #[serde(skip_serializing_if = "Option::is_none")] + pub include: Option>, +} + +/// Query parameters for retrieving a run step. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "GetRunStepQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct GetRunStepQuery { + /// A list of additional fields to include in the response. Currently the only supported value is `step_details.tool_calls[*].file_search.results[*].content` to fetch the file search result content. + #[serde(skip_serializing_if = "Option::is_none")] + pub include: Option>, +} diff --git a/async-openai/src/types/assistants/mod.rs b/async-openai/src/types/assistants/mod.rs index b0debabf..3f645f7a 100644 --- a/async-openai/src/types/assistants/mod.rs +++ b/async-openai/src/types/assistants/mod.rs @@ -1,3 +1,4 @@ +mod api; mod assistant; mod assistant_impls; mod assistant_stream; @@ -6,6 +7,7 @@ mod run; mod step; mod thread; +pub use api::*; pub use assistant::*; pub use assistant_stream::*; pub use message::*; diff --git a/async-openai/src/types/batches/api.rs b/async-openai/src/types/batches/api.rs new file mode 100644 index 00000000..bd431383 --- /dev/null +++ b/async-openai/src/types/batches/api.rs @@ -0,0 +1,20 @@ +use crate::error::OpenAIError; +use derive_builder::Builder; +use serde::Serialize; + +/// Query parameters for listing batches. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "ListBatchesQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct ListBatchesQuery { + /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, +} + diff --git a/async-openai/src/types/batches/mod.rs b/async-openai/src/types/batches/mod.rs index ab4c11ca..98701977 100644 --- a/async-openai/src/types/batches/mod.rs +++ b/async-openai/src/types/batches/mod.rs @@ -1,3 +1,5 @@ +mod api; mod batch; +pub use api::*; pub use batch::*; diff --git a/async-openai/src/types/chat/api.rs b/async-openai/src/types/chat/api.rs new file mode 100644 index 00000000..a488eccc --- /dev/null +++ b/async-openai/src/types/chat/api.rs @@ -0,0 +1,67 @@ +use crate::error::OpenAIError; +use derive_builder::Builder; +use serde::{Deserialize, Serialize}; + +/// Sort order for listing chat completions. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "lowercase")] +pub enum ListChatCompletionsOrder { + /// Ascending order + Asc, + /// Descending order + Desc, +} + +/// Query parameters for listing chat completions. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "ListChatCompletionsQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct ListChatCompletionsQuery { + /// The model used to generate the Chat Completions. + #[serde(skip_serializing_if = "Option::is_none")] + pub model: Option, + /// A list of metadata keys to filter the Chat Completions by. + #[serde(skip_serializing_if = "Option::is_none")] + pub metadata: Option, + /// Identifier for the last chat completion from the previous pagination request. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, + /// Number of Chat Completions to retrieve. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// Sort order for Chat Completions by timestamp. Use `asc` for ascending order or `desc` for descending order. Defaults to `asc`. + #[serde(skip_serializing_if = "Option::is_none")] + pub order: Option, +} + +/// Sort order for listing chat completion messages. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "lowercase")] +pub enum GetChatCompletionMessagesOrder { + /// Ascending order + Asc, + /// Descending order + Desc, +} + +/// Query parameters for getting chat completion messages. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "GetChatCompletionMessagesQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct GetChatCompletionMessagesQuery { + /// Identifier for the last message from the previous pagination request. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, + /// Number of messages to retrieve. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// Sort order for messages by timestamp. Use `asc` for ascending order or `desc` for descending order. Defaults to `asc`. + #[serde(skip_serializing_if = "Option::is_none")] + pub order: Option, +} diff --git a/async-openai/src/types/chat/mod.rs b/async-openai/src/types/chat/mod.rs index 4634f935..f3f50df4 100644 --- a/async-openai/src/types/chat/mod.rs +++ b/async-openai/src/types/chat/mod.rs @@ -1,3 +1,5 @@ +mod api; mod chat_types; +pub use api::*; pub use chat_types::*; diff --git a/async-openai/src/types/chatkit/api.rs b/async-openai/src/types/chatkit/api.rs new file mode 100644 index 00000000..73195832 --- /dev/null +++ b/async-openai/src/types/chatkit/api.rs @@ -0,0 +1,71 @@ +use crate::error::OpenAIError; +use derive_builder::Builder; +use serde::{Deserialize, Serialize}; + +/// Sort order for listing ChatKit threads. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "lowercase")] +pub enum ListChatKitThreadsOrder { + /// Ascending order + Asc, + /// Descending order + Desc, +} + +/// Query parameters for listing ChatKit threads. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "ListChatKitThreadsQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct ListChatKitThreadsQuery { + /// Maximum number of thread items to return. Defaults to 20. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// Sort order for results by creation time. Defaults to `desc`. + #[serde(skip_serializing_if = "Option::is_none")] + pub order: Option, + /// List items created after this thread item ID. Defaults to null for the first page. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, + /// List items created before this thread item ID. Defaults to null for the newest results. + #[serde(skip_serializing_if = "Option::is_none")] + pub before: Option, + /// Filter threads that belong to this user identifier. Defaults to null to return all users. + #[serde(skip_serializing_if = "Option::is_none")] + pub user: Option, +} + +/// Sort order for listing ChatKit thread items. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "lowercase")] +pub enum ListChatKitThreadItemsOrder { + /// Ascending order + Asc, + /// Descending order + Desc, +} + +/// Query parameters for listing ChatKit thread items. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "ListChatKitThreadItemsQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct ListChatKitThreadItemsQuery { + /// Maximum number of thread items to return. Defaults to 20. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// Sort order for results by creation time. Defaults to `desc`. + #[serde(skip_serializing_if = "Option::is_none")] + pub order: Option, + /// List items created after this thread item ID. Defaults to null for the first page. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, + /// List items created before this thread item ID. Defaults to null for the newest results. + #[serde(skip_serializing_if = "Option::is_none")] + pub before: Option, +} + diff --git a/async-openai/src/types/chatkit/mod.rs b/async-openai/src/types/chatkit/mod.rs index ad660ea1..bf0bbd69 100644 --- a/async-openai/src/types/chatkit/mod.rs +++ b/async-openai/src/types/chatkit/mod.rs @@ -1,5 +1,7 @@ +mod api; mod session; mod thread; +pub use api::*; pub use session::*; pub use thread::*; diff --git a/async-openai/src/types/containers/api.rs b/async-openai/src/types/containers/api.rs new file mode 100644 index 00000000..a2f9764b --- /dev/null +++ b/async-openai/src/types/containers/api.rs @@ -0,0 +1,62 @@ +use crate::error::OpenAIError; +use derive_builder::Builder; +use serde::{Deserialize, Serialize}; + +/// Sort order for listing containers. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "lowercase")] +pub enum ListContainersOrder { + /// Ascending order + Asc, + /// Descending order + Desc, +} + +/// Query parameters for listing containers. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "ListContainersQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct ListContainersQuery { + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` for descending order. + #[serde(skip_serializing_if = "Option::is_none")] + pub order: Option, + /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, +} + +/// Sort order for listing container files. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "lowercase")] +pub enum ListContainerFilesOrder { + /// Ascending order + Asc, + /// Descending order + Desc, +} + +/// Query parameters for listing container files. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "ListContainerFilesQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct ListContainerFilesQuery { + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` for descending order. + #[serde(skip_serializing_if = "Option::is_none")] + pub order: Option, + /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, +} + diff --git a/async-openai/src/types/containers/container.rs b/async-openai/src/types/containers/container.rs index 597b4466..5d51ad93 100644 --- a/async-openai/src/types/containers/container.rs +++ b/async-openai/src/types/containers/container.rs @@ -83,24 +83,6 @@ pub struct DeleteContainerResponse { pub deleted: bool, } -/// Query parameters for listing containers. -#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] -#[builder(name = "ListContainersQueryArgs")] -#[builder(pattern = "mutable")] -#[builder(setter(into, strip_option), default)] -#[builder(derive(Debug))] -#[builder(build_fn(error = "OpenAIError"))] -pub struct ListContainersQuery { - /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. - #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, - /// Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` for descending order. - #[serde(skip_serializing_if = "Option::is_none")] - pub order: Option, - /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. - #[serde(skip_serializing_if = "Option::is_none")] - pub after: Option, -} // Container File types @@ -156,21 +138,3 @@ pub struct DeleteContainerFileResponse { pub deleted: bool, } -/// Query parameters for listing container files. -#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] -#[builder(name = "ListContainerFilesQueryArgs")] -#[builder(pattern = "mutable")] -#[builder(setter(into, strip_option), default)] -#[builder(derive(Debug))] -#[builder(build_fn(error = "OpenAIError"))] -pub struct ListContainerFilesQuery { - /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. - #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, - /// Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` for descending order. - #[serde(skip_serializing_if = "Option::is_none")] - pub order: Option, - /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. - #[serde(skip_serializing_if = "Option::is_none")] - pub after: Option, -} diff --git a/async-openai/src/types/containers/mod.rs b/async-openai/src/types/containers/mod.rs index f6990dfa..b7ab5455 100644 --- a/async-openai/src/types/containers/mod.rs +++ b/async-openai/src/types/containers/mod.rs @@ -1,3 +1,5 @@ +mod api; mod container; +pub use api::*; pub use container::*; diff --git a/async-openai/src/types/evals/api.rs b/async-openai/src/types/evals/api.rs new file mode 100644 index 00000000..1da411af --- /dev/null +++ b/async-openai/src/types/evals/api.rs @@ -0,0 +1,135 @@ +use crate::error::OpenAIError; +use derive_builder::Builder; +use serde::{Deserialize, Serialize}; + +/// Sort order for listing evals. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "lowercase")] +pub enum ListEvalsOrder { + /// Ascending order + Asc, + /// Descending order + Desc, +} + +/// Order by field for listing evals. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "snake_case")] +pub enum ListEvalsOrderBy { + /// Order by creation time + CreatedAt, + /// Order by last updated time + UpdatedAt, +} + +/// Query parameters for listing evals. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "ListEvalsQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct ListEvalsQuery { + /// Identifier for the last eval from the previous pagination request. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, + /// Number of evals to retrieve. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// Sort order for evals by timestamp. Use `asc` for ascending order or `desc` for descending order. + #[serde(skip_serializing_if = "Option::is_none")] + pub order: Option, + /// Evals can be ordered by creation time or last updated time. Use `created_at` for creation time or `updated_at` for last updated time. + #[serde(skip_serializing_if = "Option::is_none")] + pub order_by: Option, +} + +/// Sort order for getting eval runs. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "lowercase")] +pub enum GetEvalRunsOrder { + /// Ascending order + Asc, + /// Descending order + Desc, +} + +/// Status filter for eval runs. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "snake_case")] +pub enum GetEvalRunsStatus { + /// Queued status + Queued, + /// In progress status + InProgress, + /// Completed status + Completed, + /// Canceled status + Canceled, + /// Failed status + Failed, +} + +/// Query parameters for getting eval runs. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "GetEvalRunsQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct GetEvalRunsQuery { + /// Identifier for the last run from the previous pagination request. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, + /// Number of runs to retrieve. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// Sort order for runs by timestamp. Use `asc` for ascending order or `desc` for descending order. Defaults to `asc`. + #[serde(skip_serializing_if = "Option::is_none")] + pub order: Option, + /// Filter runs by status. One of `queued` | `in_progress` | `failed` | `completed` | `canceled`. + #[serde(skip_serializing_if = "Option::is_none")] + pub status: Option, +} + +/// Sort order for getting eval run output items. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "lowercase")] +pub enum GetEvalRunOutputItemsOrder { + /// Ascending order + Asc, + /// Descending order + Desc, +} + +/// Status filter for eval run output items. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "lowercase")] +pub enum GetEvalRunOutputItemsStatus { + /// Failed status + Fail, + /// Pass status + Pass, +} + +/// Query parameters for getting eval run output items. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "GetEvalRunOutputItemsQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct GetEvalRunOutputItemsQuery { + /// Identifier for the last output item from the previous pagination request. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, + /// Number of output items to retrieve. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// Filter output items by status. Use `failed` to filter by failed output items or `pass` to filter by passed output items. + #[serde(skip_serializing_if = "Option::is_none")] + pub status: Option, + /// Sort order for output items by timestamp. Use `asc` for ascending order or `desc` for descending order. Defaults to `asc`. + #[serde(skip_serializing_if = "Option::is_none")] + pub order: Option, +} diff --git a/async-openai/src/types/evals/mod.rs b/async-openai/src/types/evals/mod.rs index 635e168e..4dee2981 100644 --- a/async-openai/src/types/evals/mod.rs +++ b/async-openai/src/types/evals/mod.rs @@ -1,3 +1,5 @@ +mod api; mod eval; +pub use api::*; pub use eval::*; diff --git a/async-openai/src/types/files/api.rs b/async-openai/src/types/files/api.rs new file mode 100644 index 00000000..b3c6b2e3 --- /dev/null +++ b/async-openai/src/types/files/api.rs @@ -0,0 +1,36 @@ +use crate::error::OpenAIError; +use derive_builder::Builder; +use serde::{Deserialize, Serialize}; + +/// Sort order for listing files. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "lowercase")] +pub enum ListFilesOrder { + /// Ascending order + Asc, + /// Descending order + Desc, +} + +/// Query parameters for listing files. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "ListFilesQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct ListFilesQuery { + /// Only return files with the given purpose. + #[serde(skip_serializing_if = "Option::is_none")] + pub purpose: Option, + /// A limit on the number of objects to be returned. Limit can range between 1 and 10,000, and the default is 10,000. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` for descending order. + #[serde(skip_serializing_if = "Option::is_none")] + pub order: Option, + /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, +} + diff --git a/async-openai/src/types/files/mod.rs b/async-openai/src/types/files/mod.rs index 529c201f..add19077 100644 --- a/async-openai/src/types/files/mod.rs +++ b/async-openai/src/types/files/mod.rs @@ -1,3 +1,5 @@ +mod api; mod file; +pub use api::*; pub use file::*; diff --git a/async-openai/src/types/finetuning/api.rs b/async-openai/src/types/finetuning/api.rs new file mode 100644 index 00000000..71c21cb2 --- /dev/null +++ b/async-openai/src/types/finetuning/api.rs @@ -0,0 +1,110 @@ +use crate::error::OpenAIError; +use derive_builder::Builder; +use serde::{Deserialize, Serialize}; + +/// Sort order for listing fine-tuning checkpoint permissions. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "lowercase")] +pub enum ListFineTuningCheckpointPermissionsOrder { + /// Ascending order + Ascending, + /// Descending order + Descending, +} + +/// Query parameters for listing fine-tuning checkpoint permissions. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "ListFineTuningCheckpointPermissionsQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct ListFineTuningCheckpointPermissionsQuery { + /// The ID of the project to get permissions for. + #[serde(skip_serializing_if = "Option::is_none")] + pub project_id: Option, + /// Identifier for the last permission ID from the previous pagination request. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, + /// Number of permissions to retrieve. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// The order in which to retrieve permissions. + #[serde(skip_serializing_if = "Option::is_none")] + pub order: Option, +} + +/// Query parameters for listing fine-tuning jobs. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "ListPaginatedFineTuningJobsQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct ListPaginatedFineTuningJobsQuery { + /// Identifier for the last job from the previous pagination request. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, + /// Number of fine-tuning jobs to retrieve. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// Optional metadata filter. To filter, use the syntax `metadata[k]=v`. Alternatively, set `metadata=null` to indicate no metadata. + #[serde(skip_serializing_if = "Option::is_none")] + pub metadata: Option, +} + +/// Sort order for listing fine-tuning job checkpoints. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "lowercase")] +pub enum ListFineTuningJobCheckpointsOrder { + /// Ascending order + Asc, + /// Descending order + Desc, +} + +/// Query parameters for listing fine-tuning job checkpoints. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "ListFineTuningJobCheckpointsQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct ListFineTuningJobCheckpointsQuery { + /// Identifier for the last checkpoint from the previous pagination request. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, + /// Number of checkpoints to retrieve. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, +} + +/// Sort order for listing fine-tuning events. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "lowercase")] +pub enum ListFineTuningEventsOrder { + /// Ascending order + Asc, + /// Descending order + Desc, +} + +/// Query parameters for listing fine-tuning events. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "ListFineTuningEventsQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct ListFineTuningEventsQuery { + /// Identifier for the last event from the previous pagination request. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, + /// Number of events to retrieve. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// Sort order for events by timestamp. Use `asc` for ascending order or `desc` for descending order. Defaults to `asc`. + #[serde(skip_serializing_if = "Option::is_none")] + pub order: Option, +} + diff --git a/async-openai/src/types/finetuning/mod.rs b/async-openai/src/types/finetuning/mod.rs index 9e4375ee..f049ec82 100644 --- a/async-openai/src/types/finetuning/mod.rs +++ b/async-openai/src/types/finetuning/mod.rs @@ -1,3 +1,5 @@ +mod api; mod fine_tuning; +pub use api::*; pub use fine_tuning::*; diff --git a/async-openai/src/types/responses/api.rs b/async-openai/src/types/responses/api.rs new file mode 100644 index 00000000..4bb3aa93 --- /dev/null +++ b/async-openai/src/types/responses/api.rs @@ -0,0 +1,107 @@ +use crate::error::OpenAIError; +use derive_builder::Builder; +use serde::{Deserialize, Serialize}; + +use super::conversation::{IncludeParam, ListOrder}; + +/// Query parameters for listing conversation items. +#[derive(Clone, Serialize, Default, Debug, Deserialize, Builder, PartialEq)] +#[builder(name = "ListConversationItemsQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct ListConversationItemsQuery { + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// The order to return the input items in. Default is `desc`. + #[serde(skip_serializing_if = "Option::is_none")] + pub order: Option, + /// An item ID to list items after, used in pagination. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, + /// Specify additional output data to include in the model response. + #[serde(skip_serializing_if = "Option::is_none")] + pub include: Option>, +} + +/// Sort order for listing input items. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "lowercase")] +pub enum ListInputItemsOrder { + /// Ascending order + Asc, + /// Descending order + Desc, +} + +/// Query parameters for getting a response. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "GetResponseQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct GetResponseQuery { + /// Additional fields to include in the response. + #[serde(skip_serializing_if = "Option::is_none")] + pub include: Option>, + /// If set to true, the model response data will be streamed to the client as it is generated using server-sent events. + #[serde(skip_serializing_if = "Option::is_none")] + pub stream: Option, + /// The sequence number of the event after which to start streaming. + #[serde(skip_serializing_if = "Option::is_none")] + pub starting_after: Option, + /// When true, stream obfuscation will be enabled. + #[serde(skip_serializing_if = "Option::is_none")] + pub include_obfuscation: Option, +} + +/// Query parameters for listing input items. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "ListInputItemsQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct ListInputItemsQuery { + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// The order to return the input items in. Default is `desc`. + #[serde(skip_serializing_if = "Option::is_none")] + pub order: Option, + /// An item ID to list items after, used in pagination. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, + /// Additional fields to include in the response. + #[serde(skip_serializing_if = "Option::is_none")] + pub include: Option>, +} + +/// Query parameters for getting a conversation item. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "GetConversationItemQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct GetConversationItemQuery { + /// Additional fields to include in the response. + #[serde(skip_serializing_if = "Option::is_none")] + pub include: Option>, +} + +/// Query parameters for creating conversation items. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "CreateConversationItemsQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct CreateConversationItemsQuery { + /// Additional fields to include in the response. + #[serde(skip_serializing_if = "Option::is_none")] + pub include: Option>, +} diff --git a/async-openai/src/types/responses/conversation.rs b/async-openai/src/types/responses/conversation.rs index 5ee65020..94d23545 100644 --- a/async-openai/src/types/responses/conversation.rs +++ b/async-openai/src/types/responses/conversation.rs @@ -213,31 +213,6 @@ pub enum IncludeParam { ReasoningEncryptedContent, } -/// Query parameters for listing conversation items. -#[derive(Clone, Serialize, Default, Debug, Deserialize, Builder, PartialEq)] -#[builder(name = "ListConversationItemsQueryArgs")] -#[builder(pattern = "mutable")] -#[builder(setter(into, strip_option), default)] -#[builder(derive(Debug))] -#[builder(build_fn(error = "OpenAIError"))] -pub struct ListConversationItemsQuery { - /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. - #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, - - /// The order to return the input items in. Default is `desc`. - #[serde(skip_serializing_if = "Option::is_none")] - pub order: Option, - - /// An item ID to list items after, used in pagination. - #[serde(skip_serializing_if = "Option::is_none")] - pub after: Option, - - /// Specify additional output data to include in the model response. - #[serde(skip_serializing_if = "Option::is_none")] - pub include: Option>, -} - /// The order to return items in. #[derive(Clone, Serialize, Debug, Deserialize, PartialEq)] #[serde(rename_all = "lowercase")] diff --git a/async-openai/src/types/responses/mod.rs b/async-openai/src/types/responses/mod.rs index 51f2d733..65003d87 100644 --- a/async-openai/src/types/responses/mod.rs +++ b/async-openai/src/types/responses/mod.rs @@ -1,7 +1,9 @@ +mod api; mod conversation; mod response; mod stream; +pub use api::*; pub use conversation::*; pub use response::*; pub use stream::*; diff --git a/async-openai/src/types/vectorstores/api.rs b/async-openai/src/types/vectorstores/api.rs new file mode 100644 index 00000000..8b62b710 --- /dev/null +++ b/async-openai/src/types/vectorstores/api.rs @@ -0,0 +1,134 @@ +use crate::error::OpenAIError; +use derive_builder::Builder; +use serde::{Deserialize, Serialize}; + +/// Sort order for listing vector stores. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "lowercase")] +pub enum ListVectorStoresOrder { + /// Ascending order + Asc, + /// Descending order + Desc, +} + +/// Query parameters for listing vector stores. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "ListVectorStoresQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct ListVectorStoresQuery { + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` for descending order. + #[serde(skip_serializing_if = "Option::is_none")] + pub order: Option, + /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, + /// A cursor for use in pagination. `before` is an object ID that defines your place in the list. + #[serde(skip_serializing_if = "Option::is_none")] + pub before: Option, +} + +/// Sort order for listing files in vector store batch. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "lowercase")] +pub enum ListFilesInVectorStoreBatchOrder { + /// Ascending order + Asc, + /// Descending order + Desc, +} + +/// Filter by file status for files in vector store batch. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "snake_case")] +pub enum ListFilesInVectorStoreBatchFilter { + /// In progress status + InProgress, + /// Completed status + Completed, + /// Failed status + Failed, + /// Cancelled status + Cancelled, +} + +/// Query parameters for listing files in vector store batch. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "ListFilesInVectorStoreBatchQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct ListFilesInVectorStoreBatchQuery { + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` for descending order. + #[serde(skip_serializing_if = "Option::is_none")] + pub order: Option, + /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, + /// A cursor for use in pagination. `before` is an object ID that defines your place in the list. + #[serde(skip_serializing_if = "Option::is_none")] + pub before: Option, + /// Filter by file status. One of `in_progress`, `completed`, `failed`, `cancelled`. + #[serde(skip_serializing_if = "Option::is_none")] + pub filter: Option, +} + +/// Sort order for listing vector store files. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "lowercase")] +pub enum ListVectorStoreFilesOrder { + /// Ascending order + Asc, + /// Descending order + Desc, +} + +/// Filter by file status for vector store files. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "snake_case")] +pub enum ListVectorStoreFilesFilter { + /// In progress status + InProgress, + /// Completed status + Completed, + /// Failed status + Failed, + /// Cancelled status + Cancelled, +} + +/// Query parameters for listing vector store files. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "ListVectorStoreFilesQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct ListVectorStoreFilesQuery { + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` for descending order. + #[serde(skip_serializing_if = "Option::is_none")] + pub order: Option, + /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, + /// A cursor for use in pagination. `before` is an object ID that defines your place in the list. + #[serde(skip_serializing_if = "Option::is_none")] + pub before: Option, + /// Filter by file status. One of `in_progress`, `completed`, `failed`, `cancelled`. + #[serde(skip_serializing_if = "Option::is_none")] + pub filter: Option, +} + diff --git a/async-openai/src/types/vectorstores/mod.rs b/async-openai/src/types/vectorstores/mod.rs index e38e391f..8dda824f 100644 --- a/async-openai/src/types/vectorstores/mod.rs +++ b/async-openai/src/types/vectorstores/mod.rs @@ -1,3 +1,5 @@ +mod api; mod vector_store; +pub use api::*; pub use vector_store::*; diff --git a/async-openai/src/types/videos/api.rs b/async-openai/src/types/videos/api.rs new file mode 100644 index 00000000..5ef570b1 --- /dev/null +++ b/async-openai/src/types/videos/api.rs @@ -0,0 +1,32 @@ +use crate::error::OpenAIError; +use derive_builder::Builder; +use serde::{Deserialize, Serialize}; + +/// Sort order for listing videos. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "lowercase")] +pub enum ListVideosOrder { + /// Ascending order + Asc, + /// Descending order + Desc, +} + +/// Query parameters for listing videos. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "ListVideosQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct ListVideosQuery { + /// Number of items to retrieve. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// Sort order of results by timestamp. Use `asc` for ascending order or `desc` for descending order. + #[serde(skip_serializing_if = "Option::is_none")] + pub order: Option, + /// Identifier for the last item from the previous pagination request. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, +} diff --git a/async-openai/src/types/videos/mod.rs b/async-openai/src/types/videos/mod.rs index a361cb4e..7bcc8a28 100644 --- a/async-openai/src/types/videos/mod.rs +++ b/async-openai/src/types/videos/mod.rs @@ -1,3 +1,5 @@ +mod api; mod video; +pub use api::*; pub use video::*; From ef312ad3b7977c10772c8657e2b5b810ee86e3a1 Mon Sep 17 00:00:00 2001 From: Himanshu Neema Date: Tue, 18 Nov 2025 12:48:01 -0800 Subject: [PATCH 15/22] updated README --- async-openai/README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/async-openai/README.md b/async-openai/README.md index 823df5d3..e60b7516 100644 --- a/async-openai/README.md +++ b/async-openai/README.md @@ -32,15 +32,16 @@ | **Realtime** | Realtime Calls, Client secrets, Client events, Server events | | **Chat Completions** | Chat Completions, Streaming | | **Assistants** (Beta) | Assistants, Threads, Messages, Runs, Run steps, Streaming | -| **Administration** | Administration, Admin API Keys, Invites, Users, Projects, Project users, Project service accounts, Project API keys, Project rate limits, Audit logs, Usage, Certificates | +| **Administration** | Admin API Keys, Invites, Users, Projects, Project users, Project service accounts, Project API keys, Project rate limits, Audit logs, Usage, Certificates | | **Legacy** | Completions | Features that makes `async-openai` unique: - Bring your own custom types for Request or Response objects. -- SSE streaming on available APIs +- SSE streaming on available APIs. +- Customize query and headers globally or per request. - Requests (except SSE streaming) including form submissions are retried with exponential backoff when [rate limited](https://platform.openai.com/docs/guides/rate-limits). - Ergonomic builder pattern for all request objects. -- Microsoft Azure OpenAI Service (only for APIs matching OpenAI spec) +- Microsoft Azure OpenAI Service (only for APIs matching OpenAI spec). ## Usage From b8a88457e07bdd35a7c363df36ad68e77a25b292 Mon Sep 17 00:00:00 2001 From: Himanshu Neema Date: Tue, 18 Nov 2025 12:50:00 -0800 Subject: [PATCH 16/22] fix example: --- examples/usage/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/usage/src/main.rs b/examples/usage/src/main.rs index a589f16e..b92d0cc5 100644 --- a/examples/usage/src/main.rs +++ b/examples/usage/src/main.rs @@ -3,7 +3,7 @@ use std::time::{SystemTime, UNIX_EPOCH}; use async_openai::{ traits::RequestOptionsBuilder, - types::admin::usage::{UsageQueryParams, UsageResult}, + types::admin::{usage::UsageResult, UsageQueryParams}, Client, }; From 91c7d60492adc5a91ec876be2f96db968ba1806a Mon Sep 17 00:00:00 2001 From: Himanshu Neema Date: Tue, 18 Nov 2025 12:50:09 -0800 Subject: [PATCH 17/22] cargo fmt --- async-openai/src/types/admin/api.rs | 1 - async-openai/src/types/admin/usage.rs | 1 - async-openai/src/types/batches/api.rs | 1 - async-openai/src/types/chatkit/api.rs | 1 - async-openai/src/types/containers/api.rs | 1 - async-openai/src/types/containers/container.rs | 2 -- async-openai/src/types/files/api.rs | 1 - async-openai/src/types/finetuning/api.rs | 1 - async-openai/src/types/vectorstores/api.rs | 1 - 9 files changed, 10 deletions(-) diff --git a/async-openai/src/types/admin/api.rs b/async-openai/src/types/admin/api.rs index ffdbd399..abfd34b5 100644 --- a/async-openai/src/types/admin/api.rs +++ b/async-openai/src/types/admin/api.rs @@ -298,4 +298,3 @@ pub struct GetCertificateQuery { #[serde(skip_serializing_if = "Option::is_none")] pub include: Option>, } - diff --git a/async-openai/src/types/admin/usage.rs b/async-openai/src/types/admin/usage.rs index ef24e7e7..2d1214dd 100644 --- a/async-openai/src/types/admin/usage.rs +++ b/async-openai/src/types/admin/usage.rs @@ -24,7 +24,6 @@ pub enum UsageGroupBy { ServiceTier, } - /// Response structure for organization usage endpoints. #[derive(Debug, Clone, Deserialize)] pub struct UsageResponse { diff --git a/async-openai/src/types/batches/api.rs b/async-openai/src/types/batches/api.rs index bd431383..c6c4bdc6 100644 --- a/async-openai/src/types/batches/api.rs +++ b/async-openai/src/types/batches/api.rs @@ -17,4 +17,3 @@ pub struct ListBatchesQuery { #[serde(skip_serializing_if = "Option::is_none")] pub limit: Option, } - diff --git a/async-openai/src/types/chatkit/api.rs b/async-openai/src/types/chatkit/api.rs index 73195832..717f9313 100644 --- a/async-openai/src/types/chatkit/api.rs +++ b/async-openai/src/types/chatkit/api.rs @@ -68,4 +68,3 @@ pub struct ListChatKitThreadItemsQuery { #[serde(skip_serializing_if = "Option::is_none")] pub before: Option, } - diff --git a/async-openai/src/types/containers/api.rs b/async-openai/src/types/containers/api.rs index a2f9764b..0b48d8e4 100644 --- a/async-openai/src/types/containers/api.rs +++ b/async-openai/src/types/containers/api.rs @@ -59,4 +59,3 @@ pub struct ListContainerFilesQuery { #[serde(skip_serializing_if = "Option::is_none")] pub after: Option, } - diff --git a/async-openai/src/types/containers/container.rs b/async-openai/src/types/containers/container.rs index 5d51ad93..b9e19e7a 100644 --- a/async-openai/src/types/containers/container.rs +++ b/async-openai/src/types/containers/container.rs @@ -83,7 +83,6 @@ pub struct DeleteContainerResponse { pub deleted: bool, } - // Container File types /// The container file object represents a file in a container. @@ -137,4 +136,3 @@ pub struct DeleteContainerFileResponse { pub object: String, pub deleted: bool, } - diff --git a/async-openai/src/types/files/api.rs b/async-openai/src/types/files/api.rs index b3c6b2e3..b5f8df64 100644 --- a/async-openai/src/types/files/api.rs +++ b/async-openai/src/types/files/api.rs @@ -33,4 +33,3 @@ pub struct ListFilesQuery { #[serde(skip_serializing_if = "Option::is_none")] pub after: Option, } - diff --git a/async-openai/src/types/finetuning/api.rs b/async-openai/src/types/finetuning/api.rs index 71c21cb2..737f6c30 100644 --- a/async-openai/src/types/finetuning/api.rs +++ b/async-openai/src/types/finetuning/api.rs @@ -107,4 +107,3 @@ pub struct ListFineTuningEventsQuery { #[serde(skip_serializing_if = "Option::is_none")] pub order: Option, } - diff --git a/async-openai/src/types/vectorstores/api.rs b/async-openai/src/types/vectorstores/api.rs index 8b62b710..7e24a8fb 100644 --- a/async-openai/src/types/vectorstores/api.rs +++ b/async-openai/src/types/vectorstores/api.rs @@ -131,4 +131,3 @@ pub struct ListVectorStoreFilesQuery { #[serde(skip_serializing_if = "Option::is_none")] pub filter: Option, } - From 3dc59f6463a9da3725e90b1058748925286dfa64 Mon Sep 17 00:00:00 2001 From: Himanshu Neema Date: Tue, 18 Nov 2025 13:01:53 -0800 Subject: [PATCH 18/22] namespaced query param types --- async-openai/src/types/admin/api.rs | 300 ------------------ async-openai/src/types/admin/api_keys.rs | 29 ++ async-openai/src/types/admin/audit_logs.rs | 39 +++ async-openai/src/types/admin/certificates.rs | 71 +++++ async-openai/src/types/admin/invites.rs | 16 + async-openai/src/types/admin/mod.rs | 3 - .../src/types/admin/project_api_keys.rs | 18 ++ .../src/types/admin/project_rate_limits.rs | 20 +- .../types/admin/project_service_accounts.rs | 18 ++ async-openai/src/types/admin/project_users.rs | 16 + async-openai/src/types/admin/projects.rs | 19 ++ async-openai/src/types/admin/usage.rs | 37 +++ async-openai/src/types/admin/users.rs | 19 ++ 13 files changed, 301 insertions(+), 304 deletions(-) delete mode 100644 async-openai/src/types/admin/api.rs diff --git a/async-openai/src/types/admin/api.rs b/async-openai/src/types/admin/api.rs deleted file mode 100644 index abfd34b5..00000000 --- a/async-openai/src/types/admin/api.rs +++ /dev/null @@ -1,300 +0,0 @@ -use crate::error::OpenAIError; -use derive_builder::Builder; -use serde::{Deserialize, Serialize}; - -use super::usage::{UsageBucketWidth, UsageGroupBy}; - -/// Sort order for listing admin API keys. -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] -#[serde(rename_all = "lowercase")] -pub enum ListAdminApiKeysOrder { - /// Ascending order - Asc, - /// Descending order - Desc, -} - -/// Query parameters for listing admin API keys. -#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] -#[builder(name = "ListAdminApiKeysQueryArgs")] -#[builder(pattern = "mutable")] -#[builder(setter(into, strip_option), default)] -#[builder(derive(Debug))] -#[builder(build_fn(error = "OpenAIError"))] -pub struct ListAdminApiKeysQuery { - /// Return keys with IDs that come after this ID in the pagination order. - #[serde(skip_serializing_if = "Option::is_none")] - pub after: Option, - /// Order results by creation time, ascending or descending. - #[serde(skip_serializing_if = "Option::is_none")] - pub order: Option, - /// Maximum number of keys to return. - #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, -} - -/// Query parameters for listing audit logs. -#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] -#[builder(name = "ListAuditLogsQueryArgs")] -#[builder(pattern = "mutable")] -#[builder(setter(into, strip_option), default)] -#[builder(derive(Debug))] -#[builder(build_fn(error = "OpenAIError"))] -pub struct ListAuditLogsQuery { - /// Return only events whose `effective_at` (Unix seconds) is in this range. - #[serde(skip_serializing_if = "Option::is_none")] - pub effective_at: Option, - /// Return only events for these projects. - #[serde(skip_serializing_if = "Option::is_none")] - pub project_ids: Option>, - /// Return only events with a `type` in one of these values. - #[serde(skip_serializing_if = "Option::is_none")] - pub event_types: Option>, - /// Return only events performed by these actors. - #[serde(skip_serializing_if = "Option::is_none")] - pub actor_ids: Option>, - /// Return only events performed by users with these emails. - #[serde(skip_serializing_if = "Option::is_none")] - pub actor_emails: Option>, - /// Return only events performed on these targets. - #[serde(skip_serializing_if = "Option::is_none")] - pub resource_ids: Option>, - /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. - #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, - /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. - #[serde(skip_serializing_if = "Option::is_none")] - pub after: Option, - /// A cursor for use in pagination. `before` is an object ID that defines your place in the list. - #[serde(skip_serializing_if = "Option::is_none")] - pub before: Option, -} - -/// Sort order for listing organization certificates. -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] -#[serde(rename_all = "lowercase")] -pub enum ListOrganizationCertificatesOrder { - /// Ascending order - Asc, - /// Descending order - Desc, -} - -/// Query parameters for listing organization certificates. -#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] -#[builder(name = "ListOrganizationCertificatesQueryArgs")] -#[builder(pattern = "mutable")] -#[builder(setter(into, strip_option), default)] -#[builder(derive(Debug))] -#[builder(build_fn(error = "OpenAIError"))] -pub struct ListOrganizationCertificatesQuery { - /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. - #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, - /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. - #[serde(skip_serializing_if = "Option::is_none")] - pub after: Option, - /// Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` for descending order. - #[serde(skip_serializing_if = "Option::is_none")] - pub order: Option, -} - -/// Query parameters for listing invites. -#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] -#[builder(name = "ListInvitesQueryArgs")] -#[builder(pattern = "mutable")] -#[builder(setter(into, strip_option), default)] -#[builder(derive(Debug))] -#[builder(build_fn(error = "OpenAIError"))] -pub struct ListInvitesQuery { - /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. - #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, - /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. - #[serde(skip_serializing_if = "Option::is_none")] - pub after: Option, -} - -/// Query parameters for listing projects. -#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] -#[builder(name = "ListProjectsQueryArgs")] -#[builder(pattern = "mutable")] -#[builder(setter(into, strip_option), default)] -#[builder(derive(Debug))] -#[builder(build_fn(error = "OpenAIError"))] -pub struct ListProjectsQuery { - /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. - #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, - /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. - #[serde(skip_serializing_if = "Option::is_none")] - pub after: Option, - /// If `true` returns all projects including those that have been `archived`. Archived projects are not included by default. - #[serde(skip_serializing_if = "Option::is_none")] - pub include_archived: Option, -} - -/// Query parameters for listing project API keys. -#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] -#[builder(name = "ListProjectApiKeysQueryArgs")] -#[builder(pattern = "mutable")] -#[builder(setter(into, strip_option), default)] -#[builder(derive(Debug))] -#[builder(build_fn(error = "OpenAIError"))] -pub struct ListProjectApiKeysQuery { - /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. - #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, - /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. - #[serde(skip_serializing_if = "Option::is_none")] - pub after: Option, -} - -/// Sort order for listing project certificates. -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] -#[serde(rename_all = "lowercase")] -pub enum ListProjectCertificatesOrder { - /// Ascending order - Asc, - /// Descending order - Desc, -} - -/// Query parameters for listing project certificates. -#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] -#[builder(name = "ListProjectCertificatesQueryArgs")] -#[builder(pattern = "mutable")] -#[builder(setter(into, strip_option), default)] -#[builder(derive(Debug))] -#[builder(build_fn(error = "OpenAIError"))] -pub struct ListProjectCertificatesQuery { - /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. - #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, - /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. - #[serde(skip_serializing_if = "Option::is_none")] - pub after: Option, - /// Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` for descending order. - #[serde(skip_serializing_if = "Option::is_none")] - pub order: Option, -} - -/// Query parameters for listing project rate limits. -#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] -#[builder(name = "ListProjectRateLimitsQueryArgs")] -#[builder(pattern = "mutable")] -#[builder(setter(into, strip_option), default)] -#[builder(derive(Debug))] -#[builder(build_fn(error = "OpenAIError"))] -pub struct ListProjectRateLimitsQuery { - /// A limit on the number of objects to be returned. The default is 100. - #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, - /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. - #[serde(skip_serializing_if = "Option::is_none")] - pub after: Option, - /// A cursor for use in pagination. `before` is an object ID that defines your place in the list. - #[serde(skip_serializing_if = "Option::is_none")] - pub before: Option, -} - -/// Query parameters for listing project service accounts. -#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] -#[builder(name = "ListProjectServiceAccountsQueryArgs")] -#[builder(pattern = "mutable")] -#[builder(setter(into, strip_option), default)] -#[builder(derive(Debug))] -#[builder(build_fn(error = "OpenAIError"))] -pub struct ListProjectServiceAccountsQuery { - /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. - #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, - /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. - #[serde(skip_serializing_if = "Option::is_none")] - pub after: Option, -} - -/// Query parameters for listing project users. -#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] -#[builder(name = "ListProjectUsersQueryArgs")] -#[builder(pattern = "mutable")] -#[builder(setter(into, strip_option), default)] -#[builder(derive(Debug))] -#[builder(build_fn(error = "OpenAIError"))] -pub struct ListProjectUsersQuery { - /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. - #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, - /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. - #[serde(skip_serializing_if = "Option::is_none")] - pub after: Option, -} - -/// Query parameters for listing users. -#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] -#[builder(name = "ListUsersQueryArgs")] -#[builder(pattern = "mutable")] -#[builder(setter(into, strip_option), default)] -#[builder(derive(Debug))] -#[builder(build_fn(error = "OpenAIError"))] -pub struct ListUsersQuery { - /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. - #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, - /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. - #[serde(skip_serializing_if = "Option::is_none")] - pub after: Option, - /// Filter by the email address of users. - #[serde(skip_serializing_if = "Option::is_none")] - pub emails: Option>, -} - -/// Query parameters for organization usage endpoints. -#[derive(Debug, Clone, Serialize, Default)] -pub struct UsageQueryParams { - /// Start time (Unix seconds) of the query time range, inclusive. - pub start_time: u64, - /// End time (Unix seconds) of the query time range, exclusive. - #[serde(skip_serializing_if = "Option::is_none")] - pub end_time: Option, - /// Width of each time bucket in response. Currently `1m`, `1h` and `1d` are supported, default to `1d`. - #[serde(skip_serializing_if = "Option::is_none")] - pub bucket_width: Option, - /// Return only usage for these projects. - #[serde(skip_serializing_if = "Option::is_none")] - pub project_ids: Option>, - /// Return only usage for these users. - #[serde(skip_serializing_if = "Option::is_none")] - pub user_ids: Option>, - /// Return only usage for these API keys. - #[serde(skip_serializing_if = "Option::is_none")] - pub api_key_ids: Option>, - /// Return only usage for these models. - #[serde(skip_serializing_if = "Option::is_none")] - pub models: Option>, - /// If `true`, return batch jobs only. If `false`, return non-batch jobs only. By default, return both. - #[serde(skip_serializing_if = "Option::is_none")] - pub batch: Option, - /// Group the usage data by the specified fields. - #[serde(skip_serializing_if = "Option::is_none")] - pub group_by: Option>, - /// Specifies the number of buckets to return. - #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, - /// A cursor for use in pagination. Corresponding to the `next_page` field from the previous response. - #[serde(skip_serializing_if = "Option::is_none")] - pub page: Option, -} - -/// Query parameters for getting a certificate. -#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] -#[builder(name = "GetCertificateQueryArgs")] -#[builder(pattern = "mutable")] -#[builder(setter(into, strip_option), default)] -#[builder(derive(Debug))] -#[builder(build_fn(error = "OpenAIError"))] -pub struct GetCertificateQuery { - /// A list of additional fields to include in the response. Currently the only supported value is `content` to fetch the PEM content of the certificate. - #[serde(skip_serializing_if = "Option::is_none")] - pub include: Option>, -} diff --git a/async-openai/src/types/admin/api_keys.rs b/async-openai/src/types/admin/api_keys.rs index 0be8723f..3578591c 100644 --- a/async-openai/src/types/admin/api_keys.rs +++ b/async-openai/src/types/admin/api_keys.rs @@ -2,6 +2,35 @@ use crate::types::OpenAIError; use derive_builder::Builder; use serde::{Deserialize, Serialize}; +/// Sort order for listing admin API keys. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "lowercase")] +pub enum ListAdminApiKeysOrder { + /// Ascending order + Asc, + /// Descending order + Desc, +} + +/// Query parameters for listing admin API keys. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "ListAdminApiKeysQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct ListAdminApiKeysQuery { + /// Return keys with IDs that come after this ID in the pagination order. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, + /// Order results by creation time, ascending or descending. + #[serde(skip_serializing_if = "Option::is_none")] + pub order: Option, + /// Maximum number of keys to return. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, +} + /// Represents an individual Admin API key in an org. #[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] pub struct AdminApiKey { diff --git a/async-openai/src/types/admin/audit_logs.rs b/async-openai/src/types/admin/audit_logs.rs index 1d3b137e..05bfa4d8 100644 --- a/async-openai/src/types/admin/audit_logs.rs +++ b/async-openai/src/types/admin/audit_logs.rs @@ -1,5 +1,44 @@ +use crate::error::OpenAIError; +use derive_builder::Builder; use serde::{Deserialize, Serialize}; +/// Query parameters for listing audit logs. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "ListAuditLogsQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct ListAuditLogsQuery { + /// Return only events whose `effective_at` (Unix seconds) is in this range. + #[serde(skip_serializing_if = "Option::is_none")] + pub effective_at: Option, + /// Return only events for these projects. + #[serde(skip_serializing_if = "Option::is_none")] + pub project_ids: Option>, + /// Return only events with a `type` in one of these values. + #[serde(skip_serializing_if = "Option::is_none")] + pub event_types: Option>, + /// Return only events performed by these actors. + #[serde(skip_serializing_if = "Option::is_none")] + pub actor_ids: Option>, + /// Return only events performed by users with these emails. + #[serde(skip_serializing_if = "Option::is_none")] + pub actor_emails: Option>, + /// Return only events performed on these targets. + #[serde(skip_serializing_if = "Option::is_none")] + pub resource_ids: Option>, + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, + /// A cursor for use in pagination. `before` is an object ID that defines your place in the list. + #[serde(skip_serializing_if = "Option::is_none")] + pub before: Option, +} + /// The event type. #[derive(Debug, Serialize, Deserialize)] pub enum AuditLogEventType { diff --git a/async-openai/src/types/admin/certificates.rs b/async-openai/src/types/admin/certificates.rs index e10774f0..2370f00b 100644 --- a/async-openai/src/types/admin/certificates.rs +++ b/async-openai/src/types/admin/certificates.rs @@ -2,6 +2,77 @@ use crate::error::OpenAIError; use derive_builder::Builder; use serde::{Deserialize, Serialize}; +/// Sort order for listing organization certificates. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "lowercase")] +pub enum ListOrganizationCertificatesOrder { + /// Ascending order + Asc, + /// Descending order + Desc, +} + +/// Query parameters for listing organization certificates. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "ListOrganizationCertificatesQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct ListOrganizationCertificatesQuery { + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, + /// Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` for descending order. + #[serde(skip_serializing_if = "Option::is_none")] + pub order: Option, +} + +/// Sort order for listing project certificates. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "lowercase")] +pub enum ListProjectCertificatesOrder { + /// Ascending order + Asc, + /// Descending order + Desc, +} + +/// Query parameters for listing project certificates. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "ListProjectCertificatesQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct ListProjectCertificatesQuery { + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, + /// Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` for descending order. + #[serde(skip_serializing_if = "Option::is_none")] + pub order: Option, +} + +/// Query parameters for getting a certificate. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "GetCertificateQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct GetCertificateQuery { + /// A list of additional fields to include in the response. Currently the only supported value is `content` to fetch the PEM content of the certificate. + #[serde(skip_serializing_if = "Option::is_none")] + pub include: Option>, +} + /// Represents an individual certificate uploaded to the organization. #[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] pub struct Certificate { diff --git a/async-openai/src/types/admin/invites.rs b/async-openai/src/types/admin/invites.rs index a327af83..1db16692 100644 --- a/async-openai/src/types/admin/invites.rs +++ b/async-openai/src/types/admin/invites.rs @@ -3,6 +3,22 @@ use crate::types::OrganizationRole; use derive_builder::Builder; use serde::{Deserialize, Serialize}; +/// Query parameters for listing invites. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "ListInvitesQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct ListInvitesQuery { + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, +} + #[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)] #[serde(rename_all = "lowercase")] pub enum InviteStatus { diff --git a/async-openai/src/types/admin/mod.rs b/async-openai/src/types/admin/mod.rs index 99977db4..396f3ca5 100644 --- a/async-openai/src/types/admin/mod.rs +++ b/async-openai/src/types/admin/mod.rs @@ -1,6 +1,5 @@ //! Admin-related types for organization management APIs. -pub mod api; pub mod api_keys; pub mod audit_logs; pub mod certificates; @@ -12,5 +11,3 @@ pub mod project_users; pub mod projects; pub mod usage; pub mod users; - -pub use api::*; diff --git a/async-openai/src/types/admin/project_api_keys.rs b/async-openai/src/types/admin/project_api_keys.rs index 2d339d7b..3bf0875a 100644 --- a/async-openai/src/types/admin/project_api_keys.rs +++ b/async-openai/src/types/admin/project_api_keys.rs @@ -1,8 +1,26 @@ +use crate::error::OpenAIError; +use derive_builder::Builder; use serde::{Deserialize, Serialize}; use crate::types::admin::project_service_accounts::ProjectServiceAccount; use crate::types::admin::project_users::ProjectUser; +/// Query parameters for listing project API keys. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "ListProjectApiKeysQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct ListProjectApiKeysQuery { + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, +} + /// Represents an individual API key in a project. #[derive(Debug, Serialize, Deserialize)] pub struct ProjectApiKey { diff --git a/async-openai/src/types/admin/project_rate_limits.rs b/async-openai/src/types/admin/project_rate_limits.rs index fdadb03b..22ca1e86 100644 --- a/async-openai/src/types/admin/project_rate_limits.rs +++ b/async-openai/src/types/admin/project_rate_limits.rs @@ -1,7 +1,25 @@ +use crate::error::OpenAIError; use derive_builder::Builder; use serde::{Deserialize, Serialize}; -use crate::types::OpenAIError; +/// Query parameters for listing project rate limits. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "ListProjectRateLimitsQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct ListProjectRateLimitsQuery { + /// A limit on the number of objects to be returned. The default is 100. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, + /// A cursor for use in pagination. `before` is an object ID that defines your place in the list. + #[serde(skip_serializing_if = "Option::is_none")] + pub before: Option, +} /// Represents a project rate limit config. #[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] diff --git a/async-openai/src/types/admin/project_service_accounts.rs b/async-openai/src/types/admin/project_service_accounts.rs index 1ec1ae6a..a1d09f9b 100644 --- a/async-openai/src/types/admin/project_service_accounts.rs +++ b/async-openai/src/types/admin/project_service_accounts.rs @@ -1,7 +1,25 @@ +use crate::error::OpenAIError; +use derive_builder::Builder; use serde::{Deserialize, Serialize}; use crate::types::admin::project_users::ProjectUserRole; +/// Query parameters for listing project service accounts. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "ListProjectServiceAccountsQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct ListProjectServiceAccountsQuery { + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, +} + /// Represents an individual service account in a project. #[derive(Debug, Serialize, Deserialize)] pub struct ProjectServiceAccount { diff --git a/async-openai/src/types/admin/project_users.rs b/async-openai/src/types/admin/project_users.rs index 51a88199..585b0e1b 100644 --- a/async-openai/src/types/admin/project_users.rs +++ b/async-openai/src/types/admin/project_users.rs @@ -2,6 +2,22 @@ use crate::types::OpenAIError; use derive_builder::Builder; use serde::{Deserialize, Serialize}; +/// Query parameters for listing project users. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "ListProjectUsersQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct ListProjectUsersQuery { + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, +} + /// Represents an individual user in a project. #[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] pub struct ProjectUser { diff --git a/async-openai/src/types/admin/projects.rs b/async-openai/src/types/admin/projects.rs index 20fdc309..1a8189d7 100644 --- a/async-openai/src/types/admin/projects.rs +++ b/async-openai/src/types/admin/projects.rs @@ -2,6 +2,25 @@ use crate::types::OpenAIError; use derive_builder::Builder; use serde::{Deserialize, Serialize}; +/// Query parameters for listing projects. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "ListProjectsQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct ListProjectsQuery { + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, + /// If `true` returns all projects including those that have been `archived`. Archived projects are not included by default. + #[serde(skip_serializing_if = "Option::is_none")] + pub include_archived: Option, +} + /// `active` or `archived` #[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)] #[serde(rename_all = "lowercase")] diff --git a/async-openai/src/types/admin/usage.rs b/async-openai/src/types/admin/usage.rs index 2d1214dd..2b2f16df 100644 --- a/async-openai/src/types/admin/usage.rs +++ b/async-openai/src/types/admin/usage.rs @@ -1,5 +1,42 @@ use serde::{Deserialize, Serialize}; +/// Query parameters for organization usage endpoints. +#[derive(Debug, Clone, Serialize, Default)] +pub struct UsageQueryParams { + /// Start time (Unix seconds) of the query time range, inclusive. + pub start_time: u64, + /// End time (Unix seconds) of the query time range, exclusive. + #[serde(skip_serializing_if = "Option::is_none")] + pub end_time: Option, + /// Width of each time bucket in response. Currently `1m`, `1h` and `1d` are supported, default to `1d`. + #[serde(skip_serializing_if = "Option::is_none")] + pub bucket_width: Option, + /// Return only usage for these projects. + #[serde(skip_serializing_if = "Option::is_none")] + pub project_ids: Option>, + /// Return only usage for these users. + #[serde(skip_serializing_if = "Option::is_none")] + pub user_ids: Option>, + /// Return only usage for these API keys. + #[serde(skip_serializing_if = "Option::is_none")] + pub api_key_ids: Option>, + /// Return only usage for these models. + #[serde(skip_serializing_if = "Option::is_none")] + pub models: Option>, + /// If `true`, return batch jobs only. If `false`, return non-batch jobs only. By default, return both. + #[serde(skip_serializing_if = "Option::is_none")] + pub batch: Option, + /// Group the usage data by the specified fields. + #[serde(skip_serializing_if = "Option::is_none")] + pub group_by: Option>, + /// Specifies the number of buckets to return. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// A cursor for use in pagination. Corresponding to the `next_page` field from the previous response. + #[serde(skip_serializing_if = "Option::is_none")] + pub page: Option, +} + /// Width of each time bucket in response. #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(rename_all = "lowercase")] diff --git a/async-openai/src/types/admin/users.rs b/async-openai/src/types/admin/users.rs index 8ed29112..32e3b1a0 100644 --- a/async-openai/src/types/admin/users.rs +++ b/async-openai/src/types/admin/users.rs @@ -3,6 +3,25 @@ use crate::types::OrganizationRole; use derive_builder::Builder; use serde::{Deserialize, Serialize}; +/// Query parameters for listing users. +#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)] +#[builder(name = "ListUsersQueryArgs")] +#[builder(pattern = "mutable")] +#[builder(setter(into, strip_option), default)] +#[builder(derive(Debug))] +#[builder(build_fn(error = "OpenAIError"))] +pub struct ListUsersQuery { + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, + /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. + #[serde(skip_serializing_if = "Option::is_none")] + pub after: Option, + /// Filter by the email address of users. + #[serde(skip_serializing_if = "Option::is_none")] + pub emails: Option>, +} + /// Represents an individual `user` within an organization. #[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] pub struct User { From 035d413cbfd3c8ba9204b7ba852f92a5734b3132 Mon Sep 17 00:00:00 2001 From: Himanshu Neema Date: Tue, 18 Nov 2025 13:01:59 -0800 Subject: [PATCH 19/22] fix example --- examples/usage/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/usage/src/main.rs b/examples/usage/src/main.rs index b92d0cc5..a589f16e 100644 --- a/examples/usage/src/main.rs +++ b/examples/usage/src/main.rs @@ -3,7 +3,7 @@ use std::time::{SystemTime, UNIX_EPOCH}; use async_openai::{ traits::RequestOptionsBuilder, - types::admin::{usage::UsageResult, UsageQueryParams}, + types::admin::usage::{UsageQueryParams, UsageResult}, Client, }; From 6cd66a532bbdc6f0ea82123b53d697750463c08e Mon Sep 17 00:00:00 2001 From: Himanshu Neema Date: Tue, 18 Nov 2025 13:10:34 -0800 Subject: [PATCH 20/22] update --- async-openai/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/async-openai/README.md b/async-openai/README.md index e60b7516..3ba6e28e 100644 --- a/async-openai/README.md +++ b/async-openai/README.md @@ -38,7 +38,7 @@ Features that makes `async-openai` unique: - Bring your own custom types for Request or Response objects. - SSE streaming on available APIs. -- Customize query and headers globally or per request. +- Customize query and headers per request, customize headers globally. - Requests (except SSE streaming) including form submissions are retried with exponential backoff when [rate limited](https://platform.openai.com/docs/guides/rate-limits). - Ergonomic builder pattern for all request objects. - Microsoft Azure OpenAI Service (only for APIs matching OpenAI spec). From 83eb4091687b648a6da0815c0d4b7bbc3d2f7758 Mon Sep 17 00:00:00 2001 From: Himanshu Neema Date: Tue, 18 Nov 2025 13:18:39 -0800 Subject: [PATCH 21/22] fix link --- async-openai/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/async-openai/README.md b/async-openai/README.md index 3ba6e28e..3a266ba8 100644 --- a/async-openai/README.md +++ b/async-openai/README.md @@ -14,7 +14,7 @@
-Logo created by this repo itself +Logo created by this repo itself
## Overview From b517c5b11b3b4153a3b9116fa3bd7916b3f4ca05 Mon Sep 17 00:00:00 2001 From: Himanshu Neema Date: Tue, 18 Nov 2025 13:22:17 -0800 Subject: [PATCH 22/22] only initialize request options vector when needed --- async-openai/src/request_options.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/async-openai/src/request_options.rs b/async-openai/src/request_options.rs index e9a3530c..91ce7669 100644 --- a/async-openai/src/request_options.rs +++ b/async-openai/src/request_options.rs @@ -6,14 +6,14 @@ use crate::{config::OPENAI_API_BASE, error::OpenAIError}; #[derive(Clone, Debug, Default)] pub struct RequestOptions { - query: Vec<(String, String)>, + query: Option>, headers: Option, } impl RequestOptions { pub(crate) fn new() -> Self { Self { - query: Vec::new(), + query: None, headers: None, } } @@ -66,15 +66,16 @@ impl RequestOptions { } // Extract query pairs from the URL and append to our vec + let query = self.query.get_or_insert_with(Vec::new); for (key, value) in url.query_pairs() { - self.query.push((key.to_string(), value.to_string())); + query.push((key.to_string(), value.to_string())); } Ok(()) } pub(crate) fn query(&self) -> &[(String, String)] { - &self.query + self.query.as_deref().unwrap_or(&[]) } pub(crate) fn headers(&self) -> Option<&HeaderMap> {