mirror of
https://github.com/typesense/typesense.git
synced 2025-05-21 06:02:26 +08:00
Refactor ``get_public_model_config
`` method to check cache only if network fails
This commit is contained in:
parent
b0e677e221
commit
bdd35ea642
@ -448,14 +448,6 @@ text_embedding_model::text_embedding_model(const nlohmann::json& json) {
|
||||
|
||||
|
||||
Option<nlohmann::json> EmbedderManager::get_public_model_config(const std::string& model_name) {
|
||||
// check cache first
|
||||
if(std::filesystem::exists(get_absolute_config_path(model_name))) {
|
||||
std::ifstream config_file(get_absolute_config_path(model_name));
|
||||
nlohmann::json config;
|
||||
config_file >> config;
|
||||
config_file.close();
|
||||
return Option<nlohmann::json>(config);
|
||||
}
|
||||
|
||||
auto actual_model_name = get_model_name_without_namespace(model_name);
|
||||
HttpClient& httpClient = HttpClient::get_instance();
|
||||
@ -475,6 +467,15 @@ Option<nlohmann::json> EmbedderManager::get_public_model_config(const std::strin
|
||||
return Option<nlohmann::json>(nlohmann::json::parse(response_body));
|
||||
}
|
||||
|
||||
// check cache if network fails
|
||||
if(std::filesystem::exists(get_absolute_config_path(model_name))) {
|
||||
std::ifstream config_file(get_absolute_config_path(model_name));
|
||||
nlohmann::json config;
|
||||
config_file >> config;
|
||||
config_file.close();
|
||||
return Option<nlohmann::json>(config);
|
||||
}
|
||||
|
||||
return Option<nlohmann::json>(404, "Model not found");
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user