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

Method buildStreamingResponse

tests/utils/mock_anthropic_client.cpp:222–256  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

220}
221
222std::vector<std::string> AnthropicResponseBuilder::buildStreamingResponse(
223 const std::string& content) {
224 std::vector<std::string> events;
225
226 // Message start event
227 events.push_back(
228 "data: "
229 "{\"type\":\"message_start\",\"message\":{\"id\":\"msg_stream\",\"type\":"
230 "\"message\",\"role\":\"assistant\",\"content\":[]}}\n\n");
231
232 // Content block start
233 events.push_back(
234 "data: "
235 "{\"type\":\"content_block_start\",\"index\":0,\"content_block\":{"
236 "\"type\":\"text\",\"text\":\"\"}}\n\n");
237
238 // Split content into chunks
239 const size_t chunk_size = 5;
240 for (size_t i = 0; i < content.length(); i += chunk_size) {
241 std::string chunk = content.substr(i, chunk_size);
242 nlohmann::json event = {
243 {"type", "content_block_delta"},
244 {"index", 0},
245 {"delta", {{"type", "text_delta"}, {"text", chunk}}}};
246 events.push_back("data: " + event.dump() + "\n\n");
247 }
248
249 // Content block stop
250 events.push_back("data: {\"type\":\"content_block_stop\",\"index\":0}\n\n");
251
252 // Message stop event
253 events.push_back("data: {\"type\":\"message_stop\"}\n\n");
254
255 return events;
256}
257
258std::string AnthropicResponseBuilder::buildRateLimitResponse() {
259 return buildErrorResponse(429, "rate_limit_error", "Rate limit exceeded");

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected