mirror of
https://github.com/openai/codex.git
synced 2026-04-25 23:24:55 +00:00
Support anyOf and enum in JsonSchema (#16875)
This brings us into better alignment with the JSON schema subset that is supported in <https://developers.openai.com/api/docs/guides/structured-outputs#supported-schemas>, and also allows us to render richer function signatures in code mode (e.g., anyOf{null, OtherObjectType})
This commit is contained in:
@@ -12,71 +12,60 @@ pub fn create_request_user_input_tool(description: String) -> ToolSpec {
|
||||
let option_props = BTreeMap::from([
|
||||
(
|
||||
"label".to_string(),
|
||||
JsonSchema::String {
|
||||
description: Some("User-facing label (1-5 words).".to_string()),
|
||||
},
|
||||
JsonSchema::string(Some("User-facing label (1-5 words).".to_string())),
|
||||
),
|
||||
(
|
||||
"description".to_string(),
|
||||
JsonSchema::String {
|
||||
description: Some(
|
||||
"One short sentence explaining impact/tradeoff if selected.".to_string(),
|
||||
),
|
||||
},
|
||||
JsonSchema::string(Some(
|
||||
"One short sentence explaining impact/tradeoff if selected.".to_string(),
|
||||
)),
|
||||
),
|
||||
]);
|
||||
|
||||
let options_schema = JsonSchema::Array {
|
||||
description: Some(
|
||||
let options_schema = JsonSchema::array(JsonSchema::object(
|
||||
option_props,
|
||||
Some(vec!["label".to_string(), "description".to_string()]),
|
||||
Some(false.into()),
|
||||
), Some(
|
||||
"Provide 2-3 mutually exclusive choices. Put the recommended option first and suffix its label with \"(Recommended)\". Do not include an \"Other\" option in this list; the client will add a free-form \"Other\" option automatically."
|
||||
.to_string(),
|
||||
),
|
||||
items: Box::new(JsonSchema::Object {
|
||||
properties: option_props,
|
||||
required: Some(vec!["label".to_string(), "description".to_string()]),
|
||||
additional_properties: Some(false.into()),
|
||||
}),
|
||||
};
|
||||
));
|
||||
|
||||
let question_props = BTreeMap::from([
|
||||
(
|
||||
"id".to_string(),
|
||||
JsonSchema::String {
|
||||
description: Some(
|
||||
"Stable identifier for mapping answers (snake_case).".to_string(),
|
||||
),
|
||||
},
|
||||
JsonSchema::string(Some(
|
||||
"Stable identifier for mapping answers (snake_case).".to_string(),
|
||||
)),
|
||||
),
|
||||
(
|
||||
"header".to_string(),
|
||||
JsonSchema::String {
|
||||
description: Some(
|
||||
"Short header label shown in the UI (12 or fewer chars).".to_string(),
|
||||
),
|
||||
},
|
||||
JsonSchema::string(Some(
|
||||
"Short header label shown in the UI (12 or fewer chars).".to_string(),
|
||||
)),
|
||||
),
|
||||
(
|
||||
"question".to_string(),
|
||||
JsonSchema::String {
|
||||
description: Some("Single-sentence prompt shown to the user.".to_string()),
|
||||
},
|
||||
JsonSchema::string(Some(
|
||||
"Single-sentence prompt shown to the user.".to_string(),
|
||||
)),
|
||||
),
|
||||
("options".to_string(), options_schema),
|
||||
]);
|
||||
|
||||
let questions_schema = JsonSchema::Array {
|
||||
description: Some("Questions to show the user. Prefer 1 and do not exceed 3".to_string()),
|
||||
items: Box::new(JsonSchema::Object {
|
||||
properties: question_props,
|
||||
required: Some(vec![
|
||||
let questions_schema = JsonSchema::array(
|
||||
JsonSchema::object(
|
||||
question_props,
|
||||
Some(vec![
|
||||
"id".to_string(),
|
||||
"header".to_string(),
|
||||
"question".to_string(),
|
||||
"options".to_string(),
|
||||
]),
|
||||
additional_properties: Some(false.into()),
|
||||
}),
|
||||
};
|
||||
Some(false.into()),
|
||||
),
|
||||
Some("Questions to show the user. Prefer 1 and do not exceed 3".to_string()),
|
||||
);
|
||||
|
||||
let properties = BTreeMap::from([("questions".to_string(), questions_schema)]);
|
||||
|
||||
@@ -85,11 +74,11 @@ pub fn create_request_user_input_tool(description: String) -> ToolSpec {
|
||||
description,
|
||||
strict: false,
|
||||
defer_loading: None,
|
||||
parameters: JsonSchema::Object {
|
||||
parameters: JsonSchema::object(
|
||||
properties,
|
||||
required: Some(vec!["questions".to_string()]),
|
||||
additional_properties: Some(false.into()),
|
||||
},
|
||||
Some(vec!["questions".to_string()]),
|
||||
Some(false.into()),
|
||||
),
|
||||
output_schema: None,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user