Oysiyl commited on
Commit
a54d338
·
verified ·
1 Parent(s): 95aae9b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -14,10 +14,10 @@ def process_history(history):
14
  """Process chat history into the format expected by the model."""
15
  processed_history = []
16
  for user_msg, assistant_msg in history:
17
- if user_msg:
18
- processed_history.append({"role": "user", "content": [{"type": "text", "text": user_msg}]})
19
- if assistant_msg:
20
- processed_history.append({"role": "assistant", "content": [{"type": "text", "text": assistant_msg}]})
21
  return processed_history
22
 
23
 
@@ -39,7 +39,11 @@ def respond(
39
  if system_message:
40
  messages.append({"role": "system", "content": [{"type": "text", "text": system_message}]})
41
 
42
- messages.extend(process_history(history))
 
 
 
 
43
  messages.append({"role": "user", "content": process_new_user_message(message)})
44
 
45
  # Apply chat template
 
14
  """Process chat history into the format expected by the model."""
15
  processed_history = []
16
  for user_msg, assistant_msg in history:
17
+ # Always add user message first, even if empty
18
+ processed_history.append({"role": "user", "content": [{"type": "text", "text": user_msg or ""}]})
19
+ # Always add assistant message, even if empty
20
+ processed_history.append({"role": "assistant", "content": [{"type": "text", "text": assistant_msg or ""}]})
21
  return processed_history
22
 
23
 
 
39
  if system_message:
40
  messages.append({"role": "system", "content": [{"type": "text", "text": system_message}]})
41
 
42
+ # Process the conversation history
43
+ if history:
44
+ messages.extend(process_history(history))
45
+
46
+ # Add the new user message
47
  messages.append({"role": "user", "content": process_new_user_message(message)})
48
 
49
  # Apply chat template