@@ -80,7 +80,7 @@ struct mtmd_cli_context {
8080 common_chat_templates_ptr tmpls;
8181 std::vector<common_chat_msg> chat_history;
8282 bool use_jinja = false ;
83- std::string system_prompt;
83+ // TODO: support for --system-prompt with /clear command
8484
8585 // support for legacy templates (models not having EOT token)
8686 llama_tokens antiprompt_tokens;
@@ -111,8 +111,7 @@ struct mtmd_cli_context {
111111
112112 tmpls = common_chat_templates_init (model, params.chat_template );
113113 use_jinja = params.use_jinja ;
114- system_prompt = params.system_prompt ;
115- reset_chat_history ();
114+ chat_history.clear ();
116115 LOG_INF (" %s: chat template example:\n %s\n " , __func__, common_chat_format_example (tmpls.get (), params.use_jinja , params.default_template_kwargs ).c_str ());
117116
118117 init_vision_context (params);
@@ -130,16 +129,6 @@ struct mtmd_cli_context {
130129 common_sampler_free (smpl);
131130 }
132131
133- void reset_chat_history () {
134- chat_history.clear ();
135- if (!system_prompt.empty ()) {
136- common_chat_msg sys_msg;
137- sys_msg.role = " system" ;
138- sys_msg.content = system_prompt;
139- chat_history.push_back (std::move (sys_msg));
140- }
141- }
142-
143132 void init_vision_context (common_params & params) {
144133 const char * clip_path = params.mmproj .path .c_str ();
145134 mtmd_context_params mparams = mtmd_context_params_default ();
@@ -228,7 +217,8 @@ static std::string chat_add_and_format(mtmd_cli_context & ctx, common_chat_msg &
228217 return formatted;
229218}
230219
231- static int eval_message (mtmd_cli_context & ctx, common_chat_msg & msg, bool add_bos = false ) {
220+ static int eval_message (mtmd_cli_context & ctx, common_chat_msg & msg) {
221+ bool add_bos = ctx.chat_history .empty ();
232222 auto formatted_chat = chat_add_and_format (ctx, msg);
233223 LOG_DBG (" formatted_chat.prompt: %s\n " , formatted_chat.c_str ());
234224
@@ -331,7 +321,7 @@ int main(int argc, char ** argv) {
331321 return 1 ; // error is already printed by libmtmd
332322 }
333323 }
334- if (eval_message (ctx, msg, true )) {
324+ if (eval_message (ctx, msg)) {
335325 return 1 ;
336326 }
337327 if (!g_is_interrupted && generate_response (ctx, n_predict)) {
@@ -350,7 +340,6 @@ int main(int argc, char ** argv) {
350340 LOG (" \n /quit or /exit exit the program" );
351341 LOG (" \n " );
352342
353- bool is_first_msg = true ;
354343 std::string content;
355344
356345 while (!g_is_interrupted) {
@@ -370,7 +359,7 @@ int main(int argc, char ** argv) {
370359 }
371360 if (line == " /clear" ) {
372361 ctx.n_past = 0 ;
373- ctx.reset_chat_history ();
362+ ctx.chat_history . clear ();
374363 llama_memory_clear (llama_get_memory (ctx.lctx ), true );
375364 LOG (" Chat history cleared\n\n " );
376365 continue ;
@@ -396,7 +385,7 @@ int main(int argc, char ** argv) {
396385 common_chat_msg msg;
397386 msg.role = " user" ;
398387 msg.content = content;
399- int ret = eval_message (ctx, msg, is_first_msg );
388+ int ret = eval_message (ctx, msg);
400389 if (ret) {
401390 return 1 ;
402391 }
@@ -405,7 +394,6 @@ int main(int argc, char ** argv) {
405394 return 1 ;
406395 }
407396 content.clear ();
408- is_first_msg = false ;
409397 }
410398 }
411399 if (g_is_interrupted) LOG (" \n Interrupted by user\n " );
0 commit comments