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

Method buildSuccessResponse

tests/utils/mock_openai_client.cpp:166–188  ·  view source on GitHub ↗

ResponseBuilder implementation

Source from the content-addressed store, hash-verified

164
165// ResponseBuilder implementation
166std::string ResponseBuilder::buildSuccessResponse(const std::string& content,
167 const std::string& model,
168 int prompt_tokens,
169 int completion_tokens) {
170 nlohmann::json response = {
171 {"id", "chatcmpl-test123"},
172 {"object", "chat.completion"},
173 {"created", 1234567890},
174 {"model", model},
175 {"system_fingerprint", "fp_test123"},
176 {"choices",
177 nlohmann::json::array(
178 {{{"index", 0},
179 {"message", {{"role", "assistant"}, {"content", content}}},
180 {"finish_reason", "stop"},
181 {"logprobs", nullptr}}})},
182 {"usage",
183 {{"prompt_tokens", prompt_tokens},
184 {"completion_tokens", completion_tokens},
185 {"total_tokens", prompt_tokens + completion_tokens}}}};
186
187 return response.dump();
188}
189
190std::string ResponseBuilder::buildErrorResponse(int status_code,
191 const std::string& error_type,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected