Skip to content

Commit bbb5e2f

Browse files
committed
simplify
1 parent 60652c3 commit bbb5e2f

5 files changed

Lines changed: 26 additions & 78 deletions

File tree

async-openai/src/beta.rs

Lines changed: 0 additions & 42 deletions
This file was deleted.

async-openai/src/client.rs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use reqwest_eventsource::{Error as EventSourceError, Event, EventSource, Request
77
use serde::{de::DeserializeOwned, Serialize};
88

99
use crate::{
10-
beta::Beta,
10+
chatkit::Chatkit,
1111
config::{Config, OpenAIConfig},
1212
error::{map_deserialization_error, ApiError, OpenAIError, StreamError, WrappedError},
1313
file::Files,
@@ -189,26 +189,14 @@ impl<C: Config> Client<C> {
189189
Evals::new(self)
190190
}
191191

192-
/// Access beta APIs like ChatKit.
193-
///
194-
/// Beta APIs require special headers that are automatically added.
195-
/// Use `client.beta().chatkit()` to access ChatKit APIs.
196-
pub fn beta(&self) -> Beta<'_, C> {
197-
Beta::new_generic(self)
192+
pub fn chatkit(&self) -> Chatkit<'_, C> {
193+
Chatkit::new(self)
198194
}
199195

200196
pub fn config(&self) -> &C {
201197
&self.config
202198
}
203199

204-
pub(crate) fn http_client(&self) -> &reqwest::Client {
205-
&self.http_client
206-
}
207-
208-
pub(crate) fn backoff(&self) -> &backoff::ExponentialBackoff {
209-
&self.backoff
210-
}
211-
212200
/// Make a GET request to {path} and deserialize the response body
213201
pub(crate) async fn get<O>(&self, path: &str) -> Result<O, OpenAIError>
214202
where

async-openai/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ mod assistants;
144144
mod audio;
145145
mod audit_logs;
146146
mod batches;
147-
mod beta;
148147
mod chat;
149148
mod chatkit;
150149
mod client;
@@ -194,7 +193,6 @@ pub use assistants::Assistants;
194193
pub use audio::Audio;
195194
pub use audit_logs::AuditLogs;
196195
pub use batches::Batches;
197-
pub use beta::Beta;
198196
pub use chat::Chat;
199197
pub use chatkit::Chatkit;
200198
pub use client::Client;

async-openai/src/types/chatkit/session.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ pub struct ChatkitWorkflow {
4141
/// Identifier of the workflow backing the session.
4242
pub id: String,
4343
/// Specific workflow version used for the session. Defaults to null when using the latest deployment.
44+
#[serde(skip_serializing_if = "Option::is_none")]
4445
pub version: Option<String>,
4546
/// State variable key-value pairs applied when invoking the workflow. Defaults to null when no overrides were provided.
47+
#[serde(skip_serializing_if = "Option::is_none")]
4648
pub state_variables: Option<HashMap<String, serde_json::Value>>,
4749
/// Tracing settings applied to the workflow.
4850
pub tracing: ChatkitWorkflowTracing,
@@ -95,8 +97,10 @@ pub struct ChatSessionFileUpload {
9597
/// Indicates if uploads are enabled for the session.
9698
pub enabled: bool,
9799
/// Maximum upload size in megabytes.
100+
#[serde(skip_serializing_if = "Option::is_none")]
98101
pub max_file_size: Option<i32>,
99102
/// Maximum number of uploads allowed during the session.
103+
#[serde(skip_serializing_if = "Option::is_none")]
100104
pub max_files: Option<i32>,
101105
}
102106

@@ -106,14 +110,15 @@ pub struct ChatSessionHistory {
106110
/// Indicates if chat history is persisted for the session.
107111
pub enabled: bool,
108112
/// Number of prior threads surfaced in history views. Defaults to null when all history is retained.
113+
#[serde(skip_serializing_if = "Option::is_none")]
109114
pub recent_threads: Option<i32>,
110115
}
111116

112117
/// Parameters for provisioning a new ChatKit session.
113-
#[derive(Clone, Serialize, Debug, Deserialize, Builder, PartialEq)]
118+
#[derive(Clone, Serialize, Debug, Deserialize, Builder, PartialEq, Default)]
114119
#[builder(name = "CreateChatSessionRequestArgs")]
115120
#[builder(pattern = "mutable")]
116-
#[builder(setter(into, strip_option))]
121+
#[builder(setter(into, strip_option), default)]
117122
#[builder(derive(Debug))]
118123
#[builder(build_fn(error = "OpenAIError"))]
119124
pub struct CreateChatSessionBody {
@@ -133,10 +138,10 @@ pub struct CreateChatSessionBody {
133138
}
134139

135140
/// Workflow reference and overrides applied to the chat session.
136-
#[derive(Clone, Serialize, Debug, Deserialize, Builder, PartialEq)]
141+
#[derive(Clone, Serialize, Debug, Deserialize, Builder, PartialEq, Default)]
137142
#[builder(name = "WorkflowParamArgs")]
138143
#[builder(pattern = "mutable")]
139-
#[builder(setter(into, strip_option))]
144+
#[builder(setter(into, strip_option), default)]
140145
#[builder(derive(Debug))]
141146
#[builder(build_fn(error = "OpenAIError"))]
142147
pub struct WorkflowParam {
@@ -167,10 +172,10 @@ pub struct WorkflowTracingParam {
167172
}
168173

169174
/// Controls when the session expires relative to an anchor timestamp.
170-
#[derive(Clone, Serialize, Debug, Deserialize, Builder, PartialEq)]
175+
#[derive(Clone, Serialize, Debug, Deserialize, Builder, PartialEq, Default)]
171176
#[builder(name = "ExpiresAfterParamArgs")]
172177
#[builder(pattern = "mutable")]
173-
#[builder(setter(into, strip_option))]
178+
#[builder(setter(into, strip_option), default)]
174179
#[builder(derive(Debug))]
175180
#[builder(build_fn(error = "OpenAIError"))]
176181
pub struct ExpiresAfterParam {
@@ -187,7 +192,7 @@ fn default_anchor() -> String {
187192
}
188193

189194
/// Controls request rate limits for the session.
190-
#[derive(Clone, Serialize, Default, Debug, Deserialize, Builder, PartialEq)]
195+
#[derive(Clone, Serialize, Debug, Deserialize, Builder, PartialEq, Default)]
191196
#[builder(name = "RateLimitsParamArgs")]
192197
#[builder(pattern = "mutable")]
193198
#[builder(setter(into, strip_option), default)]
@@ -200,7 +205,7 @@ pub struct RateLimitsParam {
200205
}
201206

202207
/// Optional per-session configuration settings for ChatKit behavior.
203-
#[derive(Clone, Serialize, Default, Debug, Deserialize, Builder, PartialEq)]
208+
#[derive(Clone, Serialize, Debug, Deserialize, Builder, PartialEq, Default)]
204209
#[builder(name = "ChatkitConfigurationParamArgs")]
205210
#[builder(pattern = "mutable")]
206211
#[builder(setter(into, strip_option), default)]
@@ -219,7 +224,7 @@ pub struct ChatkitConfigurationParam {
219224
}
220225

221226
/// Controls whether ChatKit automatically generates thread titles.
222-
#[derive(Clone, Serialize, Default, Debug, Deserialize, Builder, PartialEq)]
227+
#[derive(Clone, Serialize, Debug, Deserialize, Builder, PartialEq, Default)]
223228
#[builder(name = "AutomaticThreadTitlingParamArgs")]
224229
#[builder(pattern = "mutable")]
225230
#[builder(setter(into, strip_option), default)]
@@ -232,7 +237,7 @@ pub struct AutomaticThreadTitlingParam {
232237
}
233238

234239
/// Controls whether users can upload files.
235-
#[derive(Clone, Serialize, Default, Debug, Deserialize, Builder, PartialEq)]
240+
#[derive(Clone, Serialize, Debug, Deserialize, Builder, PartialEq, Default)]
236241
#[builder(name = "FileUploadParamArgs")]
237242
#[builder(pattern = "mutable")]
238243
#[builder(setter(into, strip_option), default)]
@@ -251,7 +256,7 @@ pub struct FileUploadParam {
251256
}
252257

253258
/// Controls how much historical context is retained for the session.
254-
#[derive(Clone, Serialize, Default, Debug, Deserialize, Builder, PartialEq)]
259+
#[derive(Clone, Serialize, Debug, Deserialize, Builder, PartialEq, Default)]
255260
#[builder(name = "HistoryParamArgs")]
256261
#[builder(pattern = "mutable")]
257262
#[builder(setter(into, strip_option), default)]

async-openai/src/types/chatkit/thread.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub enum ThreadStatus {
3939
}
4040

4141
/// A paginated list of ChatKit threads.
42-
#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
42+
#[derive(Clone, Serialize, Debug, Deserialize, PartialEq, Default)]
4343
pub struct ThreadListResource {
4444
/// The type of object returned, must be `list`.
4545
#[serde(default = "default_list_object")]
@@ -59,7 +59,7 @@ fn default_list_object() -> String {
5959
}
6060

6161
/// Confirmation payload returned after deleting a thread.
62-
#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
62+
#[derive(Clone, Serialize, Debug, Deserialize, PartialEq, Default)]
6363
pub struct DeletedThreadResource {
6464
/// Identifier of the deleted thread.
6565
pub id: String,
@@ -75,7 +75,7 @@ fn default_deleted_object() -> String {
7575
}
7676

7777
/// A paginated list of thread items rendered for the ChatKit API.
78-
#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
78+
#[derive(Clone, Serialize, Debug, Deserialize, PartialEq, Default)]
7979
pub struct ThreadItemListResource {
8080
/// The type of object returned, must be `list`.
8181
#[serde(default = "default_list_object")]
@@ -115,7 +115,7 @@ pub enum ThreadItem {
115115
}
116116

117117
/// User-authored messages within a thread.
118-
#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
118+
#[derive(Clone, Serialize, Debug, Deserialize, PartialEq, Default)]
119119
pub struct UserMessageItem {
120120
/// Identifier of the thread item.
121121
pub id: String,
@@ -177,7 +177,7 @@ pub enum AttachmentType {
177177
}
178178

179179
/// Model and tool overrides applied when generating the assistant response.
180-
#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
180+
#[derive(Clone, Serialize, Debug, Deserialize, PartialEq, Default)]
181181
pub struct InferenceOptions {
182182
/// Preferred tool to invoke. Defaults to null when ChatKit should auto-select.
183183
#[serde(skip_serializing_if = "Option::is_none")]
@@ -188,14 +188,14 @@ pub struct InferenceOptions {
188188
}
189189

190190
/// Tool selection that the assistant should honor when executing the item.
191-
#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
191+
#[derive(Clone, Serialize, Debug, Deserialize, PartialEq, Default)]
192192
pub struct ToolChoice {
193193
/// Identifier of the requested tool.
194194
pub id: String,
195195
}
196196

197197
/// Assistant-authored message within a thread.
198-
#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
198+
#[derive(Clone, Serialize, Debug, Deserialize, PartialEq, Default)]
199199
pub struct AssistantMessageItem {
200200
/// Identifier of the thread item.
201201
pub id: String,
@@ -397,4 +397,3 @@ pub struct TaskGroupTask {
397397
/// Optional summary that describes the grouped task. Defaults to null when omitted.
398398
pub summary: Option<String>,
399399
}
400-

0 commit comments

Comments
 (0)