| 12345678910111213141516171819202122232425 |
- #pragma once
- #include <string>
- #include <vector>
- #include <nlohmann/json.hpp>
- namespace svapi {
- std::vector<float> parseEmbeddingResponse(const nlohmann::json& body);
- // Split an OpenAI-compatible base URL into the origin (scheme://host[:port] —
- // httplib::Client ignores any path) and a path prefix to prepend to
- // "/v1/embeddings". e.g. "https://api.openai.com" -> {"https://api.openai.com", ""};
- // "https://openrouter.ai/api" -> {"https://openrouter.ai", "/api"}.
- struct EmbeddingEndpoint { std::string origin; std::string path; };
- EmbeddingEndpoint splitEmbeddingBase(const std::string& apiBase);
- class EmbeddingClient {
- public:
- EmbeddingClient(std::string apiBase, std::string apiKey,
- uint32_t connectTimeoutSec = 10, uint32_t readTimeoutSec = 60,
- uint32_t poolSize = 4);
- std::vector<float> embed(const std::string& model, const std::string& text);
- private:
- std::string apiBase_, apiKey_;
- uint32_t connectTimeoutSec_, readTimeoutSec_, poolSize_;
- };
- }
|