Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 0619816

Browse files
committed
chore: add log
1 parent 04895b8 commit 0619816

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed

engine/extensions/remote-engine/remote_engine.cc

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,13 @@ CurlResponse RemoteEngine::MakeStreamingChatCompletionRequest(
9393
return response;
9494
}
9595

96-
std::string full_url =
97-
config.transform_req["chat_completions"]["url"].as<std::string>();
96+
std::string full_url = chat_url_;
97+
98+
if (config.transform_req["chat_completions"]["url"]) {
99+
full_url =
100+
config.transform_req["chat_completions"]["url"].as<std::string>();
101+
}
102+
CTL_DBG("full_url: " << full_url);
98103

99104
struct curl_slist* headers = nullptr;
100105
if (!config.api_key.empty()) {
@@ -246,8 +251,13 @@ CurlResponse RemoteEngine::MakeChatCompletionRequest(
246251
response.error_message = "Failed to initialize CURL";
247252
return response;
248253
}
249-
std::string full_url =
250-
config.transform_req["chat_completions"]["url"].as<std::string>();
254+
std::string full_url = chat_url_;
255+
256+
if (config.transform_req["chat_completions"]["url"]) {
257+
full_url =
258+
config.transform_req["chat_completions"]["url"].as<std::string>();
259+
}
260+
CTL_DBG("full_url: " << full_url);
251261

252262
struct curl_slist* headers = nullptr;
253263
if (!config.api_key.empty()) {
@@ -411,6 +421,14 @@ void RemoteEngine::LoadModel(
411421
.asString();
412422
CTL_INF(chat_res_template_);
413423
}
424+
425+
if (!metadata_["transform_req"].isNull() &&
426+
!metadata_["transform_req"]["chat_completions"].isNull() &&
427+
!metadata_["transform_req"]["chat_completions"]["url"].isNull()) {
428+
chat_url_ =
429+
metadata_["transform_req"]["chat_completions"]["url"].asString();
430+
CTL_INF(chat_url_);
431+
}
414432
}
415433

416434
if (!LoadModelConfig(model, model_path, api_key)) {
@@ -713,14 +731,12 @@ Json::Value RemoteEngine::GetRemoteModels(const std::string& url,
713731
CTL_WRN(response.error_message);
714732
return error;
715733
}
716-
Json::Value response_json;
717-
Json::Reader reader;
718-
if (!reader.parse(response.body, response_json)) {
719-
Json::Value error;
720-
error["error"] = "Failed to parse response";
721-
return error;
734+
CTL_DBG(response.body);
735+
auto body_json = json_helper::ParseJsonString(response.body);
736+
if (body_json.isMember("error")) {
737+
return body_json["error"];
722738
}
723-
return response_json;
739+
return body_json;
724740
}
725741
}
726742

engine/extensions/remote-engine/remote_engine.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class RemoteEngine : public RemoteEngineI {
5353
std::string chat_res_template_;
5454
std::string api_key_header_;
5555
std::string engine_name_;
56+
std::string chat_url_;
5657
trantor::ConcurrentTaskQueue q_;
5758

5859
// Helper functions

engine/services/engine_service.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,12 @@ cpp::result<Json::Value, std::string> EngineService::GetRemoteModels(
11421142
auto api_key = remote_engine_json["api_key"].asString();
11431143
auto api_key_template =
11441144
remote_engine_json["metadata"]["api_key_template"].asString();
1145+
if (url.empty())
1146+
CTL_WRN("url is empty");
1147+
if (api_key.empty())
1148+
CTL_WRN("api_key is empty");
1149+
if (api_key_template.empty())
1150+
CTL_WRN("api_key_template is empty");
11451151
auto res = e->GetRemoteModels(url, api_key, api_key_template);
11461152
if (!res["error"].isNull()) {
11471153
return cpp::fail(res["error"].asString());

0 commit comments

Comments
 (0)