@@ -535,6 +535,7 @@ json server_chat_msg_diff_to_json_oaicompat(const common_chat_msg_diff & diff) {
535535
536536json convert_transcriptions_to_chatcmpl (
537537 const json & inp_body,
538+ const common_chat_templates * tmpls,
538539 const std::map<std::string, raw_buffer> & in_files,
539540 std::vector<raw_buffer> & out_files) {
540541 // TODO @ngxson : this function may need to be improved in the future
@@ -548,27 +549,29 @@ json convert_transcriptions_to_chatcmpl(
548549 }
549550
550551 // handle input data
551- std::string prompt = json_value (inp_body, " prompt" , std::string ());
552- std::string language = json_value (inp_body, " language" , std::string ());
552+ std::string prompt = json_value (inp_body, " prompt" , std::string ());
553+ std::string language = json_value (inp_body, " language" , std::string ());
553554 std::string response_format = json_value (inp_body, " response_format" , std::string (" json" ));
554555 if (response_format != " json" ) {
555556 throw std::invalid_argument (" Only 'json' response_format is supported for transcription" );
556557 }
558+ const common_chat_prompt_preset preset = common_chat_get_asr_prompt (tmpls);
557559 if (prompt.empty ()) {
558- prompt = " Transcribe audio to text " ;
560+ prompt = preset. user ;
559561 }
560562 if (!language.empty ()) {
561563 prompt += string_format (" (language: %s)" , language.c_str ());
562564 }
563565 prompt += get_media_marker ();
564566
567+ json messages = json::array ();
568+ if (!preset.system .empty ()) {
569+ messages.push_back ({{" role" , " system" }, {" content" , preset.system }});
570+ }
571+ messages.push_back ({{" role" , " user" }, {" content" , prompt}});
572+
565573 json chatcmpl_body = inp_body; // copy all fields
566- chatcmpl_body[" messages" ] = json::array ({
567- {
568- {" role" , " user" },
569- {" content" , prompt},
570- },
571- });
574+ chatcmpl_body[" messages" ] = messages;
572575
573576 // because input from form-data, everything is string, we need to correct the types here
574577 std::string stream = json_value (inp_body, " stream" , std::string (" false" ));
0 commit comments