mirror of
https://github.com/typesense/typesense.git
synced 2025-05-21 06:02:26 +08:00
Standardize variable names
This commit is contained in:
parent
5bc9360934
commit
a9de01f161
@ -16,7 +16,7 @@ class TextEmbedder {
|
||||
// Constructor for remote models
|
||||
TextEmbedder(const nlohmann::json& model_config);
|
||||
~TextEmbedder();
|
||||
embedding_res_t Embed(const std::string& text, const size_t remote_embedder_timeout_ms = 30000, const size_t remote_embedder_num_try = 2);
|
||||
embedding_res_t Embed(const std::string& text, const size_t remote_embedder_timeout_ms = 30000, const size_t remote_embedding_num_try = 2);
|
||||
std::vector<embedding_res_t> batch_embed(const std::vector<std::string>& inputs);
|
||||
const std::string& get_vocab_file_name() const;
|
||||
bool is_remote() {
|
||||
|
@ -29,7 +29,7 @@ class RemoteEmbedder {
|
||||
static inline ReplicationState* raft_server = nullptr;
|
||||
public:
|
||||
virtual nlohmann::json get_error_json(const nlohmann::json& req_body, long res_code, const std::string& res_body) = 0;
|
||||
virtual embedding_res_t Embed(const std::string& text, const size_t remote_embedder_timeout_ms = 30000, const size_t remote_embedder_num_retry = 2) = 0;
|
||||
virtual embedding_res_t Embed(const std::string& text, const size_t remote_embedder_timeout_ms = 30000, const size_t remote_embedding_num_try = 2) = 0;
|
||||
virtual std::vector<embedding_res_t> batch_embed(const std::vector<std::string>& inputs) = 0;
|
||||
static void init(ReplicationState* rs) {
|
||||
raft_server = rs;
|
||||
@ -48,7 +48,7 @@ class OpenAIEmbedder : public RemoteEmbedder {
|
||||
public:
|
||||
OpenAIEmbedder(const std::string& openai_model_path, const std::string& api_key);
|
||||
static Option<bool> is_model_valid(const nlohmann::json& model_config, unsigned int& num_dims);
|
||||
embedding_res_t Embed(const std::string& text, const size_t remote_embedder_timeout_ms = 30000, const size_t remote_embedder_num_retry = 2) override;
|
||||
embedding_res_t Embed(const std::string& text, const size_t remote_embedder_timeout_ms = 30000, const size_t remote_embedding_num_try = 2) override;
|
||||
std::vector<embedding_res_t> batch_embed(const std::vector<std::string>& inputs) override;
|
||||
nlohmann::json get_error_json(const nlohmann::json& req_body, long res_code, const std::string& res_body) override;
|
||||
};
|
||||
@ -65,7 +65,7 @@ class GoogleEmbedder : public RemoteEmbedder {
|
||||
public:
|
||||
GoogleEmbedder(const std::string& google_api_key);
|
||||
static Option<bool> is_model_valid(const nlohmann::json& model_config, unsigned int& num_dims);
|
||||
embedding_res_t Embed(const std::string& text, const size_t remote_embedder_timeout_ms = 30000, const size_t remote_embedder_num_retry = 2) override;
|
||||
embedding_res_t Embed(const std::string& text, const size_t remote_embedder_timeout_ms = 30000, const size_t remote_embedding_num_try = 2) override;
|
||||
std::vector<embedding_res_t> batch_embed(const std::vector<std::string>& inputs) override;
|
||||
nlohmann::json get_error_json(const nlohmann::json& req_body, long res_code, const std::string& res_body) override;
|
||||
};
|
||||
@ -92,7 +92,7 @@ class GCPEmbedder : public RemoteEmbedder {
|
||||
GCPEmbedder(const std::string& project_id, const std::string& model_name, const std::string& access_token,
|
||||
const std::string& refresh_token, const std::string& client_id, const std::string& client_secret);
|
||||
static Option<bool> is_model_valid(const nlohmann::json& model_config, unsigned int& num_dims);
|
||||
embedding_res_t Embed(const std::string& text, const size_t remote_embedder_timeout_ms = 30000, const size_t remote_embedder_num_retry = 2) override;
|
||||
embedding_res_t Embed(const std::string& text, const size_t remote_embedder_timeout_ms = 30000, const size_t remote_embedding_num_try = 2) override;
|
||||
std::vector<embedding_res_t> batch_embed(const std::vector<std::string>& inputs) override;
|
||||
nlohmann::json get_error_json(const nlohmann::json& req_body, long res_code, const std::string& res_body) override;
|
||||
};
|
||||
|
@ -83,9 +83,9 @@ std::vector<float> TextEmbedder::mean_pooling(const std::vector<std::vector<floa
|
||||
return pooled_output;
|
||||
}
|
||||
|
||||
embedding_res_t TextEmbedder::Embed(const std::string& text, const size_t remote_embedder_timeout_ms, const size_t remote_embedder_max_retries) {
|
||||
embedding_res_t TextEmbedder::Embed(const std::string& text, const size_t remote_embedder_timeout_ms, const size_t remote_embedding_num_try) {
|
||||
if(is_remote()) {
|
||||
return remote_embedder_->Embed(text, remote_embedder_timeout_ms, remote_embedder_max_retries);
|
||||
return remote_embedder_->Embed(text, remote_embedder_timeout_ms, remote_embedding_num_try);
|
||||
} else {
|
||||
// Cannot run same model in parallel, so lock the mutex
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
@ -132,13 +132,13 @@ Option<bool> OpenAIEmbedder::is_model_valid(const nlohmann::json& model_config,
|
||||
return Option<bool>(true);
|
||||
}
|
||||
|
||||
embedding_res_t OpenAIEmbedder::Embed(const std::string& text, const size_t remote_embedder_timeout_ms, const size_t remote_embedder_num_try) {
|
||||
embedding_res_t OpenAIEmbedder::Embed(const std::string& text, const size_t remote_embedder_timeout_ms, const size_t remote_embedding_num_try) {
|
||||
std::unordered_map<std::string, std::string> headers;
|
||||
std::map<std::string, std::string> res_headers;
|
||||
headers["Authorization"] = "Bearer " + api_key;
|
||||
headers["Content-Type"] = "application/json";
|
||||
headers["timeout_ms"] = std::to_string(remote_embedder_timeout_ms);
|
||||
headers["num_try"] = std::to_string(remote_embedder_num_try);
|
||||
headers["num_try"] = std::to_string(remote_embedding_num_try);
|
||||
std::string res;
|
||||
nlohmann::json req_body;
|
||||
req_body["input"] = std::vector<std::string>{text};
|
||||
@ -287,12 +287,12 @@ Option<bool> GoogleEmbedder::is_model_valid(const nlohmann::json& model_config,
|
||||
return Option<bool>(true);
|
||||
}
|
||||
|
||||
embedding_res_t GoogleEmbedder::Embed(const std::string& text, const size_t remote_embedder_timeout_ms, const size_t remote_embedder_num_try) {
|
||||
embedding_res_t GoogleEmbedder::Embed(const std::string& text, const size_t remote_embedder_timeout_ms, const size_t remote_embedding_num_try) {
|
||||
std::unordered_map<std::string, std::string> headers;
|
||||
std::map<std::string, std::string> res_headers;
|
||||
headers["Content-Type"] = "application/json";
|
||||
headers["timeout_ms"] = std::to_string(remote_embedder_timeout_ms);
|
||||
headers["num_try"] = std::to_string(remote_embedder_num_try);
|
||||
headers["num_try"] = std::to_string(remote_embedding_num_try);
|
||||
std::string res;
|
||||
nlohmann::json req_body;
|
||||
req_body["text"] = text;
|
||||
@ -422,7 +422,7 @@ Option<bool> GCPEmbedder::is_model_valid(const nlohmann::json& model_config, uns
|
||||
return Option<bool>(true);
|
||||
}
|
||||
|
||||
embedding_res_t GCPEmbedder::Embed(const std::string& text, const size_t remote_embedder_timeout_ms, const size_t remote_embedder_num_try) {
|
||||
embedding_res_t GCPEmbedder::Embed(const std::string& text, const size_t remote_embedder_timeout_ms, const size_t remote_embedding_num_try) {
|
||||
nlohmann::json req_body;
|
||||
req_body["instances"] = nlohmann::json::array();
|
||||
nlohmann::json instance;
|
||||
@ -432,7 +432,7 @@ embedding_res_t GCPEmbedder::Embed(const std::string& text, const size_t remote_
|
||||
headers["Authorization"] = "Bearer " + access_token;
|
||||
headers["Content-Type"] = "application/json";
|
||||
headers["timeout_ms"] = std::to_string(remote_embedder_timeout_ms);
|
||||
headers["num_try"] = std::to_string(remote_embedder_num_try);
|
||||
headers["num_try"] = std::to_string(remote_embedding_num_try);
|
||||
std::map<std::string, std::string> res_headers;
|
||||
std::string res;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user