Skip to content

Commit 3c4d5bb

Browse files
author
Dongri Jin
authored
Merge pull request #72 from dongri/add-serialize
Add serialize
2 parents 4099fee + 9b90bf7 commit 3c4d5bb

File tree

15 files changed

+67
-67
lines changed

15 files changed

+67
-67
lines changed

examples/function_call.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
6969
}
7070
Some(chat_completion::FinishReason::tool_calls) => {
7171
println!("ToolCalls");
72-
#[derive(Serialize, Deserialize)]
72+
#[derive(Deserialize, Serialize)]
7373
struct Currency {
7474
coin: String,
7575
}

examples/function_call_role.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
6464
}
6565
Some(chat_completion::FinishReason::tool_calls) => {
6666
println!("ToolCalls");
67-
#[derive(Serialize, Deserialize)]
67+
#[derive(Deserialize, Serialize)]
6868
struct Currency {
6969
coin: String,
7070
}

src/v1/assistant.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl_builder_methods!(
4444
metadata: HashMap<String, String>
4545
);
4646

47-
#[derive(Debug, Serialize, Deserialize)]
47+
#[derive(Debug, Deserialize, Serialize)]
4848
pub struct AssistantObject {
4949
pub id: String,
5050
pub object: String,
@@ -61,14 +61,14 @@ pub struct AssistantObject {
6161
pub metadata: HashMap<String, String>,
6262
}
6363

64-
#[derive(Debug, Serialize, Deserialize)]
64+
#[derive(Debug, Deserialize, Serialize)]
6565
pub struct DeletionStatus {
6666
pub id: String,
6767
pub object: String,
6868
pub deleted: bool,
6969
}
7070

71-
#[derive(Debug, Serialize, Deserialize)]
71+
#[derive(Debug, Deserialize, Serialize)]
7272
pub struct ListAssistant {
7373
pub object: String,
7474
pub data: Vec<AssistantObject>,
@@ -79,15 +79,15 @@ pub struct AssistantFileRequest {
7979
pub file_id: String,
8080
}
8181

82-
#[derive(Debug, Serialize, Deserialize)]
82+
#[derive(Debug, Deserialize, Serialize)]
8383
pub struct AssistantFileObject {
8484
pub id: String,
8585
pub object: String,
8686
pub created_at: i64,
8787
pub assistant_id: String,
8888
}
8989

90-
#[derive(Debug, Serialize, Deserialize)]
90+
#[derive(Debug, Deserialize, Serialize)]
9191
pub struct ListAssistantFile {
9292
pub object: String,
9393
pub data: Vec<AssistantFileObject>,

src/v1/audio.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl_builder_methods!(
3939
language: String
4040
);
4141

42-
#[derive(Debug, Deserialize)]
42+
#[derive(Debug, Deserialize, Serialize)]
4343
pub struct AudioTranscriptionResponse {
4444
pub text: String,
4545
}
@@ -75,7 +75,7 @@ impl_builder_methods!(
7575
temperature: f32
7676
);
7777

78-
#[derive(Debug, Deserialize)]
78+
#[derive(Debug, Deserialize, Serialize)]
7979
pub struct AudioTranslationResponse {
8080
pub text: String,
8181
}
@@ -111,7 +111,7 @@ impl AudioSpeechRequest {
111111

112112
impl_builder_methods!(AudioSpeechRequest,);
113113

114-
#[derive(Debug, Deserialize)]
114+
#[derive(Debug, Deserialize, Serialize)]
115115
pub struct AudioSpeechResponse {
116116
pub result: bool,
117117
}

src/v1/chat_completion.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl_builder_methods!(
8989
tool_choice: ToolChoiceType
9090
);
9191

92-
#[derive(Debug, Serialize, Deserialize, Clone)]
92+
#[derive(Debug, Deserialize, Serialize, Clone)]
9393
#[allow(non_camel_case_types)]
9494
pub enum MessageRole {
9595
user,
@@ -116,20 +116,20 @@ impl serde::Serialize for Content {
116116
}
117117
}
118118

119-
#[derive(Debug, Serialize, Deserialize, Clone)]
119+
#[derive(Debug, Deserialize, Serialize, Clone)]
120120
#[allow(non_camel_case_types)]
121121
pub enum ContentType {
122122
text,
123123
image_url,
124124
}
125125

126-
#[derive(Debug, Serialize, Deserialize, Clone)]
126+
#[derive(Debug, Deserialize, Serialize, Clone)]
127127
#[allow(non_camel_case_types)]
128128
pub struct ImageUrlType {
129129
pub url: String,
130130
}
131131

132-
#[derive(Debug, Serialize, Deserialize, Clone)]
132+
#[derive(Debug, Deserialize, Serialize, Clone)]
133133
#[allow(non_camel_case_types)]
134134
pub struct ImageUrl {
135135
pub r#type: ContentType,
@@ -139,15 +139,15 @@ pub struct ImageUrl {
139139
pub image_url: Option<ImageUrlType>,
140140
}
141141

142-
#[derive(Debug, Serialize, Deserialize, Clone)]
142+
#[derive(Debug, Deserialize, Serialize, Clone)]
143143
pub struct ChatCompletionMessage {
144144
pub role: MessageRole,
145145
pub content: Content,
146146
#[serde(skip_serializing_if = "Option::is_none")]
147147
pub name: Option<String>,
148148
}
149149

150-
#[derive(Debug, Serialize, Deserialize)]
150+
#[derive(Debug, Deserialize, Serialize)]
151151
pub struct ChatCompletionMessageForResponse {
152152
pub role: MessageRole,
153153
#[serde(skip_serializing_if = "Option::is_none")]
@@ -177,15 +177,15 @@ pub struct ChatCompletionResponse {
177177
pub system_fingerprint: Option<String>,
178178
}
179179

180-
#[derive(Debug, Serialize, Deserialize, Clone)]
180+
#[derive(Debug, Deserialize, Serialize, Clone)]
181181
pub struct Function {
182182
pub name: String,
183183
#[serde(skip_serializing_if = "Option::is_none")]
184184
pub description: Option<String>,
185185
pub parameters: FunctionParameters,
186186
}
187187

188-
#[derive(Debug, Serialize, Deserialize, Clone)]
188+
#[derive(Debug, Deserialize, Serialize, Clone)]
189189
#[serde(rename_all = "lowercase")]
190190
pub enum JSONSchemaType {
191191
Object,
@@ -196,7 +196,7 @@ pub enum JSONSchemaType {
196196
Boolean,
197197
}
198198

199-
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
199+
#[derive(Debug, Deserialize, Serialize, Clone, Default)]
200200
pub struct JSONSchemaDefine {
201201
#[serde(rename = "type")]
202202
pub schema_type: Option<JSONSchemaType>,
@@ -212,7 +212,7 @@ pub struct JSONSchemaDefine {
212212
pub items: Option<Box<JSONSchemaDefine>>,
213213
}
214214

215-
#[derive(Debug, Serialize, Deserialize, Clone)]
215+
#[derive(Debug, Deserialize, Serialize, Clone)]
216216
pub struct FunctionParameters {
217217
#[serde(rename = "type")]
218218
pub schema_type: JSONSchemaType,
@@ -222,7 +222,7 @@ pub struct FunctionParameters {
222222
pub required: Option<Vec<String>>,
223223
}
224224

225-
#[derive(Debug, Serialize, Deserialize)]
225+
#[derive(Debug, Deserialize, Serialize)]
226226
#[allow(non_camel_case_types)]
227227
pub enum FinishReason {
228228
stop,
@@ -232,21 +232,21 @@ pub enum FinishReason {
232232
null,
233233
}
234234

235-
#[derive(Debug, Serialize, Deserialize)]
235+
#[derive(Debug, Deserialize, Serialize)]
236236
#[allow(non_camel_case_types)]
237237
pub struct FinishDetails {
238238
pub r#type: FinishReason,
239239
pub stop: String,
240240
}
241241

242-
#[derive(Debug, Serialize, Deserialize, Clone)]
242+
#[derive(Debug, Deserialize, Serialize, Clone)]
243243
pub struct ToolCall {
244244
pub id: String,
245245
pub r#type: String,
246246
pub function: ToolCallFunction,
247247
}
248248

249-
#[derive(Debug, Serialize, Deserialize, Clone)]
249+
#[derive(Debug, Deserialize, Serialize, Clone)]
250250
pub struct ToolCallFunction {
251251
#[serde(skip_serializing_if = "Option::is_none")]
252252
pub name: Option<String>,
@@ -274,13 +274,13 @@ where
274274
}
275275
}
276276

277-
#[derive(Debug, Serialize, Deserialize, Clone)]
277+
#[derive(Debug, Deserialize, Serialize, Clone)]
278278
pub struct Tool {
279279
pub r#type: ToolType,
280280
pub function: Function,
281281
}
282282

283-
#[derive(Debug, Serialize, Deserialize, Copy, Clone)]
283+
#[derive(Debug, Deserialize, Serialize, Copy, Clone)]
284284
#[serde(rename_all = "snake_case")]
285285
pub enum ToolType {
286286
Function,

src/v1/completion.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,23 +93,23 @@ impl_builder_methods!(
9393
user: String
9494
);
9595

96-
#[derive(Debug, Deserialize)]
96+
#[derive(Debug, Deserialize, Serialize)]
9797
pub struct CompletionChoice {
9898
pub text: String,
9999
pub index: i64,
100100
pub finish_reason: String,
101101
pub logprobs: Option<LogprobResult>,
102102
}
103103

104-
#[derive(Debug, Deserialize)]
104+
#[derive(Debug, Deserialize, Serialize)]
105105
pub struct LogprobResult {
106106
pub tokens: Vec<String>,
107107
pub token_logprobs: Vec<f32>,
108108
pub top_logprobs: Vec<HashMap<String, f32>>,
109109
pub text_offset: Vec<i32>,
110110
}
111111

112-
#[derive(Debug, Deserialize)]
112+
#[derive(Debug, Deserialize, Serialize)]
113113
pub struct CompletionResponse {
114114
pub id: String,
115115
pub object: String,

src/v1/edit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ impl_builder_methods!(
3939
top_p: f32
4040
);
4141

42-
#[derive(Debug, Deserialize)]
42+
#[derive(Debug, Deserialize, Serialize)]
4343
pub struct EditChoice {
4444
pub text: String,
4545
pub index: i32,
4646
}
4747

48-
#[derive(Debug, Deserialize)]
48+
#[derive(Debug, Deserialize, Serialize)]
4949
pub struct EditResponse {
5050
pub object: String,
5151
pub created: i64,

src/v1/embedding.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::option::Option;
33

44
use crate::impl_builder_methods;
55

6-
#[derive(Debug, Deserialize)]
6+
#[derive(Debug, Deserialize, Serialize)]
77
pub struct EmbeddingData {
88
pub object: String,
99
pub embedding: Vec<f32>,
@@ -33,15 +33,15 @@ impl_builder_methods!(
3333
user: String
3434
);
3535

36-
#[derive(Debug, Deserialize)]
36+
#[derive(Debug, Deserialize, Serialize)]
3737
pub struct EmbeddingResponse {
3838
pub object: String,
3939
pub data: Vec<EmbeddingData>,
4040
pub model: String,
4141
pub usage: Usage,
4242
}
4343

44-
#[derive(Debug, Deserialize)]
44+
#[derive(Debug, Deserialize, Serialize)]
4545
pub struct Usage {
4646
pub prompt_tokens: i32,
4747
pub total_tokens: i32,

src/v1/file.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use serde::{Deserialize, Serialize};
22

3-
#[derive(Debug, Deserialize)]
3+
#[derive(Debug, Deserialize, Serialize)]
44
pub struct FileData {
55
pub id: String,
66
pub oejct: String,
@@ -10,7 +10,7 @@ pub struct FileData {
1010
pub purpose: String,
1111
}
1212

13-
#[derive(Debug, Deserialize)]
13+
#[derive(Debug, Deserialize, Serialize)]
1414
pub struct FileListResponse {
1515
pub object: String,
1616
pub data: Vec<FileData>,
@@ -28,7 +28,7 @@ impl FileUploadRequest {
2828
}
2929
}
3030

31-
#[derive(Debug, Deserialize)]
31+
#[derive(Debug, Deserialize, Serialize)]
3232
pub struct FileUploadResponse {
3333
pub id: String,
3434
pub oejct: String,
@@ -49,7 +49,7 @@ impl FileDeleteRequest {
4949
}
5050
}
5151

52-
#[derive(Debug, Deserialize)]
52+
#[derive(Debug, Deserialize, Serialize)]
5353
pub struct FileDeleteResponse {
5454
pub id: String,
5555
pub oejct: String,
@@ -67,7 +67,7 @@ impl FileRetrieveRequest {
6767
}
6868
}
6969

70-
#[derive(Debug, Deserialize)]
70+
#[derive(Debug, Deserialize, Serialize)]
7171
pub struct FileRetrieveResponse {
7272
pub id: String,
7373
pub oejct: String,
@@ -88,7 +88,7 @@ impl FileRetrieveContentRequest {
8888
}
8989
}
9090

91-
#[derive(Debug, Deserialize)]
91+
#[derive(Debug, Deserialize, Serialize)]
9292
pub struct FileRetrieveContentResponse {
9393
pub id: String,
9494
pub oejct: String,

src/v1/fine_tuning.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ impl CancelFineTuningJobRequest {
9393
}
9494
}
9595

96-
#[derive(Debug, Deserialize)]
96+
#[derive(Debug, Deserialize, Serialize)]
9797
pub struct FineTuningPagination<T> {
9898
pub object: String,
9999
pub data: Vec<T>,
100100
pub has_more: bool,
101101
}
102102

103-
#[derive(Debug, Deserialize)]
103+
#[derive(Debug, Deserialize, Serialize)]
104104
pub struct FineTuningJobObject {
105105
pub id: String,
106106
pub created_at: i64,
@@ -118,14 +118,14 @@ pub struct FineTuningJobObject {
118118
pub validation_file: Option<String>,
119119
}
120120

121-
#[derive(Debug, Deserialize)]
121+
#[derive(Debug, Deserialize, Serialize)]
122122
pub struct FineTuningJobError {
123123
pub code: String,
124124
pub message: String,
125125
pub param: Option<String>,
126126
}
127127

128-
#[derive(Debug, Deserialize)]
128+
#[derive(Debug, Deserialize, Serialize)]
129129
pub struct FineTuningJobEvent {
130130
pub id: String,
131131
pub created_at: i64,
@@ -134,7 +134,7 @@ pub struct FineTuningJobEvent {
134134
pub object: String,
135135
}
136136

137-
#[derive(Clone, Debug, Serialize, Deserialize)]
137+
#[derive(Clone, Debug, Deserialize, Serialize)]
138138
pub struct HyperParameters {
139139
#[serde(skip_serializing_if = "Option::is_none")]
140140
pub batch_size: Option<String>,

0 commit comments

Comments
 (0)