MCPcopy Create free account
hub / github.com/cactus-compute/cactus / test_tool_call

Function test_tool_call

tests/test_llm.cpp:383–419  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

381}
382
383bool 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
421bool test_multiple_tool_call_invocations() {
422 const char* messages = R"([

Callers 1

mainFunction · 0.70

Calls 2

print_jsonMethod · 0.80
run_testFunction · 0.70

Tested by

no test coverage detected