#![allow(
clippy::expect_used,
clippy::indexing_slicing,
clippy::panic,
clippy::unwrap_used,
clippy::unreachable
)]
mod tools {
use rig_derive::rig_tool;
#[rig_tool(
description = "A public tool for testing visibility",
params(x = "A number")
)]
pub async fn public_adder(x: i32) -> Result<i32, rig::tool::ToolError> {
Ok(x + 1)
}
#[allow(dead_code)]
#[rig_tool(
description = "A private tool for testing visibility",
params(x = "A number")
)]
async fn private_adder(x: i32) -> Result<i32, rig::tool::ToolError> {
Ok(x + 1)
}
pub async fn use_private_tool() -> i32 {
use rig::tool::Tool;
let tool = PrivateAdder;
tool.call(PrivateAdderParameters { x: 99 }).await.unwrap()
}
}
#[tokio::test]
async fn test_pub_tool_accessible_from_outside_module() {
use rig::tool::Tool;
let tool = tools::PublicAdder;
let def = tool.definition(String::default()).await;
assert_eq!(def.name, "public_adder");
assert_eq!(def.description, "A public tool for testing visibility");
let result = tool
.call(tools::PublicAdderParameters { x: 41 })
.await
.unwrap();
assert_eq!(result, serde_json::json!(42));
}
#[test]
fn test_pub_static_accessible_from_outside_module() {
let _ = tools::PUBLIC_ADDER;
}
#[tokio::test]
async fn test_private_tool_accessible_within_module() {
assert_eq!(tools::use_private_tool().await, 100);
}