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

Function get_weather

examples/tool_calling_multistep.cpp:56–74  ·  view source on GitHub ↗

Tool: Get weather for a location

Source from the content-addressed store, hash-verified

54
55// Tool: Get weather for a location
56ai::JsonValue get_weather(const ai::JsonValue& args,
57 const ai::ToolExecutionContext& context) {
58 std::string location = args["location"].get<std::string>();
59
60 std::cout << "🌤️ Getting weather for: " << location << std::endl;
61
62 // Simulate weather API call
63 std::srand(std::time(nullptr) + location.length()); // Add some variety
64 int temperature = 50 + (std::rand() % 50);
65
66 std::vector<std::string> conditions = {"Sunny", "Cloudy", "Rainy",
67 "Partly cloudy"};
68 std::string condition = conditions[std::rand() % conditions.size()];
69
70 return ai::JsonValue{{"location", location},
71 {"temperature", temperature},
72 {"condition", condition},
73 {"unit", "Fahrenheit"}};
74}
75
76// Tool: Send email notification
77ai::JsonValue send_email(const ai::JsonValue& args,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected