From b514a7d401882d02b8e543c93f57daaaa43b70b4 Mon Sep 17 00:00:00 2001 From: Collin Brittain Date: Mon, 7 Apr 2025 11:52:12 -0500 Subject: [PATCH] Remove excessive comments and fix broken test --- rig-macros/examples/README.md | 48 ------------------------- rig-macros/examples/async_tool.rs | 6 ---- rig-macros/examples/full.rs | 4 --- rig-macros/examples/simple.rs | 4 --- rig-macros/examples/with_description.rs | 4 --- rig-macros/src/lib.rs | 1 - rig-macros/tests/calculator.rs | 18 +++++----- 7 files changed, 9 insertions(+), 76 deletions(-) delete mode 100644 rig-macros/examples/README.md diff --git a/rig-macros/examples/README.md b/rig-macros/examples/README.md deleted file mode 100644 index e9aaed7..0000000 --- a/rig-macros/examples/README.md +++ /dev/null @@ -1,48 +0,0 @@ -# Rig Tool Macro Examples - -This directory contains examples demonstrating different ways to use the `rig_tool` macro with a rig Agent. - -## Examples - -### 1. Simple Example (`simple.rs`) -Demonstrates the most basic usage of the macro without any attributes. Shows how to create a simple tool that adds two numbers and use it with a rig Agent. - -### 2. With Description (`with_description.rs`) -Shows how to add a description to your tool using the `description` attribute. Implements a calculator that can perform basic arithmetic operations and uses it with a rig Agent. - -### 3. Full Attributes (`full.rs`) -Demonstrates using all available attributes including parameter descriptions. Implements a string processor that can perform various string operations and uses it with a rig Agent. - -### 4. Async Tool (`async_tool.rs`) -Demonstrates how to create and use async tools with a rig Agent, including: -- Basic async operation -- Error handling in async context - -## Running the Examples - -To run any example, use: - -```bash -cargo run --example -``` - -For example: -```bash -cargo run --example simple -cargo run --example with_description -cargo run --example full -cargo run --example async_tool -``` - -## Features Demonstrated - -- Basic tool creation -- Optional attributes -- Parameter descriptions -- Error handling -- Async support -- Static tool instances -- Parameter validation -- Integration with rig Agent -- Natural language interaction with tools -- Tool definitions and schemas diff --git a/rig-macros/examples/async_tool.rs b/rig-macros/examples/async_tool.rs index b44074e..5e8f4da 100644 --- a/rig-macros/examples/async_tool.rs +++ b/rig-macros/examples/async_tool.rs @@ -15,10 +15,8 @@ use tracing_subscriber; ) )] async fn async_operation(input: String, delay_ms: u64) -> Result { - // Simulate some async work tokio::time::sleep(Duration::from_millis(delay_ms)).await; - // Process the input Ok(format!( "Processed after {}ms: {}", delay_ms, @@ -28,10 +26,8 @@ async fn async_operation(input: String, delay_ms: u64) -> Result Result) -> Result { #[tokio::main] async fn main() { - // Initialize tracing tracing_subscriber::fmt().pretty().init(); - // Create an agent with the ADD tool let calculator_agent = providers::openai::Client::from_env() .agent(providers::openai::GPT_4O) .preamble("You are an agent with tools access, always use the tools") @@ -62,7 +59,6 @@ async fn main() { .tool(Add) .build(); - // Test prompts for prompt in [ "What tools do you have?", "Calculate 5 + 3", diff --git a/rig-macros/examples/with_description.rs b/rig-macros/examples/with_description.rs index 7308740..813005e 100644 --- a/rig-macros/examples/with_description.rs +++ b/rig-macros/examples/with_description.rs @@ -29,10 +29,8 @@ fn calculator(x: i32, y: i32, operation: String) -> Result TokenStream { } } - // Generate the implementation let params_struct_name = format_ident!("{}Parameters", struct_name); let static_name = format_ident!("{}", fn_name_str.to_uppercase()); diff --git a/rig-macros/tests/calculator.rs b/rig-macros/tests/calculator.rs index 525c40c..38ed2fe 100644 --- a/rig-macros/tests/calculator.rs +++ b/rig-macros/tests/calculator.rs @@ -74,7 +74,7 @@ async fn test_calculator_tool() { // Test valid operations let test_cases = vec![ ( - serde_json::json!({ + rig::serde_json::json!({ "x": 5, "y": 3, "operation": "add" @@ -82,7 +82,7 @@ async fn test_calculator_tool() { 8, ), ( - serde_json::json!({ + rig::serde_json::json!({ "x": 5, "y": 3, "operation": "subtract" @@ -90,7 +90,7 @@ async fn test_calculator_tool() { 2, ), ( - serde_json::json!({ + rig::serde_json::json!({ "x": 5, "y": 3, "operation": "multiply" @@ -98,7 +98,7 @@ async fn test_calculator_tool() { 15, ), ( - serde_json::json!({ + rig::serde_json::json!({ "x": 6, "y": 2, "operation": "divide" @@ -109,11 +109,11 @@ async fn test_calculator_tool() { for (input, expected) in test_cases { let result = calculator.call(input).await.unwrap(); - assert_eq!(result, serde_json::json!(expected)); + assert_eq!(result, rig::serde_json::json!(expected)); } // Test division by zero - let div_zero = serde_json::json!({ + let div_zero = rig::serde_json::json!({ "x": 5, "y": 0, "operation": "divide" @@ -122,7 +122,7 @@ async fn test_calculator_tool() { assert!(matches!(err, rig::tool::ToolError::ToolCallError(_))); // Test invalid operation - let invalid_op = serde_json::json!({ + let invalid_op = rig::serde_json::json!({ "x": 5, "y": 3, "operation": "power" @@ -133,7 +133,7 @@ async fn test_calculator_tool() { // Test sync calculator let sync_calculator = SyncCalculator::default(); let result = sync_calculator - .call(serde_json::json!({ + .call(rig::serde_json::json!({ "x": 5, "y": 3, "operation": "add" @@ -141,5 +141,5 @@ async fn test_calculator_tool() { .await .unwrap(); - assert_eq!(result, serde_json::json!(8)); + assert_eq!(result, rig::serde_json::json!(8)); }