Test single tool calling
| 163 | |
| 164 | // Test single tool calling |
| 165 | TEST_P(ToolCallingIntegrationTest, SingleToolCall) { |
| 166 | if (!use_real_api_) { |
| 167 | GTEST_SKIP() << "No API key set for " << GetParam(); |
| 168 | } |
| 169 | |
| 170 | GenerateOptions options(model_, "What's the weather like in San Francisco?"); |
| 171 | options.tools = tools_; |
| 172 | options.max_tokens = 200; |
| 173 | |
| 174 | auto result = client_->generate_text(options); |
| 175 | |
| 176 | // Result should be successful, though text might be empty if only tool calls |
| 177 | // are returned |
| 178 | EXPECT_TRUE(result.is_success()) |
| 179 | << "Expected successful result but got error: " << result.error_message(); |
| 180 | EXPECT_FALSE(result.error.has_value()) |
| 181 | << "Expected no error in successful result"; |
| 182 | |
| 183 | // Should have called the weather tool |
| 184 | EXPECT_TRUE(result.has_tool_calls()); |
| 185 | EXPECT_GT(result.tool_calls.size(), 0); |
| 186 | |
| 187 | auto weather_call = std::find_if( |
| 188 | result.tool_calls.begin(), result.tool_calls.end(), |
| 189 | [](const ToolCall& call) { return call.tool_name == "weather"; }); |
| 190 | EXPECT_NE(weather_call, result.tool_calls.end()); |
| 191 | |
| 192 | if (weather_call != result.tool_calls.end()) { |
| 193 | EXPECT_TRUE(weather_call->arguments.contains("location")); |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | // Test multiple tool calls in one request |
| 198 | TEST_P(ToolCallingIntegrationTest, MultipleDifferentToolCalls) { |
nothing calls this directly
no test coverage detected