| 381 | } |
| 382 | |
| 383 | bool test_tool_call() { |
| 384 | const char* messages = R"([ |
| 385 | {"role": "system", "content": "You are a helpful assistant that can use tools."}, |
| 386 | {"role": "user", "content": "What's the weather in San Francisco?"} |
| 387 | ])"; |
| 388 | |
| 389 | const char* tools = R"([{ |
| 390 | "type": "function", |
| 391 | "function": { |
| 392 | "name": "get_weather", |
| 393 | "description": "Get weather for a location", |
| 394 | "parameters": { |
| 395 | "type": "object", |
| 396 | "properties": { |
| 397 | "location": {"type": "string", "description": "City, State, Country"} |
| 398 | }, |
| 399 | "required": ["location"] |
| 400 | } |
| 401 | } |
| 402 | }])"; |
| 403 | |
| 404 | const char* options_with_force_tools = R"({ |
| 405 | "max_tokens": 256, |
| 406 | "stop_sequences": ["<|im_end|>", "<end_of_turn>"], |
| 407 | "force_tools": true |
| 408 | })"; |
| 409 | |
| 410 | return EngineTestUtils::run_test("TOOL CALL TEST", g_model_path, messages, options_with_force_tools, |
| 411 | [](int result, const StreamingData&, const std::string& response, const Metrics& m) { |
| 412 | bool has_function = response.find("\"function_calls\":[") != std::string::npos; |
| 413 | bool has_tool = has_function && response.find("get_weather") != std::string::npos; |
| 414 | std::cout << "├─ Function call: " << (has_function ? "YES" : "NO") << "\n" |
| 415 | << "├─ Correct tool: " << (has_tool ? "YES" : "NO") << "\n"; |
| 416 | m.print_json(); |
| 417 | return result > 0 && has_function && has_tool; |
| 418 | }, tools, -1, "What's the weather in San Francisco?"); |
| 419 | } |
| 420 | |
| 421 | bool test_multiple_tool_call_invocations() { |
| 422 | const char* messages = R"([ |
no test coverage detected