AnjanSB commited on
Commit
08b3aaa
·
1 Parent(s): 7a5d4de

feat: fix gradio history object bug

Browse files
Files changed (1) hide show
  1. app.py +10 -4
app.py CHANGED
@@ -23,10 +23,16 @@ def respond(
23
  )
24
 
25
  def sanitize_messages(history):
26
- return [
27
- {"role": m["role"], "content": m["content"]}
28
- for m in history
29
- ]
 
 
 
 
 
 
30
 
31
  messages = [{"role": "system", "content": system_message}]
32
  messages.extend(sanitize_messages(history))
 
23
  )
24
 
25
  def sanitize_messages(history):
26
+ sanitized = []
27
+ for m in history:
28
+ # Check if it's the new dictionary format
29
+ if isinstance(m, dict):
30
+ sanitized.append({"role": m["role"], "content": m["content"]})
31
+ # Check if it's the old list/tuple format [user, bot]
32
+ elif isinstance(m, (list, tuple)):
33
+ if m[0]: sanitized.append({"role": "user", "content": m[0]})
34
+ if m[1]: sanitized.append({"role": "assistant", "content": m[1]})
35
+ return sanitized
36
 
37
  messages = [{"role": "system", "content": system_message}]
38
  messages.extend(sanitize_messages(history))