Reda-b commited on
Commit
40e598d
·
verified ·
1 Parent(s): 8c650f8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -1
app.py CHANGED
@@ -72,6 +72,20 @@ record_unknown_question_json = {
72
  tools = [{"type": "function", "function": record_user_details_json},
73
  {"type": "function", "function": record_unknown_question_json}]
74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
 
76
  class Me:
77
 
@@ -85,7 +99,6 @@ class Me:
85
  with open("me/summary.txt", "r", encoding="utf-8") as f:
86
  self.summary = f.read()
87
 
88
-
89
  def handle_tool_call(self, tool_calls):
90
  results = []
91
  for tool_call in tool_calls:
 
72
  tools = [{"type": "function", "function": record_user_details_json},
73
  {"type": "function", "function": record_unknown_question_json}]
74
 
75
+ def normalize_history(history):
76
+ clean = []
77
+ for h in history:
78
+ if isinstance(h, dict):
79
+ # Keep only role + content (drop metadata)
80
+ clean.append({
81
+ "role": h.get("role"),
82
+ "content": h.get("content", "")
83
+ })
84
+ elif isinstance(h, (list, tuple)) and len(h) == 2:
85
+ # Older Gradio formats
86
+ clean.append({"role": "user", "content": h[0]})
87
+ clean.append({"role": "assistant", "content": h[1]})
88
+ return clean
89
 
90
  class Me:
91
 
 
99
  with open("me/summary.txt", "r", encoding="utf-8") as f:
100
  self.summary = f.read()
101
 
 
102
  def handle_tool_call(self, tool_calls):
103
  results = []
104
  for tool_call in tool_calls: