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

Function process_file_async

examples/tool_calling_async.cpp:125–164  ·  view source on GitHub ↗

Async tool: File processing simulation

Source from the content-addressed store, hash-verified

123
124// Async tool: File processing simulation
125std::future<ai::JsonValue> process_file_async(
126 const ai::JsonValue& args,
127 const ai::ToolExecutionContext& context) {
128 std::string filename = args["filename"].get<std::string>();
129 std::string operation = args["operation"].get<std::string>();
130
131 return std::async(std::launch::async, [filename, operation]() {
132 std::cout << "📄 Processing file: " << filename
133 << " (operation: " << operation << ", async)..." << std::endl;
134
135 // Simulate file processing time based on operation
136 int delay_ms = 500;
137 if (operation == "compress")
138 delay_ms = 1200;
139 else if (operation == "analyze")
140 delay_ms = 900;
141 else if (operation == "backup")
142 delay_ms = 600;
143
144 std::this_thread::sleep_for(std::chrono::milliseconds(delay_ms));
145
146 ai::JsonValue result = {{"filename", filename},
147 {"operation", operation},
148 {"status", "completed"},
149 {"processing_time_ms", delay_ms}};
150
151 if (operation == "analyze") {
152 result["file_size"] = "2.5 MB";
153 result["line_count"] = 1250;
154 } else if (operation == "compress") {
155 result["original_size"] = "5.0 MB";
156 result["compressed_size"] = "1.8 MB";
157 result["compression_ratio"] = "36%";
158 }
159
160 std::cout << "📄 File processing completed: " << filename << std::endl;
161
162 return result;
163 });
164}
165
166int main() {
167 std::cout << "AI SDK C++ - Async Tool Calling Example\n";

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected