Skip to content

Commit dd51463

Browse files
committed
feat: RequestOptions
1 parent 6fdf15c commit dd51463

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+868
-270
lines changed

async-openai/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ derive_builder = "0.20.2"
5050
secrecy = { version = "0.10.3", features = ["serde"] }
5151
bytes = "1.9.0"
5252
eventsource-stream = "0.2.3"
53+
serde_urlencoded = "0.7.1"
5354
tokio-tungstenite = { version = "0.26.1", optional = true, default-features = false }
5455
hmac = { version = "0.12", optional = true, default-features = false}
5556
sha2 = { version = "0.10", optional = true, default-features = false }

async-openai/src/admin_api_keys.rs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,23 @@ use crate::{
66
types::admin::api_keys::{
77
AdminApiKey, AdminApiKeyDeleteResponse, ApiKeyList, CreateAdminApiKeyRequest,
88
},
9-
Client,
9+
Client, RequestOptions,
1010
};
1111

1212
/// Admin API keys enable Organization Owners to programmatically manage various aspects of their
1313
/// organization, including users, projects, and API keys. These keys provide administrative capabilities,
1414
/// allowing you to automate organization management tasks.
1515
pub struct AdminAPIKeys<'c, C: Config> {
1616
client: &'c Client<C>,
17+
pub(crate) request_options: RequestOptions,
1718
}
1819

1920
impl<'c, C: Config> AdminAPIKeys<'c, C> {
2021
pub fn new(client: &'c Client<C>) -> Self {
21-
Self { client }
22+
Self {
23+
client,
24+
request_options: RequestOptions::new(),
25+
}
2226
}
2327

2428
/// List all organization and project API keys.
@@ -28,7 +32,11 @@ impl<'c, C: Config> AdminAPIKeys<'c, C> {
2832
Q: Serialize + ?Sized,
2933
{
3034
self.client
31-
.get_with_query("/organization/admin_api_keys", &query)
35+
.get_with_query(
36+
"/organization/admin_api_keys",
37+
&query,
38+
&self.request_options,
39+
)
3240
.await
3341
}
3442

@@ -38,23 +46,33 @@ impl<'c, C: Config> AdminAPIKeys<'c, C> {
3846
request: CreateAdminApiKeyRequest,
3947
) -> Result<AdminApiKey, OpenAIError> {
4048
self.client
41-
.post("/organization/admin_api_keys", request)
49+
.post(
50+
"/organization/admin_api_keys",
51+
request,
52+
&self.request_options,
53+
)
4254
.await
4355
}
4456

4557
/// Retrieve a single organization API key.
4658
#[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
4759
pub async fn retrieve(&self, key_id: &str) -> Result<AdminApiKey, OpenAIError> {
4860
self.client
49-
.get(format!("/organization/admin_api_keys/{key_id}").as_str())
61+
.get(
62+
format!("/organization/admin_api_keys/{key_id}").as_str(),
63+
&self.request_options,
64+
)
5065
.await
5166
}
5267

5368
/// Delete an organization admin API key.
5469
#[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
5570
pub async fn delete(&self, key_id: &str) -> Result<AdminApiKeyDeleteResponse, OpenAIError> {
5671
self.client
57-
.delete(format!("/organization/admin_api_keys/{key_id}").as_str())
72+
.delete(
73+
format!("/organization/admin_api_keys/{key_id}").as_str(),
74+
&self.request_options,
75+
)
5876
.await
5977
}
6078
}

async-openai/src/assistants.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,23 @@ use crate::{
77
AssistantObject, CreateAssistantRequest, DeleteAssistantResponse, ListAssistantsResponse,
88
ModifyAssistantRequest,
99
},
10-
Client,
10+
Client, RequestOptions,
1111
};
1212

1313
/// Build assistants that can call models and use tools to perform tasks.
1414
///
1515
/// [Get started with the Assistants API](https://platform.openai.com/docs/assistants)
1616
pub struct Assistants<'c, C: Config> {
1717
client: &'c Client<C>,
18+
pub(crate) request_options: RequestOptions,
1819
}
1920

2021
impl<'c, C: Config> Assistants<'c, C> {
2122
pub fn new(client: &'c Client<C>) -> Self {
22-
Self { client }
23+
Self {
24+
client,
25+
request_options: RequestOptions::new(),
26+
}
2327
}
2428

2529
/// Create an assistant with a model and instructions.
@@ -28,14 +32,14 @@ impl<'c, C: Config> Assistants<'c, C> {
2832
&self,
2933
request: CreateAssistantRequest,
3034
) -> Result<AssistantObject, OpenAIError> {
31-
self.client.post("/assistants", request).await
35+
self.client.post("/assistants", request, &self.request_options).await
3236
}
3337

3438
/// Retrieves an assistant.
3539
#[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
3640
pub async fn retrieve(&self, assistant_id: &str) -> Result<AssistantObject, OpenAIError> {
3741
self.client
38-
.get(&format!("/assistants/{assistant_id}"))
42+
.get(&format!("/assistants/{assistant_id}"), &self.request_options)
3943
.await
4044
}
4145

@@ -47,15 +51,15 @@ impl<'c, C: Config> Assistants<'c, C> {
4751
request: ModifyAssistantRequest,
4852
) -> Result<AssistantObject, OpenAIError> {
4953
self.client
50-
.post(&format!("/assistants/{assistant_id}"), request)
54+
.post(&format!("/assistants/{assistant_id}"), request, &self.request_options)
5155
.await
5256
}
5357

5458
/// Delete an assistant.
5559
#[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
5660
pub async fn delete(&self, assistant_id: &str) -> Result<DeleteAssistantResponse, OpenAIError> {
5761
self.client
58-
.delete(&format!("/assistants/{assistant_id}"))
62+
.delete(&format!("/assistants/{assistant_id}"), &self.request_options)
5963
.await
6064
}
6165

@@ -65,6 +69,6 @@ impl<'c, C: Config> Assistants<'c, C> {
6569
where
6670
Q: Serialize + ?Sized,
6771
{
68-
self.client.get_with_query("/assistants", &query).await
72+
self.client.get_with_query("/assistants", &query, &self.request_options).await
6973
}
7074
}

async-openai/src/audio.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
use crate::{config::Config, Client, Speech, Transcriptions, Translations};
1+
use crate::{config::Config, Client, RequestOptions, Speech, Transcriptions, Translations};
22

33
/// Turn audio into text or text into audio.
44
/// Related guide: [Speech to text](https://platform.openai.com/docs/guides/speech-to-text)
55
pub struct Audio<'c, C: Config> {
66
client: &'c Client<C>,
7+
pub(crate) request_options: RequestOptions,
78
}
89

910
impl<'c, C: Config> Audio<'c, C> {
1011
pub fn new(client: &'c Client<C>) -> Self {
11-
Self { client }
12+
Self {
13+
client,
14+
request_options: RequestOptions::new(),
15+
}
1216
}
1317

1418
/// APIs in Speech group.

async-openai/src/audit_logs.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
use serde::Serialize;
22

33
use crate::{
4-
config::Config, error::OpenAIError, types::admin::audit_logs::ListAuditLogsResponse, Client,
4+
config::Config, error::OpenAIError, types::admin::audit_logs::ListAuditLogsResponse, Client, RequestOptions,
55
};
66

77
/// Logs of user actions and configuration changes within this organization.
88
/// To log events, you must activate logging in the [Organization Settings](https://platform.openai.com/settings/organization/general).
99
/// Once activated, for security reasons, logging cannot be deactivated.
1010
pub struct AuditLogs<'c, C: Config> {
1111
client: &'c Client<C>,
12+
pub(crate) request_options: RequestOptions,
1213
}
1314

1415
impl<'c, C: Config> AuditLogs<'c, C> {
1516
pub fn new(client: &'c Client<C>) -> Self {
16-
Self { client }
17+
Self {
18+
client,
19+
request_options: RequestOptions::new(),
20+
}
1721
}
1822

1923
/// List user actions and configuration changes within this organization.
@@ -23,7 +27,7 @@ impl<'c, C: Config> AuditLogs<'c, C> {
2327
Q: Serialize + ?Sized,
2428
{
2529
self.client
26-
.get_with_query("/organization/audit_logs", &query)
30+
.get_with_query("/organization/audit_logs", &query, &self.request_options)
2731
.await
2832
}
2933
}

async-openai/src/batches.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,29 @@ use crate::{
44
config::Config,
55
error::OpenAIError,
66
types::batches::{Batch, BatchRequest, ListBatchesResponse},
7-
Client,
7+
Client, RequestOptions,
88
};
99

1010
/// Create large batches of API requests for asynchronous processing. The Batch API returns completions within 24 hours for a 50% discount.
1111
///
1212
/// Related guide: [Batch](https://platform.openai.com/docs/guides/batch)
1313
pub struct Batches<'c, C: Config> {
1414
client: &'c Client<C>,
15+
pub(crate) request_options: RequestOptions,
1516
}
1617

1718
impl<'c, C: Config> Batches<'c, C> {
1819
pub fn new(client: &'c Client<C>) -> Self {
19-
Self { client }
20+
Self {
21+
client,
22+
request_options: RequestOptions::new(),
23+
}
2024
}
2125

2226
/// Creates and executes a batch from an uploaded file of requests
2327
#[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
2428
pub async fn create(&self, request: BatchRequest) -> Result<Batch, OpenAIError> {
25-
self.client.post("/batches", request).await
29+
self.client.post("/batches", request, &self.request_options).await
2630
}
2731

2832
/// List your organization's batches.
@@ -31,13 +35,13 @@ impl<'c, C: Config> Batches<'c, C> {
3135
where
3236
Q: Serialize + ?Sized,
3337
{
34-
self.client.get_with_query("/batches", &query).await
38+
self.client.get_with_query("/batches", &query, &self.request_options).await
3539
}
3640

3741
/// Retrieves a batch.
3842
#[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
3943
pub async fn retrieve(&self, batch_id: &str) -> Result<Batch, OpenAIError> {
40-
self.client.get(&format!("/batches/{batch_id}")).await
44+
self.client.get(&format!("/batches/{batch_id}"), &self.request_options).await
4145
}
4246

4347
/// 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> {
4751
.post(
4852
&format!("/batches/{batch_id}/cancel"),
4953
serde_json::json!({}),
54+
&self.request_options,
5055
)
5156
.await
5257
}

async-openai/src/certificates.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,22 @@ use crate::{
77
Certificate, DeleteCertificateResponse, ListCertificatesResponse, ModifyCertificateRequest,
88
ToggleCertificatesRequest, UploadCertificateRequest,
99
},
10-
Client,
10+
Client, RequestOptions,
1111
};
1212

1313
/// Certificates enable Mutual TLS (mTLS) authentication for your organization.
1414
/// Manage certificates at the organization level.
1515
pub struct Certificates<'c, C: Config> {
1616
client: &'c Client<C>,
17+
pub(crate) request_options: RequestOptions,
1718
}
1819

1920
impl<'c, C: Config> Certificates<'c, C> {
2021
pub fn new(client: &'c Client<C>) -> Self {
21-
Self { client }
22+
Self {
23+
client,
24+
request_options: RequestOptions::new(),
25+
}
2226
}
2327

2428
// Organization-level certificate operations
@@ -33,7 +37,7 @@ impl<'c, C: Config> Certificates<'c, C> {
3337
Q: Serialize + ?Sized,
3438
{
3539
self.client
36-
.get_with_query("/organization/certificates", &query)
40+
.get_with_query("/organization/certificates", &query, &self.request_options)
3741
.await
3842
}
3943

@@ -44,7 +48,7 @@ impl<'c, C: Config> Certificates<'c, C> {
4448
request: UploadCertificateRequest,
4549
) -> Result<Certificate, OpenAIError> {
4650
self.client
47-
.post("/organization/certificates", request)
51+
.post("/organization/certificates", request, &self.request_options)
4852
.await
4953
}
5054

@@ -55,7 +59,7 @@ impl<'c, C: Config> Certificates<'c, C> {
5559
request: ToggleCertificatesRequest,
5660
) -> Result<ListCertificatesResponse, OpenAIError> {
5761
self.client
58-
.post("/organization/certificates/activate", request)
62+
.post("/organization/certificates/activate", request, &self.request_options)
5963
.await
6064
}
6165

@@ -66,15 +70,15 @@ impl<'c, C: Config> Certificates<'c, C> {
6670
request: ToggleCertificatesRequest,
6771
) -> Result<ListCertificatesResponse, OpenAIError> {
6872
self.client
69-
.post("/organization/certificates/deactivate", request)
73+
.post("/organization/certificates/deactivate", request, &self.request_options)
7074
.await
7175
}
7276

7377
/// Retrieve a single certificate.
7478
#[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
7579
pub async fn retrieve(&self, certificate_id: &str) -> Result<Certificate, OpenAIError> {
7680
self.client
77-
.get(format!("/organization/certificates/{certificate_id}").as_str())
81+
.get(format!("/organization/certificates/{certificate_id}").as_str(), &self.request_options)
7882
.await
7983
}
8084

@@ -91,6 +95,7 @@ impl<'c, C: Config> Certificates<'c, C> {
9195
.get_with_query(
9296
format!("/organization/certificates/{certificate_id}").as_str(),
9397
query,
98+
&self.request_options,
9499
)
95100
.await
96101
}
@@ -106,6 +111,7 @@ impl<'c, C: Config> Certificates<'c, C> {
106111
.post(
107112
format!("/organization/certificates/{certificate_id}").as_str(),
108113
request,
114+
&self.request_options,
109115
)
110116
.await
111117
}
@@ -118,7 +124,7 @@ impl<'c, C: Config> Certificates<'c, C> {
118124
certificate_id: &str,
119125
) -> Result<DeleteCertificateResponse, OpenAIError> {
120126
self.client
121-
.delete(format!("/organization/certificates/{certificate_id}").as_str())
127+
.delete(format!("/organization/certificates/{certificate_id}").as_str(), &self.request_options)
122128
.await
123129
}
124130
}

0 commit comments

Comments
 (0)