@@ -116,11 +116,6 @@ CurlResponse RemoteEngine::MakeStreamingChatCompletionRequest(
116
116
}
117
117
118
118
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
- }
124
119
CTL_DBG (" full_url: " << full_url);
125
120
126
121
struct curl_slist * headers = nullptr ;
@@ -134,12 +129,6 @@ CurlResponse RemoteEngine::MakeStreamingChatCompletionRequest(
134
129
headers = curl_slist_append (headers, " Connection: keep-alive" );
135
130
136
131
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
- }
143
132
144
133
StreamContext context{
145
134
std::make_shared<std::function<void (Json::Value&&, Json::Value&&)>>(
@@ -295,11 +284,6 @@ CurlResponse RemoteEngine::MakeChatCompletionRequest(
295
284
return response;
296
285
}
297
286
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
- }
303
287
CTL_DBG (" full_url: " << full_url);
304
288
305
289
struct curl_slist * headers = nullptr ;
@@ -341,7 +325,6 @@ bool RemoteEngine::LoadModelConfig(const std::string& model,
341
325
342
326
ModelConfig model_config;
343
327
model_config.model = model;
344
- model_config.api_key = body[" api_key" ].asString ();
345
328
// model_config.url = ;
346
329
// Optional fields
347
330
if (auto s = config[" header_template" ]; s && !s.as <std::string>().empty ()) {
@@ -350,16 +333,6 @@ bool RemoteEngine::LoadModelConfig(const std::string& model,
350
333
CTL_DBG (" header: " << h);
351
334
}
352
335
}
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
- }
363
336
364
337
model_config.is_loaded = true ;
365
338
@@ -414,9 +387,10 @@ void RemoteEngine::LoadModel(
414
387
std::shared_ptr<Json::Value> json_body,
415
388
std::function<void (Json::Value&&, Json::Value&&)>&& callback) {
416
389
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 " ) ) {
418
391
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" ;
420
394
Json::Value status;
421
395
status[" is_done" ] = true ;
422
396
status[" has_error" ] = true ;
@@ -428,43 +402,41 @@ void RemoteEngine::LoadModel(
428
402
429
403
const std::string& model = (*json_body)[" model" ].asString ();
430
404
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
- }
442
405
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
+ }
451
416
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" );
459
425
}
460
426
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);
468
440
}
469
441
}
470
442
@@ -568,13 +540,8 @@ void RemoteEngine::HandleChatCompletion(
568
540
if (!chat_req_template_.empty ()) {
569
541
CTL_DBG (" Use engine transform request template: " << chat_req_template_);
570
542
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" );
578
545
}
579
546
580
547
// Render with error handling
@@ -634,14 +601,8 @@ void RemoteEngine::HandleChatCompletion(
634
601
CTL_DBG (
635
602
" Use engine transform response template: " << chat_res_template_);
636
603
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" );
645
606
}
646
607
647
608
try {
0 commit comments