#[ allow( unused_imports ) ]
use super::*;
#[ test ]
#[ cfg( feature = "integration" ) ]
fn test_function_calling_tool_choice_format()
{
let tools = vec![
the_module::ToolDefinition {
name : "test_tool".to_string(),
description : "A test tool".to_string(),
input_schema : serde_json::json!({
"type": "object",
"properties": {
"input": {"type": "string"}
}
})
}
];
let request = the_module::CreateMessageRequest {
model : "claude-sonnet-4-5-20250929".to_string(),
max_tokens : 100,
messages : vec![the_module::Message::user("Test message".to_string())],
tools : Some(tools),
tool_choice : Some(the_module::ToolChoice::Auto),
stream : None,
system : None,
temperature : Some(0.5),
};
let serialized = serde_json::to_string(&request);
assert!(serialized.is_ok(), "Request should serialize correctly");
let json_value : serde_json::Value = serde_json::from_str(&serialized.unwrap()).unwrap();
assert!(json_value.get("tool_choice").is_some(), "tool_choice should be present");
let tool_choice = &json_value["tool_choice"];
assert!(tool_choice.is_object() || tool_choice.is_string(), "tool_choice should be object or string");
println!("â
ToolChoice serialization format validated");
println!(" Serialized as : {tool_choice}");
}
#[ tokio::test ]
#[ cfg( feature = "integration" ) ]
#[ ignore = "Requires workspace secrets file" ]
async fn test_function_calling_real_api_basic()
{
let client = the_module::Client::from_workspace()
.expect("INTEGRATION: Must have workspace client");
let simple_tool = the_module::ToolDefinition
{
name : "simple_math".to_string(),
description : "Perform simple addition".to_string(),
input_schema : serde_json::json!({
"type": "object",
"properties": {
"a": {"type": "number", "description": "First number"},
"b": {"type": "number", "description": "Second number"}
},
"required": ["a", "b"]
})
};
let request = the_module::CreateMessageRequest
{
model : "claude-sonnet-4-5-20250929".to_string(),
max_tokens : 200,
messages : vec![
the_module::Message::user("What is 5 + 3?".to_string())
],
tools : Some(vec![simple_tool]),
tool_choice : Some(the_module::ToolChoice::Auto),
stream : None,
system : Some( vec![ the_module::SystemContent::text( "You are a helpful assistant." ) ] ),
temperature : Some(0.3),
};
let result = client.create_message(request).await;
if let Err(e) = &result
{
let error_string = e.to_string().to_lowercase();
assert!(
!error_string.contains("tool_choice") || !error_string.contains("dictionary"),
"Should not fail with tool_choice format error : {e}"
);
}
if let Ok(response) = result
{
assert!(!response.id.is_empty(), "Response should have ID");
assert!(!response.content.is_empty(), "Response should have content");
println!("â
Function calling API test passed");
println!(" Response ID: {}", response.id);
println!(" Content items : {}", response.content.len());
} else {
println!("âšī¸ Function calling test failed for non-format reasons - acceptable");
}
}