@@ -294,7 +294,7 @@ json parse_options(bool streaming, const backend::PredictOptions* predict, const
294294 } else {
295295 SRV_WRN (" [TOOLS DEBUG] parse_options: Parsed tools JSON is not an array: %s\n " , tools_json.dump ().c_str ());
296296 }
297- } catch (const json::parse_error & e) {
297+ } catch (const common_json_error & e) {
298298 SRV_WRN (" Failed to parse tools JSON from proto: %s\n " , e.what ());
299299 SRV_WRN (" [TOOLS DEBUG] parse_options: Tools string that failed to parse: %s\n " , predict->tools ().c_str ());
300300 }
@@ -324,7 +324,7 @@ json parse_options(bool streaming, const backend::PredictOptions* predict, const
324324 SRV_DBG (" [TOOLS DEBUG] Received tool_choice object from Go layer: %s\n " , tool_choice_json.dump ().c_str ());
325325 }
326326 SRV_INF (" Extracted tool_choice from proto: %s\n " , predict->toolchoice ().c_str ());
327- } catch (const json::parse_error & e) {
327+ } catch (const common_json_error & e) {
328328 // If parsing fails, treat as string
329329 data[" tool_choice" ] = predict->toolchoice ();
330330 SRV_INF (" Extracted tool_choice as string: %s\n " , predict->toolchoice ().c_str ());
@@ -353,7 +353,7 @@ json parse_options(bool streaming, const backend::PredictOptions* predict, const
353353 // Add to data - llama.cpp server expects it as an object (map)
354354 data[" logit_bias" ] = logit_bias_json;
355355 SRV_INF (" Using logit_bias: %s\n " , predict->logitbias ().c_str ());
356- } catch (const json::parse_error & e) {
356+ } catch (const common_json_error & e) {
357357 SRV_ERR (" Failed to parse logit_bias JSON from proto: %s\n " , e.what ());
358358 }
359359 }
@@ -398,7 +398,10 @@ json parse_options(bool streaming, const backend::PredictOptions* predict, const
398398 });
399399 }
400400
401- data[" stop" ] = predict->stopprompts ();
401+ data[" stop" ] = json::array ();
402+ for (const auto & stop : predict->stopprompts ()) {
403+ data[" stop" ].push_back (stop);
404+ }
402405 // data["n_probs"] = predict->nprobs();
403406 // TODO: images,
404407
@@ -1795,7 +1798,7 @@ class BackendServiceImpl final : public backend::Backend::Service {
17951798 for (int j = 0 ; j < request->audios_size (); j++) rin.audios .push_back (request->audios (j));
17961799 for (int j = 0 ; j < request->videos_size (); j++) rin.videos .push_back (request->videos (j));
17971800 }
1798- messages_json.push_back (llama_grpc::build_reconstructed_message (rin));
1801+ messages_json.push_back (json::parse ( llama_grpc::build_reconstructed_message (rin). dump () ));
17991802 }
18001803
18011804 // Final safety check: Ensure no message has null content (Jinja templates require strings)
@@ -1988,7 +1991,7 @@ class BackendServiceImpl final : public backend::Backend::Service {
19881991 if (!body_json.contains (" chat_template_kwargs" )) {
19891992 body_json[" chat_template_kwargs" ] = json::object ();
19901993 }
1991- for (auto & el : ctk.items ()) {
1994+ for (auto el : ctk.items ()) {
19921995 body_json[" chat_template_kwargs" ][el.key ()] = el.value ();
19931996 }
19941997 }
@@ -2074,30 +2077,27 @@ class BackendServiceImpl final : public backend::Backend::Service {
20742077 // If not using chat templates, extract files from image_data/audio_data fields
20752078 // (If using chat templates, files were already extracted by oaicompat_chat_params_parse)
20762079 if (!request->usetokenizertemplate () || request->messages_size () == 0 || ctx_server.impl ->chat_params .tmpls == nullptr ) {
2077- const auto &images_data = data.find (" image_data" );
2078- if (images_data != data.end () && images_data->is_array ())
2080+ if (data.contains (" image_data" ) && data.at (" image_data" ).is_array ())
20792081 {
2080- for (const auto &img : *images_data )
2082+ for (const auto &img : data. at ( " image_data " ) )
20812083 {
20822084 auto decoded_data = base64_decode (img[" data" ].get <std::string>());
20832085 files.push_back (decoded_data);
20842086 }
20852087 }
20862088
2087- const auto &audio_data = data.find (" audio_data" );
2088- if (audio_data != data.end () && audio_data->is_array ())
2089+ if (data.contains (" audio_data" ) && data.at (" audio_data" ).is_array ())
20892090 {
2090- for (const auto &audio : * audio_data)
2091+ for (const auto &audio : data. at ( " audio_data" ) )
20912092 {
20922093 auto decoded_data = base64_decode (audio[" data" ].get <std::string>());
20932094 files.push_back (decoded_data);
20942095 }
20952096 }
20962097
2097- const auto &video_data = data.find (" video_data" );
2098- if (video_data != data.end () && video_data->is_array ())
2098+ if (data.contains (" video_data" ) && data.at (" video_data" ).is_array ())
20992099 {
2100- for (const auto &video : * video_data)
2100+ for (const auto &video : data. at ( " video_data" ) )
21012101 {
21022102 auto decoded_data = base64_decode (video[" data" ].get <std::string>());
21032103 files.push_back (decoded_data);
@@ -2370,7 +2370,7 @@ class BackendServiceImpl final : public backend::Backend::Service {
23702370 for (int j = 0 ; j < request->audios_size (); j++) rin.audios .push_back (request->audios (j));
23712371 for (int j = 0 ; j < request->videos_size (); j++) rin.videos .push_back (request->videos (j));
23722372 }
2373- messages_json.push_back (llama_grpc::build_reconstructed_message (rin));
2373+ messages_json.push_back (json::parse ( llama_grpc::build_reconstructed_message (rin). dump () ));
23742374 }
23752375
23762376 // Final safety check: Ensure no message has null content (Jinja templates require strings)
@@ -2563,7 +2563,7 @@ class BackendServiceImpl final : public backend::Backend::Service {
25632563 if (!body_json.contains (" chat_template_kwargs" )) {
25642564 body_json[" chat_template_kwargs" ] = json::object ();
25652565 }
2566- for (auto & el : ctk.items ()) {
2566+ for (auto el : ctk.items ()) {
25672567 body_json[" chat_template_kwargs" ][el.key ()] = el.value ();
25682568 }
25692569 }
@@ -2649,32 +2649,29 @@ class BackendServiceImpl final : public backend::Backend::Service {
26492649 // If not using chat templates, extract files from image_data/audio_data fields
26502650 // (If using chat templates, files were already extracted by oaicompat_chat_params_parse)
26512651 if (!request->usetokenizertemplate () || request->messages_size () == 0 || ctx_server.impl ->chat_params .tmpls == nullptr ) {
2652- const auto &images_data = data.find (" image_data" );
2653- if (images_data != data.end () && images_data->is_array ())
2652+ if (data.contains (" image_data" ) && data.at (" image_data" ).is_array ())
26542653 {
2655- std::cout << " [PREDICT] Processing " << images_data-> size () << " images" << std::endl;
2656- for (const auto &img : *images_data )
2654+ std::cout << " [PREDICT] Processing " << data. at ( " image_data " ). size () << " images" << std::endl;
2655+ for (const auto &img : data. at ( " image_data " ) )
26572656 {
26582657 std::cout << " [PREDICT] Processing image" << std::endl;
26592658 auto decoded_data = base64_decode (img[" data" ].get <std::string>());
26602659 files.push_back (decoded_data);
26612660 }
26622661 }
26632662
2664- const auto &audio_data = data.find (" audio_data" );
2665- if (audio_data != data.end () && audio_data->is_array ())
2663+ if (data.contains (" audio_data" ) && data.at (" audio_data" ).is_array ())
26662664 {
2667- for (const auto &audio : * audio_data)
2665+ for (const auto &audio : data. at ( " audio_data" ) )
26682666 {
26692667 auto decoded_data = base64_decode (audio[" data" ].get <std::string>());
26702668 files.push_back (decoded_data);
26712669 }
26722670 }
26732671
2674- const auto &video_data = data.find (" video_data" );
2675- if (video_data != data.end () && video_data->is_array ())
2672+ if (data.contains (" video_data" ) && data.at (" video_data" ).is_array ())
26762673 {
2677- for (const auto &video : * video_data)
2674+ for (const auto &video : data. at ( " video_data" ) )
26782675 {
26792676 auto decoded_data = base64_decode (video[" data" ].get <std::string>());
26802677 files.push_back (decoded_data);
@@ -3005,7 +3002,7 @@ class BackendServiceImpl final : public backend::Backend::Service {
30053002 }
30063003
30073004 // Collect responses
3008- json responses = json::array () ;
3005+ std::vector< json> responses;
30093006 for (auto & res : all_results.results ) {
30103007 GGML_ASSERT (dynamic_cast <server_task_result_rerank*>(res.get ()) != nullptr );
30113008 responses.push_back (res->to_json ());
@@ -3018,7 +3015,7 @@ class BackendServiceImpl final : public backend::Backend::Service {
30183015 // Crop results by request.top_n if specified
30193016 int top_n = request->top_n ();
30203017 if (top_n > 0 && top_n < static_cast <int >(responses.size ())) {
3021- responses = json (responses. begin (), responses. begin () + top_n);
3018+ responses. resize ( top_n);
30223019 }
30233020 // Set usage information
30243021 backend::Usage* usage = rerankResult->mutable_usage ();
0 commit comments