@@ -116,11 +116,6 @@ CurlResponse RemoteEngine::MakeStreamingChatCompletionRequest(
116116 }
117117
118118 std::string full_url = chat_url_;
119-
120- if (config.transform_req [" chat_completions" ][" url" ]) {
121- full_url =
122- config.transform_req [" chat_completions" ][" url" ].as <std::string>();
123- }
124119 CTL_DBG (" full_url: " << full_url);
125120
126121 struct curl_slist * headers = nullptr ;
@@ -134,12 +129,6 @@ CurlResponse RemoteEngine::MakeStreamingChatCompletionRequest(
134129 headers = curl_slist_append (headers, " Connection: keep-alive" );
135130
136131 std::string stream_template = chat_res_template_;
137- if (config.transform_resp [" chat_completions" ] &&
138- config.transform_resp [" chat_completions" ][" template" ]) {
139- // Model level overrides engine level
140- stream_template =
141- config.transform_resp [" chat_completions" ][" template" ].as <std::string>();
142- }
143132
144133 StreamContext context{
145134 std::make_shared<std::function<void (Json::Value&&, Json::Value&&)>>(
@@ -295,11 +284,6 @@ CurlResponse RemoteEngine::MakeChatCompletionRequest(
295284 return response;
296285 }
297286 std::string full_url = chat_url_;
298-
299- if (config.transform_req [" chat_completions" ][" url" ]) {
300- full_url =
301- config.transform_req [" chat_completions" ][" url" ].as <std::string>();
302- }
303287 CTL_DBG (" full_url: " << full_url);
304288
305289 struct curl_slist * headers = nullptr ;
@@ -341,7 +325,6 @@ bool RemoteEngine::LoadModelConfig(const std::string& model,
341325
342326 ModelConfig model_config;
343327 model_config.model = model;
344- model_config.api_key = body[" api_key" ].asString ();
345328 // model_config.url = ;
346329 // Optional fields
347330 if (auto s = config[" header_template" ]; s && !s.as <std::string>().empty ()) {
@@ -350,16 +333,6 @@ bool RemoteEngine::LoadModelConfig(const std::string& model,
350333 CTL_DBG (" header: " << h);
351334 }
352335 }
353- if (config[" transform_req" ]) {
354- model_config.transform_req = config[" transform_req" ];
355- } else {
356- LOG_WARN << " Missing transform_req in config for model " << model;
357- }
358- if (config[" transform_resp" ]) {
359- model_config.transform_resp = config[" transform_resp" ];
360- } else {
361- LOG_WARN << " Missing transform_resp in config for model " << model;
362- }
363336
364337 model_config.is_loaded = true ;
365338
@@ -414,9 +387,10 @@ void RemoteEngine::LoadModel(
414387 std::shared_ptr<Json::Value> json_body,
415388 std::function<void (Json::Value&&, Json::Value&&)>&& callback) {
416389 if (!json_body->isMember (" model" ) || !json_body->isMember (" model_path" ) ||
417- !json_body->isMember (" api_key" )) {
390+ !json_body->isMember (" api_key" ) || !json_body-> isMember ( " metadata " ) ) {
418391 Json::Value error;
419- error[" error" ] = " Missing required fields: model or model_path" ;
392+ error[" error" ] =
393+ " Missing required fields: model, model_path, api_key or metadata" ;
420394 Json::Value status;
421395 status[" is_done" ] = true ;
422396 status[" has_error" ] = true ;
@@ -428,43 +402,41 @@ void RemoteEngine::LoadModel(
428402
429403 const std::string& model = (*json_body)[" model" ].asString ();
430404 const std::string& model_path = (*json_body)[" model_path" ].asString ();
431- const std::string& api_key = (*json_body)[" api_key" ].asString ();
432-
433- if (json_body->isMember (" metadata" )) {
434- metadata_ = (*json_body)[" metadata" ];
435- if (!metadata_[" transform_req" ].isNull () &&
436- !metadata_[" transform_req" ][" chat_completions" ].isNull () &&
437- !metadata_[" transform_req" ][" chat_completions" ][" template" ].isNull ()) {
438- chat_req_template_ =
439- metadata_[" transform_req" ][" chat_completions" ][" template" ].asString ();
440- CTL_INF (chat_req_template_);
441- }
442405
443- if (!metadata_[" transform_resp" ].isNull () &&
444- !metadata_[" transform_resp" ][" chat_completions" ].isNull () &&
445- !metadata_[" transform_resp" ][" chat_completions" ][" template" ].isNull ()) {
446- chat_res_template_ =
447- metadata_[" transform_resp" ][" chat_completions" ][" template" ]
448- .asString ();
449- CTL_INF (chat_res_template_);
450- }
406+ metadata_ = (*json_body)[" metadata" ];
407+ if (!metadata_[" transform_req" ].isNull () &&
408+ !metadata_[" transform_req" ][" chat_completions" ].isNull () &&
409+ !metadata_[" transform_req" ][" chat_completions" ][" template" ].isNull ()) {
410+ chat_req_template_ =
411+ metadata_[" transform_req" ][" chat_completions" ][" template" ].asString ();
412+ CTL_INF (chat_req_template_);
413+ } else {
414+ CTL_WRN (" Required transform_req" );
415+ }
451416
452- if (!metadata_[" transform_req" ].isNull () &&
453- !metadata_[" transform_req" ][" chat_completions" ].isNull () &&
454- !metadata_[" transform_req" ][" chat_completions" ][" url" ].isNull ()) {
455- chat_url_ =
456- metadata_[" transform_req" ][" chat_completions" ][" url" ].asString ();
457- CTL_INF (chat_url_);
458- }
417+ if (!metadata_[" transform_resp" ].isNull () &&
418+ !metadata_[" transform_resp" ][" chat_completions" ].isNull () &&
419+ !metadata_[" transform_resp" ][" chat_completions" ][" template" ].isNull ()) {
420+ chat_res_template_ =
421+ metadata_[" transform_resp" ][" chat_completions" ][" template" ].asString ();
422+ CTL_INF (chat_res_template_);
423+ } else {
424+ CTL_WRN (" Required transform_resp" );
459425 }
460426
461- if (json_body->isMember (" metadata" )) {
462- if (!metadata_[" header_template" ].isNull ()) {
463- header_ = ReplaceHeaderPlaceholders (
464- metadata_[" header_template" ].asString (), *json_body);
465- for (auto const & h : header_) {
466- CTL_DBG (" header: " << h);
467- }
427+ if (!metadata_[" transform_req" ].isNull () &&
428+ !metadata_[" transform_req" ][" chat_completions" ].isNull () &&
429+ !metadata_[" transform_req" ][" chat_completions" ][" url" ].isNull ()) {
430+ chat_url_ =
431+ metadata_[" transform_req" ][" chat_completions" ][" url" ].asString ();
432+ CTL_INF (chat_url_);
433+ }
434+
435+ if (!metadata_[" header_template" ].isNull ()) {
436+ header_ = ReplaceHeaderPlaceholders (metadata_[" header_template" ].asString (),
437+ *json_body);
438+ for (auto const & h : header_) {
439+ CTL_DBG (" header: " << h);
468440 }
469441 }
470442
@@ -568,13 +540,8 @@ void RemoteEngine::HandleChatCompletion(
568540 if (!chat_req_template_.empty ()) {
569541 CTL_DBG (" Use engine transform request template: " << chat_req_template_);
570542 template_str = chat_req_template_;
571- }
572- if (model_config->transform_req [" chat_completions" ] &&
573- model_config->transform_req [" chat_completions" ][" template" ]) {
574- // Model level overrides engine level
575- template_str = model_config->transform_req [" chat_completions" ][" template" ]
576- .as <std::string>();
577- CTL_DBG (" Use model transform request template: " << template_str);
543+ } else {
544+ CTL_WRN (" Required transform request template" );
578545 }
579546
580547 // Render with error handling
@@ -634,14 +601,8 @@ void RemoteEngine::HandleChatCompletion(
634601 CTL_DBG (
635602 " Use engine transform response template: " << chat_res_template_);
636603 template_str = chat_res_template_;
637- }
638- if (model_config->transform_resp [" chat_completions" ] &&
639- model_config->transform_resp [" chat_completions" ][" template" ]) {
640- // Model level overrides engine level
641- template_str =
642- model_config->transform_resp [" chat_completions" ][" template" ]
643- .as <std::string>();
644- CTL_DBG (" Use model transform request template: " << template_str);
604+ } else {
605+ CTL_WRN (" Required transform response template" );
645606 }
646607
647608 try {
0 commit comments