| 119 | } |
| 120 | |
| 121 | void test_multi_step() { |
| 122 | std::cout << "\n=== Testing Multi-Step Tool Calling ===\n"; |
| 123 | |
| 124 | auto client = ai::openai::create_client(); |
| 125 | |
| 126 | // Create tools for multi-step |
| 127 | ai::ToolSet tools = { |
| 128 | {"get_number", |
| 129 | ai::create_simple_tool( |
| 130 | "get_number", "Get a number for calculation", |
| 131 | {{"description", "string"}}, |
| 132 | [](const ai::JsonValue& args, |
| 133 | const ai::ToolExecutionContext& context) -> ai::JsonValue { |
| 134 | std::string desc = args["description"].get<std::string>(); |
| 135 | std::cout << "🔢 Getting number for: " << desc << std::endl; |
| 136 | return ai::JsonValue{{"number", 42}}; |
| 137 | })}, |
| 138 | {"calculate", |
| 139 | ai::create_simple_tool( |
| 140 | "calculate", "Perform a calculation", |
| 141 | {{"operation", "string"}, {"a", "number"}, {"b", "number"}}, |
| 142 | [](const ai::JsonValue& args, |
| 143 | const ai::ToolExecutionContext& context) -> ai::JsonValue { |
| 144 | std::string op = args["operation"].get<std::string>(); |
| 145 | double a = args["a"].get<double>(); |
| 146 | double b = args["b"].get<double>(); |
| 147 | |
| 148 | std::cout << "🧮 Calculating: " << a << " " << op << " " << b |
| 149 | << std::endl; |
| 150 | |
| 151 | double result = 0; |
| 152 | if (op == "add") |
| 153 | result = a + b; |
| 154 | else if (op == "multiply") |
| 155 | result = a * b; |
| 156 | |
| 157 | return ai::JsonValue{{"result", result}}; |
| 158 | })}}; |
| 159 | |
| 160 | ai::GenerateOptions options; |
| 161 | options.model = ai::openai::models::kGpt54; |
| 162 | options.prompt = "Get a number and then multiply it by 2. Show me the steps."; |
| 163 | options.tools = tools; |
| 164 | options.max_steps = 5; // Enable multi-step |
| 165 | options.max_tokens = 200; |
| 166 | |
| 167 | std::cout << "Making multi-step request...\n"; |
| 168 | |
| 169 | auto result = client.generate_text(options); |
| 170 | |
| 171 | if (result) { |
| 172 | std::cout << "✅ Multi-step request successful!\n"; |
| 173 | std::cout << "Final response: " << result.text << "\n"; |
| 174 | std::cout << "Total steps: " << result.steps.size() << "\n"; |
| 175 | std::cout << "Total tool calls: " << result.get_all_tool_calls().size() |
| 176 | << "\n"; |
| 177 | std::cout << "Total tool results: " << result.get_all_tool_results().size() |
| 178 | << "\n"; |
no test coverage detected