Shining-Data commited on
Commit
5b1d6e2
·
verified ·
1 Parent(s): ed54b6b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -1
app.py CHANGED
@@ -107,7 +107,10 @@ def retrieve_context(query, max_results=6, max_chars=600):
107
 
108
  def format_conversation(history, system_prompt, tokenizer):
109
  if hasattr(tokenizer, "chat_template") and tokenizer.chat_template:
110
- messages = [{"role": "system", "content": system_prompt.strip()}] + history
 
 
 
111
  return tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True, enable_thinking=True)
112
  else:
113
  # Fallback for base LMs without chat template
 
107
 
108
  def format_conversation(history, system_prompt, tokenizer):
109
  if hasattr(tokenizer, "chat_template") and tokenizer.chat_template:
110
+ if len(history) > 0:
111
+ messages = [{"role": "system", "content": system_prompt.strip()}] + history
112
+ else:
113
+ messages = [{"role": "system", "content": system_prompt.strip()}]
114
  return tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True, enable_thinking=True)
115
  else:
116
  # Fallback for base LMs without chat template