Skip to content

Commit f112151

Browse files
authored
fix(responses): default ResponseTextParam.format during deserialization (#554)
Closes #551
1 parent c9c99e3 commit f112151

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

async-openai/src/types/responses/response.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,7 @@ pub struct ResponseTextParam {
11391139
/// Setting to `{ "type": "json_object" }` enables the older JSON mode, which
11401140
/// ensures the message the model generates is valid JSON. Using `json_schema`
11411141
/// is preferred for models that support it.
1142+
#[serde(default)]
11421143
pub format: TextResponseFormatConfiguration,
11431144

11441145
/// Constrains the verbosity of the model's response. Lower values will result in
@@ -1149,10 +1150,11 @@ pub struct ResponseTextParam {
11491150
pub verbosity: Option<Verbosity>,
11501151
}
11511152

1152-
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
1153+
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Default)]
11531154
#[serde(tag = "type", rename_all = "snake_case")]
11541155
pub enum TextResponseFormatConfiguration {
11551156
/// Default response format. Used to generate text responses.
1157+
#[default]
11561158
Text,
11571159
/// JSON object response format. An older method of generating JSON responses.
11581160
/// Using `json_schema` is recommended for models that support it.

async-openai/tests/responses_input_item_serde.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
use async_openai::types::responses::{
44
EasyInputContent, ImageDetail, InputContent, InputItem, InputRole, Item, MessageItem,
5-
MessageType, OutputItem, ResponseStreamEvent, Role, WebSearchApproximateLocation,
5+
MessageType, OutputItem, ResponseStreamEvent, ResponseTextParam, Role,
6+
TextResponseFormatConfiguration, WebSearchApproximateLocation,
67
WebSearchApproximateLocationType, WebSearchToolCallStatus,
78
};
89
use serde_json::json;
@@ -141,6 +142,15 @@ fn input_item_easy_message_multimodal_without_detail_defaults_and_serializes_can
141142
);
142143
}
143144

145+
#[test]
146+
fn response_text_param_without_format_defaults_to_text() {
147+
let param: ResponseTextParam =
148+
serde_json::from_value(json!({})).expect("deserialize ResponseTextParam without format");
149+
150+
assert_eq!(param.format, TextResponseFormatConfiguration::Text);
151+
assert_eq!(param.verbosity, None);
152+
}
153+
144154
#[test]
145155
fn input_item_strict_message_multimodal_without_detail_defaults() {
146156
let input_item: InputItem = serde_json::from_value(json!({

0 commit comments

Comments
 (0)