@@ -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
0 commit comments