@@ -265,7 +265,7 @@ int main(int argc, char ** argv) {
265265
266266 std::vector<llama_token> embd_inp;
267267
268- bool waiting_for_first_input = params. conversation_mode && params. enable_chat_template && params. system_prompt . empty () ;
268+ bool waiting_for_first_input = false ;
269269 auto chat_add_and_format = [&chat_msgs, &chat_templates](const std::string & role, const std::string & content) {
270270 common_chat_msg new_msg;
271271 new_msg.role = role;
@@ -277,18 +277,23 @@ int main(int argc, char ** argv) {
277277 };
278278
279279 {
280- std::string prompt;
280+ std::string prompt = params. enable_chat_template ? params. system_prompt : " " ;
281281
282- if (params.conversation_mode && params.enable_chat_template ) {
283- // format the system prompt in conversation mode (will use template default if empty)
284- prompt = params.system_prompt ;
282+ if (params.enable_chat_template && !prompt.empty ()) {
283+ // format the system prompt (will use template default if not set)
284+ prompt = chat_add_and_format (" system" , prompt);
285+ }
285286
286- if (!prompt.empty ()) {
287- prompt = chat_add_and_format (" system" , prompt);
287+ if (!params.conversation_mode ) {
288+ if (params.enable_chat_template && !params.prompt .empty ()) {
289+ // format and append the user prompt
290+ prompt += chat_add_and_format (" user" , params.prompt );
291+ } else {
292+ // otherwise use the prompt as is
293+ prompt = params.prompt ;
288294 }
289- } else {
290- // otherwise use the prompt as is
291- prompt = params.prompt ;
295+ } else if (prompt.empty ()) {
296+ waiting_for_first_input = true ;
292297 }
293298
294299 if (params.interactive_first || !params.prompt .empty () || session_tokens.empty ()) {
@@ -304,7 +309,7 @@ int main(int argc, char ** argv) {
304309 }
305310
306311 // Should not run without any tokens
307- if (!params. conversation_mode && embd_inp.empty ()) {
312+ if (!waiting_for_first_input && embd_inp.empty ()) {
308313 if (add_bos) {
309314 embd_inp.push_back (llama_vocab_bos (vocab));
310315 LOG_WRN (" embd_inp was considered empty and bos was added: %s\n " , string_from (ctx, embd_inp).c_str ());
0 commit comments