Skip to content

Commit

Permalink
Add serialize
Browse files Browse the repository at this point in the history
  • Loading branch information
Dongri Jin committed Jan 26, 2024
1 parent 4099fee commit 9b90bf7
Show file tree
Hide file tree
Showing 15 changed files with 67 additions and 67 deletions.
2 changes: 1 addition & 1 deletion examples/function_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}
Some(chat_completion::FinishReason::tool_calls) => {
println!("ToolCalls");
#[derive(Serialize, Deserialize)]
#[derive(Deserialize, Serialize)]
struct Currency {
coin: String,
}
Expand Down
2 changes: 1 addition & 1 deletion examples/function_call_role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}
Some(chat_completion::FinishReason::tool_calls) => {
println!("ToolCalls");
#[derive(Serialize, Deserialize)]
#[derive(Deserialize, Serialize)]
struct Currency {
coin: String,
}
Expand Down
10 changes: 5 additions & 5 deletions src/v1/assistant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl_builder_methods!(
metadata: HashMap<String, String>
);

#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Deserialize, Serialize)]
pub struct AssistantObject {
pub id: String,
pub object: String,
Expand All @@ -61,14 +61,14 @@ pub struct AssistantObject {
pub metadata: HashMap<String, String>,
}

#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Deserialize, Serialize)]
pub struct DeletionStatus {
pub id: String,
pub object: String,
pub deleted: bool,
}

#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Deserialize, Serialize)]
pub struct ListAssistant {
pub object: String,
pub data: Vec<AssistantObject>,
Expand All @@ -79,15 +79,15 @@ pub struct AssistantFileRequest {
pub file_id: String,
}

#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Deserialize, Serialize)]
pub struct AssistantFileObject {
pub id: String,
pub object: String,
pub created_at: i64,
pub assistant_id: String,
}

#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Deserialize, Serialize)]
pub struct ListAssistantFile {
pub object: String,
pub data: Vec<AssistantFileObject>,
Expand Down
6 changes: 3 additions & 3 deletions src/v1/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl_builder_methods!(
language: String
);

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Serialize)]
pub struct AudioTranscriptionResponse {
pub text: String,
}
Expand Down Expand Up @@ -75,7 +75,7 @@ impl_builder_methods!(
temperature: f32
);

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Serialize)]
pub struct AudioTranslationResponse {
pub text: String,
}
Expand Down Expand Up @@ -111,7 +111,7 @@ impl AudioSpeechRequest {

impl_builder_methods!(AudioSpeechRequest,);

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Serialize)]
pub struct AudioSpeechResponse {
pub result: bool,
}
32 changes: 16 additions & 16 deletions src/v1/chat_completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl_builder_methods!(
tool_choice: ToolChoiceType
);

#[derive(Debug, Serialize, Deserialize, Clone)]
#[derive(Debug, Deserialize, Serialize, Clone)]
#[allow(non_camel_case_types)]
pub enum MessageRole {
user,
Expand All @@ -116,20 +116,20 @@ impl serde::Serialize for Content {
}
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[derive(Debug, Deserialize, Serialize, Clone)]
#[allow(non_camel_case_types)]
pub enum ContentType {
text,
image_url,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[derive(Debug, Deserialize, Serialize, Clone)]
#[allow(non_camel_case_types)]
pub struct ImageUrlType {
pub url: String,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[derive(Debug, Deserialize, Serialize, Clone)]
#[allow(non_camel_case_types)]
pub struct ImageUrl {
pub r#type: ContentType,
Expand All @@ -139,15 +139,15 @@ pub struct ImageUrl {
pub image_url: Option<ImageUrlType>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct ChatCompletionMessage {
pub role: MessageRole,
pub content: Content,
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
}

#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Deserialize, Serialize)]
pub struct ChatCompletionMessageForResponse {
pub role: MessageRole,
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -177,15 +177,15 @@ pub struct ChatCompletionResponse {
pub system_fingerprint: Option<String>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct Function {
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
pub parameters: FunctionParameters,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "lowercase")]
pub enum JSONSchemaType {
Object,
Expand All @@ -196,7 +196,7 @@ pub enum JSONSchemaType {
Boolean,
}

#[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[derive(Debug, Deserialize, Serialize, Clone, Default)]
pub struct JSONSchemaDefine {
#[serde(rename = "type")]
pub schema_type: Option<JSONSchemaType>,
Expand All @@ -212,7 +212,7 @@ pub struct JSONSchemaDefine {
pub items: Option<Box<JSONSchemaDefine>>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct FunctionParameters {
#[serde(rename = "type")]
pub schema_type: JSONSchemaType,
Expand All @@ -222,7 +222,7 @@ pub struct FunctionParameters {
pub required: Option<Vec<String>>,
}

#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Deserialize, Serialize)]
#[allow(non_camel_case_types)]
pub enum FinishReason {
stop,
Expand All @@ -232,21 +232,21 @@ pub enum FinishReason {
null,
}

#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Deserialize, Serialize)]
#[allow(non_camel_case_types)]
pub struct FinishDetails {
pub r#type: FinishReason,
pub stop: String,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct ToolCall {
pub id: String,
pub r#type: String,
pub function: ToolCallFunction,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct ToolCallFunction {
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
Expand Down Expand Up @@ -274,13 +274,13 @@ where
}
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct Tool {
pub r#type: ToolType,
pub function: Function,
}

#[derive(Debug, Serialize, Deserialize, Copy, Clone)]
#[derive(Debug, Deserialize, Serialize, Copy, Clone)]
#[serde(rename_all = "snake_case")]
pub enum ToolType {
Function,
Expand Down
6 changes: 3 additions & 3 deletions src/v1/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,23 +93,23 @@ impl_builder_methods!(
user: String
);

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Serialize)]
pub struct CompletionChoice {
pub text: String,
pub index: i64,
pub finish_reason: String,
pub logprobs: Option<LogprobResult>,
}

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Serialize)]
pub struct LogprobResult {
pub tokens: Vec<String>,
pub token_logprobs: Vec<f32>,
pub top_logprobs: Vec<HashMap<String, f32>>,
pub text_offset: Vec<i32>,
}

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Serialize)]
pub struct CompletionResponse {
pub id: String,
pub object: String,
Expand Down
4 changes: 2 additions & 2 deletions src/v1/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ impl_builder_methods!(
top_p: f32
);

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Serialize)]
pub struct EditChoice {
pub text: String,
pub index: i32,
}

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Serialize)]
pub struct EditResponse {
pub object: String,
pub created: i64,
Expand Down
6 changes: 3 additions & 3 deletions src/v1/embedding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::option::Option;

use crate::impl_builder_methods;

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Serialize)]
pub struct EmbeddingData {
pub object: String,
pub embedding: Vec<f32>,
Expand Down Expand Up @@ -33,15 +33,15 @@ impl_builder_methods!(
user: String
);

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Serialize)]
pub struct EmbeddingResponse {
pub object: String,
pub data: Vec<EmbeddingData>,
pub model: String,
pub usage: Usage,
}

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Serialize)]
pub struct Usage {
pub prompt_tokens: i32,
pub total_tokens: i32,
Expand Down
12 changes: 6 additions & 6 deletions src/v1/file.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Serialize)]
pub struct FileData {
pub id: String,
pub oejct: String,
Expand All @@ -10,7 +10,7 @@ pub struct FileData {
pub purpose: String,
}

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Serialize)]
pub struct FileListResponse {
pub object: String,
pub data: Vec<FileData>,
Expand All @@ -28,7 +28,7 @@ impl FileUploadRequest {
}
}

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Serialize)]
pub struct FileUploadResponse {
pub id: String,
pub oejct: String,
Expand All @@ -49,7 +49,7 @@ impl FileDeleteRequest {
}
}

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Serialize)]
pub struct FileDeleteResponse {
pub id: String,
pub oejct: String,
Expand All @@ -67,7 +67,7 @@ impl FileRetrieveRequest {
}
}

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Serialize)]
pub struct FileRetrieveResponse {
pub id: String,
pub oejct: String,
Expand All @@ -88,7 +88,7 @@ impl FileRetrieveContentRequest {
}
}

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Serialize)]
pub struct FileRetrieveContentResponse {
pub id: String,
pub oejct: String,
Expand Down
10 changes: 5 additions & 5 deletions src/v1/fine_tuning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ impl CancelFineTuningJobRequest {
}
}

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Serialize)]
pub struct FineTuningPagination<T> {
pub object: String,
pub data: Vec<T>,
pub has_more: bool,
}

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Serialize)]
pub struct FineTuningJobObject {
pub id: String,
pub created_at: i64,
Expand All @@ -118,14 +118,14 @@ pub struct FineTuningJobObject {
pub validation_file: Option<String>,
}

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Serialize)]
pub struct FineTuningJobError {
pub code: String,
pub message: String,
pub param: Option<String>,
}

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Serialize)]
pub struct FineTuningJobEvent {
pub id: String,
pub created_at: i64,
Expand All @@ -134,7 +134,7 @@ pub struct FineTuningJobEvent {
pub object: String,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct HyperParameters {
#[serde(skip_serializing_if = "Option::is_none")]
pub batch_size: Option<String>,
Expand Down
Loading

0 comments on commit 9b90bf7

Please sign in to comment.