mirror of
https://github.com/typesense/typesense.git
synced 2025-05-26 08:44:09 +08:00
Add API key support for vLLM conversation models (#1777)
This commit is contained in:
parent
5859e0fd3f
commit
79018dd2b9
@ -612,10 +612,19 @@ Option<bool> vLLMConversationModel::validate_model(const nlohmann::json& model_c
|
||||
if(!model_config["vllm_url"].is_string()) {
|
||||
return Option<bool>(400, "vLLM URL is not a string");
|
||||
}
|
||||
|
||||
|
||||
std::unordered_map<std::string, std::string> headers;
|
||||
std::map<std::string, std::string> res_headers;
|
||||
std::string res;
|
||||
|
||||
if(model_config.count("api_key") != 0) {
|
||||
if(!model_config["api_key"].is_string()) {
|
||||
return Option<bool>(400, "API key is not a string");
|
||||
}
|
||||
headers["Authorization"] = "Bearer " + model_config["api_key"].get<std::string>();
|
||||
}
|
||||
|
||||
auto res_code = RemoteEmbedder::call_remote_api("GET", get_list_models_url(model_config["vllm_url"]), "", res, res_headers, headers);
|
||||
|
||||
if(res_code == 408) {
|
||||
@ -713,6 +722,11 @@ Option<std::string> vLLMConversationModel::get_answer(const std::string& context
|
||||
req_body["messages"].push_back(message);
|
||||
|
||||
std::string res;
|
||||
|
||||
if(model_config.count("api_key") != 0) {
|
||||
headers["Authorization"] = "Bearer " + model_config["api_key"].get<std::string>();
|
||||
}
|
||||
|
||||
auto res_code = RemoteEmbedder::call_remote_api("POST", get_chat_completion_url(vllm_url), req_body.dump(), res, res_headers, headers);
|
||||
|
||||
if(res_code == 408) {
|
||||
@ -795,6 +809,10 @@ Option<std::string> vLLMConversationModel::get_standalone_question(const nlohman
|
||||
|
||||
req_body["messages"].push_back(message);
|
||||
|
||||
if(model_config.count("api_key") != 0) {
|
||||
headers["Authorization"] = "Bearer " + model_config["api_key"].get<std::string>();
|
||||
}
|
||||
|
||||
auto res_code = RemoteEmbedder::call_remote_api("POST", get_chat_completion_url(vllm_url), req_body.dump(), res, res_headers, headers);
|
||||
|
||||
if(res_code == 408) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user