Skip to content

Commit 85f5a23

Browse files
committed
Fix formatting
1 parent 0d8ca3e commit 85f5a23

File tree

2 files changed

+34
-99
lines changed

2 files changed

+34
-99
lines changed

rustfmt.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
max_width = 120
1+
max_width = 100

src/v1/resources/chat.rs

Lines changed: 33 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ use std::collections::HashMap;
66
use std::fmt::Display;
77
use std::str::FromStr;
88

9-
#[derive(
10-
Serialize, Deserialize, Debug, Clone, PartialEq,
11-
)]
9+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
1210
pub struct ChatCompletionResponse {
1311
/// A unique identifier for the chat completion.
1412
pub id: String,
@@ -28,9 +26,7 @@ pub struct ChatCompletionResponse {
2826
}
2927

3028
#[cfg(feature = "stream")]
31-
#[derive(
32-
Serialize, Deserialize, Debug, Clone, PartialEq,
33-
)]
29+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
3430
pub struct ChatCompletionChunkResponse {
3531
/// A unique identifier for the chat completion. Each chunk has the same ID.
3632
pub id: String,
@@ -48,9 +44,7 @@ pub struct ChatCompletionChunkResponse {
4844
pub object: String,
4945
}
5046

51-
#[derive(
52-
Serialize, Deserialize, Debug, Clone, PartialEq,
53-
)]
47+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
5448
pub struct ChatCompletionParameters {
5549
/// A list of messages comprising the conversation so far.
5650
pub messages: Vec<ChatMessage>,
@@ -85,8 +79,7 @@ pub struct ChatCompletionParameters {
8579
/// An object specifying the format that the model must output.
8680
/// Setting to { "type": "json_object" } enables JSON mode, which guarantees the message the model generates is valid JSON.
8781
#[serde(skip_serializing_if = "Option::is_none")]
88-
pub response_format:
89-
Option<ChatCompletionResponseFormat>,
82+
pub response_format: Option<ChatCompletionResponseFormat>,
9083
/// This feature is in Beta. If specified, our system will make a best effort to sample deterministically,
9184
/// such that repeated requests with the same seed and parameters should return the same result.
9285
/// Determinism is not guaranteed, and you should refer to the system_fingerprint response parameter to monitor changes in the backend.
@@ -118,9 +111,7 @@ pub struct ChatCompletionParameters {
118111
pub user: Option<String>,
119112
}
120113

121-
#[derive(
122-
Serialize, Deserialize, Debug, Clone, PartialEq,
123-
)]
114+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
124115
pub struct ChatCompletionToolChoiceFunction {
125116
/// The type of the tool. Currently, only 'function' is supported.
126117
#[serde(skip_serializing_if = "Option::is_none")]
@@ -129,17 +120,13 @@ pub struct ChatCompletionToolChoiceFunction {
129120
pub function: ChatCompletionToolChoiceFunctionName,
130121
}
131122

132-
#[derive(
133-
Serialize, Deserialize, Debug, Clone, PartialEq,
134-
)]
123+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
135124
pub struct ChatCompletionToolChoiceFunctionName {
136125
/// Name of the function.
137126
pub name: String,
138127
}
139128

140-
#[derive(
141-
Serialize, Deserialize, Debug, Clone, PartialEq,
142-
)]
129+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
143130
pub struct ChatCompletionFunction {
144131
/// Name of the function.
145132
pub name: String,
@@ -150,27 +137,21 @@ pub struct ChatCompletionFunction {
150137
pub parameters: serde_json::Value,
151138
}
152139

153-
#[derive(
154-
Serialize, Deserialize, Debug, Clone, PartialEq,
155-
)]
140+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
156141
pub struct ChatCompletionResponseFormat {
157142
/// The type of response format. Currently, only 'json_object' and 'text' are supported.
158143
pub r#type: ChatCompletionResponseFormatType,
159144
}
160145

161-
#[derive(
162-
Serialize, Deserialize, Debug, Clone, PartialEq,
163-
)]
146+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
164147
pub struct ChatCompletionTool {
165148
/// The type of the tool. Currently, only 'function' is supported.
166149
pub r#type: ChatCompletionToolType,
167150
/// The name of the function to call.
168151
pub function: ChatCompletionFunction,
169152
}
170153

171-
#[derive(
172-
Serialize, Deserialize, Debug, Clone, PartialEq,
173-
)]
154+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
174155
pub struct ChatMessage {
175156
/// The role of the author of this message.
176157
pub role: Role,
@@ -188,9 +169,7 @@ pub struct ChatMessage {
188169
}
189170

190171
#[cfg(feature = "stream")]
191-
#[derive(
192-
Serialize, Deserialize, Debug, Clone, PartialEq,
193-
)]
172+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
194173
pub struct DeltaChatMessage {
195174
/// The role of the author of this message.
196175
#[serde(skip_serializing_if = "Option::is_none")]
@@ -203,9 +182,7 @@ pub struct DeltaChatMessage {
203182
pub tool_calls: Option<Vec<DeltaToolCall>>,
204183
}
205184

206-
#[derive(
207-
Serialize, Deserialize, Debug, Clone, PartialEq,
208-
)]
185+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
209186
pub struct ToolCall {
210187
/// The index of the tool call in the list of tool calls.
211188
#[serde(skip_serializing_if = "Option::is_none")]
@@ -220,9 +197,7 @@ pub struct ToolCall {
220197
pub function: Function,
221198
}
222199

223-
#[derive(
224-
Serialize, Deserialize, Debug, Clone, PartialEq,
225-
)]
200+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
226201
pub struct DeltaToolCall {
227202
/// The index of the tool call in the list of tool calls.
228203
#[serde(skip_serializing_if = "Option::is_none")]
@@ -237,19 +212,15 @@ pub struct DeltaToolCall {
237212
pub function: DeltaFunction,
238213
}
239214

240-
#[derive(
241-
Serialize, Deserialize, Debug, Clone, PartialEq,
242-
)]
215+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
243216
pub struct Function {
244217
/// The name of the function to call.
245218
pub name: String,
246219
/// The arguments to call the function with, as generated by the model in JSON format.
247220
pub arguments: String,
248221
}
249222

250-
#[derive(
251-
Serialize, Deserialize, Debug, Clone, PartialEq,
252-
)]
223+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
253224
pub struct DeltaFunction {
254225
/// The name of the function to call.
255226
#[serde(skip_serializing_if = "Option::is_none")]
@@ -259,9 +230,7 @@ pub struct DeltaFunction {
259230
pub arguments: Option<String>,
260231
}
261232

262-
#[derive(
263-
Serialize, Deserialize, Debug, Clone, PartialEq,
264-
)]
233+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
265234
pub struct ChatCompletionChoice {
266235
/// The index of the choice in the list of choices.
267236
pub index: u32,
@@ -272,9 +241,7 @@ pub struct ChatCompletionChoice {
272241
}
273242

274243
#[cfg(feature = "stream")]
275-
#[derive(
276-
Serialize, Deserialize, Debug, Clone, PartialEq,
277-
)]
244+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
278245
pub struct ChatCompletionChunkChoice {
279246
/// The index of the choice in the list of choices.
280247
pub index: u32,
@@ -286,9 +253,7 @@ pub struct ChatCompletionChunkChoice {
286253
}
287254

288255
#[cfg(feature = "stream")]
289-
#[derive(
290-
Serialize, Deserialize, Debug, Clone, PartialEq,
291-
)]
256+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
292257
pub struct StreamChatCompletionParameters {
293258
pub messages: Vec<ChatMessage>,
294259
pub model: String,
@@ -303,8 +268,7 @@ pub struct StreamChatCompletionParameters {
303268
#[serde(skip_serializing_if = "Option::is_none")]
304269
pub presence_penalty: Option<f32>,
305270
#[serde(skip_serializing_if = "Option::is_none")]
306-
pub response_format:
307-
Option<ChatCompletionResponseFormat>,
271+
pub response_format: Option<ChatCompletionResponseFormat>,
308272
#[serde(skip_serializing_if = "Option::is_none")]
309273
pub stop: Option<StopToken>,
310274
pub stream: bool,
@@ -320,9 +284,7 @@ pub struct StreamChatCompletionParameters {
320284
pub user: Option<String>,
321285
}
322286

323-
#[derive(
324-
Serialize, Deserialize, Debug, Clone, PartialEq,
325-
)]
287+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
326288
pub struct ImageUrl {
327289
/// The type of the content part.
328290
pub r#type: String,
@@ -333,9 +295,7 @@ pub struct ImageUrl {
333295
pub image_url: ImageUrlType,
334296
}
335297

336-
#[derive(
337-
Serialize, Deserialize, Debug, Clone, PartialEq,
338-
)]
298+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
339299
pub struct ImageUrlType {
340300
/// Either a URL of the image or the base64 encoded image data.
341301
pub url: String,
@@ -344,60 +304,46 @@ pub struct ImageUrlType {
344304
pub detail: Option<ImageUrlDetail>,
345305
}
346306

347-
#[derive(
348-
Serialize, Deserialize, Debug, Clone, PartialEq,
349-
)]
307+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
350308
#[serde(rename_all = "lowercase")]
351309
pub enum ImageUrlDetail {
352310
Auto,
353311
High,
354312
Low,
355313
}
356314

357-
#[derive(
358-
Serialize, Deserialize, Debug, Clone, PartialEq,
359-
)]
315+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
360316
#[serde(untagged)]
361317
pub enum ChatMessageContent {
362318
Text(String),
363319
ImageUrl(Vec<ImageUrl>),
364320
None,
365321
}
366322

367-
#[derive(
368-
Serialize, Deserialize, Debug, Clone, PartialEq,
369-
)]
323+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
370324
pub enum ChatCompletionResponseFormatType {
371325
#[serde(rename = "text")]
372326
Text,
373327
#[serde(rename = "json_object")]
374328
JsonObject,
375329
}
376330

377-
#[derive(
378-
Serialize, Deserialize, Debug, Clone, PartialEq,
379-
)]
331+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
380332
#[serde(rename_all = "lowercase")]
381333
pub enum ChatCompletionToolType {
382334
Function,
383335
}
384336

385-
#[derive(
386-
Serialize, Deserialize, Debug, Clone, PartialEq,
387-
)]
337+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
388338
#[serde(rename_all = "lowercase")]
389339
#[serde(untagged)]
390340
pub enum ChatCompletionToolChoice {
391341
None,
392342
Auto,
393-
ChatCompletionToolChoiceFunction(
394-
ChatCompletionToolChoiceFunction,
395-
),
343+
ChatCompletionToolChoiceFunction(ChatCompletionToolChoiceFunction),
396344
}
397345

398-
#[derive(
399-
Serialize, Deserialize, Debug, Clone, PartialEq,
400-
)]
346+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
401347
#[serde(rename_all = "lowercase")]
402348
pub enum Role {
403349
System,
@@ -412,9 +358,7 @@ impl Default for ChatCompletionParameters {
412358
ChatCompletionParameters {
413359
messages: vec![ChatMessage {
414360
role: Role::User,
415-
content: ChatMessageContent::Text(
416-
"Hello, World!".to_string(),
417-
),
361+
content: ChatMessageContent::Text("Hello, World!".to_string()),
418362
tool_calls: None,
419363
name: None,
420364
tool_call_id: None,
@@ -443,9 +387,7 @@ impl Default for ChatMessage {
443387
fn default() -> Self {
444388
ChatMessage {
445389
role: Role::User,
446-
content: ChatMessageContent::Text(
447-
"Hello, World!".to_string(),
448-
),
390+
content: ChatMessageContent::Text("Hello, World!".to_string()),
449391
tool_calls: None,
450392
name: None,
451393
tool_call_id: None,
@@ -454,10 +396,7 @@ impl Default for ChatMessage {
454396
}
455397

456398
impl Display for Role {
457-
fn fmt(
458-
&self,
459-
f: &mut std::fmt::Formatter<'_>,
460-
) -> std::fmt::Result {
399+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
461400
write!(
462401
f,
463402
"{}",
@@ -489,16 +428,12 @@ impl FromStr for Role {
489428

490429
impl DeltaFunction {
491430
pub fn merge(&mut self, other: &Self) {
492-
if self.name.is_none()
493-
&& other.name.is_none() == false
494-
{
431+
if self.name.is_none() && other.name.is_none() == false {
495432
self.name = other.name.clone();
496433
}
497434

498435
if let Some(arguments) = &other.arguments {
499-
if let Some(self_arguments) =
500-
&mut self.arguments
501-
{
436+
if let Some(self_arguments) = &mut self.arguments {
502437
self_arguments.push_str(arguments);
503438
} else {
504439
self.arguments = Some(arguments.clone());

0 commit comments

Comments
 (0)