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

Method embeddings

src/providers/base_provider_client.cpp:149–197  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

147 return StreamResult();
148}
149
150EmbeddingResult BaseProviderClient::embeddings(
151 const EmbeddingOptions& options) {
152 try {
153 // Build request JSON using the provider-specific builder
154 auto request_json = request_builder_->build_request_json(options);
155 std::string json_body = request_json.dump();
156 ai::logger::log_debug("Request JSON built: {}", json_body);
157
158 // Build headers
159 auto headers = request_builder_->build_headers(config_);
160
161 // Make the requests
162 auto result = http_handler_->post(config_.embeddings_endpoint_path, headers,
163 json_body);
164
165 if (!result.is_success()) {
166 // Parse error response using provider-specific parser
167 if (result.provider_metadata.has_value()) {
168 int status_code = std::stoi(result.provider_metadata.value());
169 return response_parser_->parse_error_embedding_response(
170 status_code, result.error.value_or(""));
171 }
172 return EmbeddingResult(result.error);
173 }
174
175 // Parse the response JSON from result.text
176 nlohmann::json json_response;
177 try {
178 json_response = nlohmann::json::parse(result.text);
179 } catch (const nlohmann::json::exception& e) {
180 ai::logger::log_error("Failed to parse response JSON: {}", e.what());
181 ai::logger::log_debug("Raw response text: {}", result.text);
182 return EmbeddingResult("Failed to parse response: " +
183 std::string(e.what()));
184 }
185
186 ai::logger::log_info("Embeddings successful - model: {}, response_id: {}",
187 options.model, json_response.value("id", "unknown"));
188
189 // Parse using provider-specific parser
190 auto parsed_result =
191 response_parser_->parse_success_embedding_response(json_response);
192 return parsed_result;
193
194 } catch (const std::exception& e) {
195 ai::logger::log_error("Exception during embeddings: {}", e.what());
196 return EmbeddingResult(std::string("Exception: ") + e.what());
197 }
198}
199
200} // namespace providers

Callers

nothing calls this directly

Calls 10

log_debugFunction · 0.85
EmbeddingResultClass · 0.85
log_errorFunction · 0.85
log_infoFunction · 0.85
postMethod · 0.80
build_request_jsonMethod · 0.45
build_headersMethod · 0.45
is_successMethod · 0.45

Tested by

no test coverage detected