mirror of
https://github.com/openai/codex.git
synced 2026-04-28 16:45:54 +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:
@@ -20,14 +20,10 @@ fn augment_tool_spec_for_code_mode_augments_function_tools() {
|
||||
description: "Look up an order".to_string(),
|
||||
strict: false,
|
||||
defer_loading: Some(true),
|
||||
parameters: JsonSchema::Object {
|
||||
properties: BTreeMap::from([(
|
||||
parameters: JsonSchema::object(BTreeMap::from([(
|
||||
"order_id".to_string(),
|
||||
JsonSchema::String { description: None },
|
||||
)]),
|
||||
required: Some(vec!["order_id".to_string()]),
|
||||
additional_properties: Some(AdditionalProperties::Boolean(false)),
|
||||
},
|
||||
JsonSchema::string(/*description*/ None),
|
||||
)]), Some(vec!["order_id".to_string()]), Some(AdditionalProperties::Boolean(false))),
|
||||
output_schema: Some(json!({
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -41,14 +37,10 @@ fn augment_tool_spec_for_code_mode_augments_function_tools() {
|
||||
description: "Look up an order\n\nexec tool declaration:\n```ts\ndeclare const tools: { lookup_order(args: { order_id: string; }): Promise<{ ok: boolean; }>; };\n```".to_string(),
|
||||
strict: false,
|
||||
defer_loading: Some(true),
|
||||
parameters: JsonSchema::Object {
|
||||
properties: BTreeMap::from([(
|
||||
parameters: JsonSchema::object(BTreeMap::from([(
|
||||
"order_id".to_string(),
|
||||
JsonSchema::String { description: None },
|
||||
)]),
|
||||
required: Some(vec!["order_id".to_string()]),
|
||||
additional_properties: Some(AdditionalProperties::Boolean(false)),
|
||||
},
|
||||
JsonSchema::string(/*description*/ None),
|
||||
)]), Some(vec!["order_id".to_string()]), Some(AdditionalProperties::Boolean(false))),
|
||||
output_schema: Some(json!({
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -114,11 +106,11 @@ fn tool_spec_to_code_mode_tool_definition_skips_unsupported_variants() {
|
||||
tool_spec_to_code_mode_tool_definition(&ToolSpec::ToolSearch {
|
||||
execution: "sync".to_string(),
|
||||
description: "Search".to_string(),
|
||||
parameters: JsonSchema::Object {
|
||||
properties: BTreeMap::new(),
|
||||
required: None,
|
||||
additional_properties: None,
|
||||
},
|
||||
parameters: JsonSchema::object(
|
||||
BTreeMap::new(),
|
||||
/*required*/ None,
|
||||
/*additional_properties*/ None
|
||||
),
|
||||
}),
|
||||
None
|
||||
);
|
||||
@@ -137,44 +129,32 @@ fn create_wait_tool_matches_expected_spec() {
|
||||
),
|
||||
strict: false,
|
||||
defer_loading: None,
|
||||
parameters: JsonSchema::Object {
|
||||
properties: BTreeMap::from([
|
||||
parameters: JsonSchema::object(BTreeMap::from([
|
||||
(
|
||||
"cell_id".to_string(),
|
||||
JsonSchema::String {
|
||||
description: Some("Identifier of the running exec cell.".to_string()),
|
||||
},
|
||||
JsonSchema::string(Some("Identifier of the running exec cell.".to_string()),),
|
||||
),
|
||||
(
|
||||
"max_tokens".to_string(),
|
||||
JsonSchema::Number {
|
||||
description: Some(
|
||||
JsonSchema::number(Some(
|
||||
"Maximum number of output tokens to return for this wait call."
|
||||
.to_string(),
|
||||
),
|
||||
},
|
||||
),),
|
||||
),
|
||||
(
|
||||
"terminate".to_string(),
|
||||
JsonSchema::Boolean {
|
||||
description: Some(
|
||||
JsonSchema::boolean(Some(
|
||||
"Whether to terminate the running exec cell.".to_string(),
|
||||
),
|
||||
},
|
||||
),),
|
||||
),
|
||||
(
|
||||
"yield_time_ms".to_string(),
|
||||
JsonSchema::Number {
|
||||
description: Some(
|
||||
JsonSchema::number(Some(
|
||||
"How long to wait (in milliseconds) for more output before yielding again."
|
||||
.to_string(),
|
||||
),
|
||||
},
|
||||
),),
|
||||
),
|
||||
]),
|
||||
required: Some(vec!["cell_id".to_string()]),
|
||||
additional_properties: Some(false.into()),
|
||||
},
|
||||
]), Some(vec!["cell_id".to_string()]), Some(false.into())),
|
||||
output_schema: None,
|
||||
})
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user