Skip to content

Commit c95098b

Browse files
committed
Add skip_serializing_if to more option types
Signed-off-by: John Howard <[email protected]>
1 parent 483c84f commit c95098b

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

async-openai/src/types/chat.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ pub enum CompletionFinishReason {
4343
pub struct Choice {
4444
pub text: String,
4545
pub index: u32,
46+
#[serde(skip_serializing_if = "Option::is_none")]
4647
pub logprobs: Option<Logprobs>,
48+
#[serde(skip_serializing_if = "Option::is_none")]
4749
pub finish_reason: Option<CompletionFinishReason>,
4850
}
4951

@@ -94,8 +96,10 @@ pub struct CompletionUsage {
9496
/// Total number of tokens used in the request (prompt + completion).
9597
pub total_tokens: u32,
9698
/// Breakdown of tokens used in the prompt.
99+
#[serde(skip_serializing_if = "Option::is_none")]
97100
pub prompt_tokens_details: Option<PromptTokensDetails>,
98101
/// Breakdown of tokens used in a completion.
102+
#[serde(skip_serializing_if = "Option::is_none")]
99103
pub completion_tokens_details: Option<CompletionTokensDetails>,
100104
}
101105

@@ -414,21 +418,26 @@ pub struct ChatCompletionResponseMessageAudio {
414418
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
415419
pub struct ChatCompletionResponseMessage {
416420
/// The contents of the message.
421+
#[serde(skip_serializing_if = "Option::is_none")]
417422
pub content: Option<String>,
418423
/// The refusal message generated by the model.
424+
#[serde(skip_serializing_if = "Option::is_none")]
419425
pub refusal: Option<String>,
420426
/// The tool calls generated by the model, such as function calls.
427+
#[serde(skip_serializing_if = "Option::is_none")]
421428
pub tool_calls: Option<Vec<ChatCompletionMessageToolCall>>,
422429

423430
/// The role of the author of this message.
424431
pub role: Role,
425432

426433
/// Deprecated and replaced by `tool_calls`.
427434
/// The name and arguments of a function that should be called, as generated by the model.
435+
#[serde(skip_serializing_if = "Option::is_none")]
428436
#[deprecated]
429437
pub function_call: Option<FunctionCall>,
430438

431439
/// If the audio output modality is requested, this object contains data about the audio response from the model. [Learn more](https://platform.openai.com/docs/guides/audio).
440+
#[serde(skip_serializing_if = "Option::is_none")]
432441
pub audio: Option<ChatCompletionResponseMessageAudio>,
433442
}
434443

@@ -927,8 +936,10 @@ pub struct ChatChoice {
927936
/// `length` if the maximum number of tokens specified in the request was reached,
928937
/// `content_filter` if content was omitted due to a flag from our content filters,
929938
/// `tool_calls` if the model called a tool, or `function_call` (deprecated) if the model called a function.
939+
#[serde(skip_serializing_if = "Option::is_none")]
930940
pub finish_reason: Option<FinishReason>,
931941
/// Log probability information for the choice.
942+
#[serde(skip_serializing_if = "Option::is_none")]
932943
pub logprobs: Option<ChatChoiceLogprobs>,
933944
}
934945

@@ -944,10 +955,12 @@ pub struct CreateChatCompletionResponse {
944955
/// The model used for the chat completion.
945956
pub model: String,
946957
/// The service tier used for processing the request. This field is only included if the `service_tier` parameter is specified in the request.
958+
#[serde(skip_serializing_if = "Option::is_none")]
947959
pub service_tier: Option<ServiceTierResponse>,
948960
/// This fingerprint represents the backend configuration that the model runs with.
949961
///
950962
/// Can be used in conjunction with the `seed` request parameter to understand when backend changes have been made that might impact determinism.
963+
#[serde(skip_serializing_if = "Option::is_none")]
951964
pub system_fingerprint: Option<String>,
952965

953966
/// The object type, which is always `chat.completion`.
@@ -1011,8 +1024,10 @@ pub struct ChatChoiceStream {
10111024
/// content filters,
10121025
/// `tool_calls` if the model called a tool, or `function_call`
10131026
/// (deprecated) if the model called a function.
1027+
#[serde(skip_serializing_if = "Option::is_none")]
10141028
pub finish_reason: Option<FinishReason>,
10151029
/// Log probability information for the choice.
1030+
#[serde(skip_serializing_if = "Option::is_none")]
10161031
pub logprobs: Option<ChatChoiceLogprobs>,
10171032
}
10181033

0 commit comments

Comments
 (0)