Skip to content

Commit b758b55

Browse files
authored
Add skip_serializing_if to more option types (#412)
Signed-off-by: John Howard <[email protected]>
1 parent 6c98fb9 commit b758b55

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

@@ -931,8 +940,10 @@ pub struct ChatChoice {
931940
/// `length` if the maximum number of tokens specified in the request was reached,
932941
/// `content_filter` if content was omitted due to a flag from our content filters,
933942
/// `tool_calls` if the model called a tool, or `function_call` (deprecated) if the model called a function.
943+
#[serde(skip_serializing_if = "Option::is_none")]
934944
pub finish_reason: Option<FinishReason>,
935945
/// Log probability information for the choice.
946+
#[serde(skip_serializing_if = "Option::is_none")]
936947
pub logprobs: Option<ChatChoiceLogprobs>,
937948
}
938949

@@ -948,10 +959,12 @@ pub struct CreateChatCompletionResponse {
948959
/// The model used for the chat completion.
949960
pub model: String,
950961
/// The service tier used for processing the request. This field is only included if the `service_tier` parameter is specified in the request.
962+
#[serde(skip_serializing_if = "Option::is_none")]
951963
pub service_tier: Option<ServiceTierResponse>,
952964
/// This fingerprint represents the backend configuration that the model runs with.
953965
///
954966
/// Can be used in conjunction with the `seed` request parameter to understand when backend changes have been made that might impact determinism.
967+
#[serde(skip_serializing_if = "Option::is_none")]
955968
pub system_fingerprint: Option<String>,
956969

957970
/// The object type, which is always `chat.completion`.
@@ -1015,8 +1028,10 @@ pub struct ChatChoiceStream {
10151028
/// content filters,
10161029
/// `tool_calls` if the model called a tool, or `function_call`
10171030
/// (deprecated) if the model called a function.
1031+
#[serde(skip_serializing_if = "Option::is_none")]
10181032
pub finish_reason: Option<FinishReason>,
10191033
/// Log probability information for the choice.
1034+
#[serde(skip_serializing_if = "Option::is_none")]
10201035
pub logprobs: Option<ChatChoiceLogprobs>,
10211036
}
10221037

0 commit comments

Comments
 (0)