MCPcopy Create free account
hub / github.com/ClickHouse/ai-sdk-cpp / get_weather

Function get_weather

examples/tool_calling_basic.cpp:25–40  ·  view source on GitHub ↗

Example tool function: Get weather information

Source from the content-addressed store, hash-verified

23
24// Example tool function: Get weather information
25ai::JsonValue get_weather(const ai::JsonValue& args,
26 const ai::ToolExecutionContext& context) {
27 std::string location = args["location"].get<std::string>();
28
29 // Simulate weather API call
30 std::srand(std::time(nullptr));
31 int temperature = 60 + (std::rand() % 40); // Random temp between 60-100°F
32
33 ai::JsonValue result = {{"location", location},
34 {"temperature", temperature},
35 {"unit", "Fahrenheit"},
36 {"condition", "Partly cloudy"}};
37
38 std::cout << "🌤️ Weather tool called for: " << location << std::endl;
39 return result;
40}
41
42// Example tool function: Get city attractions
43ai::JsonValue get_city_attractions(const ai::JsonValue& args,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected