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