use crate::types::{CustomTool, ToolChoice};
use serde_json::Value;
pub fn json_schema_tool(
name: impl Into<String>,
description: impl Into<String>,
schema: Value,
) -> CustomTool {
CustomTool::new(name, description, schema).programmatic()
}
pub fn force_tool(tool_name: impl Into<String>) -> ToolChoice {
ToolChoice::Tool {
name: tool_name.into(),
disable_parallel_tool_use: None,
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_json_schema_tool() {
let schema = serde_json::json!({
"type": "object",
"properties": {
"name": {"type": "string"}
}
});
let tool = json_schema_tool("test_tool", "Test description", schema.clone());
assert_eq!(tool.name, "test_tool");
assert_eq!(tool.description, "Test description");
assert_eq!(tool.input_schema, schema);
assert_eq!(tool.disable_user_input, Some(true));
}
#[test]
fn test_force_tool() {
let choice = force_tool("my_tool");
match choice {
ToolChoice::Tool { name, .. } => assert_eq!(name, "my_tool"),
_ => panic!("Expected Tool variant"),
}
}
}