mirror of
https://github.com/openai/codex.git
synced 2026-05-05 13:51:29 +03: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:
@@ -1,4 +1,5 @@
|
||||
use super::*;
|
||||
use crate::JsonSchema;
|
||||
use pretty_assertions::assert_eq;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
@@ -13,46 +14,34 @@ fn list_dir_tool_matches_expected_spec() {
|
||||
.to_string(),
|
||||
strict: false,
|
||||
defer_loading: None,
|
||||
parameters: JsonSchema::Object {
|
||||
properties: BTreeMap::from([
|
||||
parameters: JsonSchema::object(BTreeMap::from([
|
||||
(
|
||||
"depth".to_string(),
|
||||
JsonSchema::Number {
|
||||
description: Some(
|
||||
"The maximum directory depth to traverse. Must be 1 or greater."
|
||||
.to_string(),
|
||||
),
|
||||
},
|
||||
JsonSchema::number(Some(
|
||||
"The maximum directory depth to traverse. Must be 1 or greater."
|
||||
.to_string(),
|
||||
)),
|
||||
),
|
||||
(
|
||||
"dir_path".to_string(),
|
||||
JsonSchema::String {
|
||||
description: Some(
|
||||
"Absolute path to the directory to list.".to_string(),
|
||||
),
|
||||
},
|
||||
JsonSchema::string(Some(
|
||||
"Absolute path to the directory to list.".to_string(),
|
||||
)),
|
||||
),
|
||||
(
|
||||
"limit".to_string(),
|
||||
JsonSchema::Number {
|
||||
description: Some(
|
||||
"The maximum number of entries to return.".to_string(),
|
||||
),
|
||||
},
|
||||
JsonSchema::number(Some(
|
||||
"The maximum number of entries to return.".to_string(),
|
||||
)),
|
||||
),
|
||||
(
|
||||
"offset".to_string(),
|
||||
JsonSchema::Number {
|
||||
description: Some(
|
||||
"The entry number to start listing from. Must be 1 or greater."
|
||||
.to_string(),
|
||||
),
|
||||
},
|
||||
JsonSchema::number(Some(
|
||||
"The entry number to start listing from. Must be 1 or greater."
|
||||
.to_string(),
|
||||
)),
|
||||
),
|
||||
]),
|
||||
required: Some(vec!["dir_path".to_string()]),
|
||||
additional_properties: Some(false.into()),
|
||||
},
|
||||
]), Some(vec!["dir_path".to_string()]), Some(false.into())),
|
||||
output_schema: None,
|
||||
})
|
||||
);
|
||||
@@ -68,69 +57,51 @@ fn test_sync_tool_matches_expected_spec() {
|
||||
.to_string(),
|
||||
strict: false,
|
||||
defer_loading: None,
|
||||
parameters: JsonSchema::Object {
|
||||
properties: BTreeMap::from([
|
||||
parameters: JsonSchema::object(BTreeMap::from([
|
||||
(
|
||||
"barrier".to_string(),
|
||||
JsonSchema::Object {
|
||||
properties: BTreeMap::from([
|
||||
JsonSchema::object(
|
||||
BTreeMap::from([
|
||||
(
|
||||
"id".to_string(),
|
||||
JsonSchema::String {
|
||||
description: Some(
|
||||
"Identifier shared by concurrent calls that should rendezvous"
|
||||
.to_string(),
|
||||
),
|
||||
},
|
||||
JsonSchema::string(Some(
|
||||
"Identifier shared by concurrent calls that should rendezvous"
|
||||
.to_string(),
|
||||
)),
|
||||
),
|
||||
(
|
||||
"participants".to_string(),
|
||||
JsonSchema::Number {
|
||||
description: Some(
|
||||
"Number of tool calls that must arrive before the barrier opens"
|
||||
.to_string(),
|
||||
),
|
||||
},
|
||||
JsonSchema::number(Some(
|
||||
"Number of tool calls that must arrive before the barrier opens"
|
||||
.to_string(),
|
||||
)),
|
||||
),
|
||||
(
|
||||
"timeout_ms".to_string(),
|
||||
JsonSchema::Number {
|
||||
description: Some(
|
||||
"Maximum time in milliseconds to wait at the barrier"
|
||||
.to_string(),
|
||||
),
|
||||
},
|
||||
JsonSchema::number(Some(
|
||||
"Maximum time in milliseconds to wait at the barrier"
|
||||
.to_string(),
|
||||
)),
|
||||
),
|
||||
]),
|
||||
required: Some(vec![
|
||||
"id".to_string(),
|
||||
"participants".to_string(),
|
||||
]),
|
||||
additional_properties: Some(false.into()),
|
||||
},
|
||||
Some(vec!["id".to_string(), "participants".to_string()]),
|
||||
Some(false.into()),
|
||||
),
|
||||
),
|
||||
(
|
||||
"sleep_after_ms".to_string(),
|
||||
JsonSchema::Number {
|
||||
description: Some(
|
||||
"Optional delay in milliseconds after completing the barrier"
|
||||
.to_string(),
|
||||
),
|
||||
},
|
||||
JsonSchema::number(Some(
|
||||
"Optional delay in milliseconds after completing the barrier"
|
||||
.to_string(),
|
||||
)),
|
||||
),
|
||||
(
|
||||
"sleep_before_ms".to_string(),
|
||||
JsonSchema::Number {
|
||||
description: Some(
|
||||
"Optional delay in milliseconds before any other action"
|
||||
.to_string(),
|
||||
),
|
||||
},
|
||||
JsonSchema::number(Some(
|
||||
"Optional delay in milliseconds before any other action".to_string(),
|
||||
)),
|
||||
),
|
||||
]),
|
||||
required: None,
|
||||
additional_properties: Some(false.into()),
|
||||
},
|
||||
]), /*required*/ None, Some(false.into())),
|
||||
output_schema: None,
|
||||
})
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user