32 lines
1.3 KiB
Rust
32 lines
1.3 KiB
Rust
use rtx_llm_tools::tools::{ParameterType, ToolDefinition, ToolExecutor, ToolParameter};
|
|
use serde_json::Value;
|
|
use std::collections::HashMap;
|
|
|
|
#[tokio::test]
|
|
async fn test_basic_tool_execution() {
|
|
let mut executor = ToolExecutor::new("test_executor");
|
|
|
|
let calculator = ToolDefinition::new(
|
|
"calculator",
|
|
"Basic arithmetic calculator",
|
|
vec![
|
|
ToolParameter::new("operation", ParameterType::String, true)
|
|
.with_description("The arithmetic operation to perform")
|
|
.with_enum_values(vec!["add", "subtract", "multiply", "divide"]),
|
|
ToolParameter::new("a", ParameterType::Number, true).with_description("First number"),
|
|
ToolParameter::new("b", ParameterType::Number, true).with_description("Second number"),
|
|
],
|
|
);
|
|
|
|
executor.register_tool(calculator).await.unwrap();
|
|
|
|
let mut params = HashMap::new();
|
|
params.insert("operation".to_string(), Value::String("add".to_string()));
|
|
params.insert("a".to_string(), Value::Number(serde_json::Number::from(10)));
|
|
params.insert("b".to_string(), Value::Number(serde_json::Number::from(5)));
|
|
|
|
let result = executor.execute("calculator", params).await.unwrap();
|
|
assert!(result.success);
|
|
assert_eq!(result.output, "15");
|
|
}
|