mirror of
https://github.com/openai/codex.git
synced 2026-05-24 13:04:29 +00:00
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})
69 lines
2.0 KiB
Rust
69 lines
2.0 KiB
Rust
use super::parse_dynamic_tool;
|
|
use crate::JsonSchema;
|
|
use crate::ToolDefinition;
|
|
use codex_protocol::dynamic_tools::DynamicToolSpec;
|
|
use pretty_assertions::assert_eq;
|
|
use std::collections::BTreeMap;
|
|
|
|
#[test]
|
|
fn parse_dynamic_tool_sanitizes_input_schema() {
|
|
let tool = DynamicToolSpec {
|
|
name: "lookup_ticket".to_string(),
|
|
description: "Fetch a ticket".to_string(),
|
|
input_schema: serde_json::json!({
|
|
"properties": {
|
|
"id": {
|
|
"description": "Ticket identifier"
|
|
}
|
|
}
|
|
}),
|
|
defer_loading: false,
|
|
};
|
|
|
|
assert_eq!(
|
|
parse_dynamic_tool(&tool).expect("parse dynamic tool"),
|
|
ToolDefinition {
|
|
name: "lookup_ticket".to_string(),
|
|
description: "Fetch a ticket".to_string(),
|
|
input_schema: JsonSchema::object(
|
|
BTreeMap::from([(
|
|
"id".to_string(),
|
|
JsonSchema::string(Some("Ticket identifier".to_string()),),
|
|
)]),
|
|
/*required*/ None,
|
|
/*additional_properties*/ None
|
|
),
|
|
output_schema: None,
|
|
defer_loading: false,
|
|
}
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn parse_dynamic_tool_preserves_defer_loading() {
|
|
let tool = DynamicToolSpec {
|
|
name: "lookup_ticket".to_string(),
|
|
description: "Fetch a ticket".to_string(),
|
|
input_schema: serde_json::json!({
|
|
"type": "object",
|
|
"properties": {}
|
|
}),
|
|
defer_loading: true,
|
|
};
|
|
|
|
assert_eq!(
|
|
parse_dynamic_tool(&tool).expect("parse dynamic tool"),
|
|
ToolDefinition {
|
|
name: "lookup_ticket".to_string(),
|
|
description: "Fetch a ticket".to_string(),
|
|
input_schema: JsonSchema::object(
|
|
BTreeMap::new(),
|
|
/*required*/ None,
|
|
/*additional_properties*/ None
|
|
),
|
|
output_schema: None,
|
|
defer_loading: true,
|
|
}
|
|
);
|
|
}
|