GhostScientist commited on
Commit
2cad9e2
·
verified ·
1 Parent(s): f27ef17

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +6 -1
app.py CHANGED
@@ -33,8 +33,12 @@ def generate_response(message, history, system_message, max_tokens, temperature,
33
 
34
  messages = [{"role": "system", "content": system_message}]
35
 
 
36
  for item in history:
37
- if isinstance(item, (list, tuple)) and len(item) == 2:
 
 
 
38
  user_msg, assistant_msg = item
39
  if user_msg:
40
  messages.append({"role": "user", "content": user_msg})
@@ -85,6 +89,7 @@ demo = gr.ChatInterface(
85
  ["What's the weather like in San Francisco?"],
86
  ["Can you search for the latest news about AI?"],
87
  ],
 
88
  )
89
 
90
  if __name__ == "__main__":
 
33
 
34
  messages = [{"role": "system", "content": system_message}]
35
 
36
+ # Handle Gradio 5.x history format (list of dicts with 'role' and 'content')
37
  for item in history:
38
+ if isinstance(item, dict):
39
+ messages.append({"role": item["role"], "content": item["content"]})
40
+ elif isinstance(item, (list, tuple)) and len(item) == 2:
41
+ # Legacy format (list of tuples)
42
  user_msg, assistant_msg = item
43
  if user_msg:
44
  messages.append({"role": "user", "content": user_msg})
 
89
  ["What's the weather like in San Francisco?"],
90
  ["Can you search for the latest news about AI?"],
91
  ],
92
+ type="messages", # Use the new messages format explicitly
93
  )
94
 
95
  if __name__ == "__main__":