Skip to content

Add default value for some response struct #403

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions async-openai/src/types/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -951,10 +951,15 @@ pub struct CreateChatCompletionResponse {
pub system_fingerprint: Option<String>,

/// The object type, which is always `chat.completion`.
#[serde(default="object_default_value")]
pub object: String,
pub usage: Option<CompletionUsage>,
}

pub fn object_default_value()->String{
"chat.completion".to_string()
}

/// Parsed server side events stream until an \[DONE\] is received from server.
pub type ChatCompletionResponseStream =
Pin<Box<dyn Stream<Item = Result<CreateChatCompletionStreamResponse, OpenAIError>> + Send>>;
Expand Down
5 changes: 5 additions & 0 deletions async-openai/src/types/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,15 @@ pub struct CreateCompletionResponse {
pub system_fingerprint: Option<String>,

/// The object type, which is always "text_completion"
#[serde(default="object_default_value")]
pub object: String,
pub usage: Option<CompletionUsage>,
}

pub fn object_default_value()->String{
"text_completion".to_string()
}

/// Parsed server side events stream until an \[DONE\] is received from server.
pub type CompletionResponseStream =
Pin<Box<dyn Stream<Item = Result<CreateCompletionResponse, OpenAIError>> + Send>>;
5 changes: 5 additions & 0 deletions examples/gemini-openai-compatibility/src/gemini_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,16 @@ pub struct GeminiCreateChatCompletionResponse {
/// The model used for the chat completion.
pub model: String,
/// The object type, which is always `chat.completion`.
#[serde(default="object_default_value")]
pub object: String,
/// usage statistics for the entire request.
pub usage: Option<CompletionUsage>,
}

pub fn object_default_value()->String{
"chat.completion".to_string()
}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
pub struct GeminiImagesResponse {
pub data: Vec<std::sync::Arc<Image>>,
Expand Down