Tonic commited on
Commit
db61106
1 Parent(s): 434332b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -7
app.py CHANGED
@@ -43,18 +43,22 @@ class FalconChatBot:
43
  def process_history(self, history):
44
  if history is None:
45
  return []
46
-
 
 
 
 
47
  # Filter out special commands from the history
48
  filtered_history = []
49
  for message in history:
50
- user_message = message["user"]
51
- assistant_message = message["assistant"]
52
- # Check if the user_message is not a special command
53
- if not user_message.startswith("Falcon:"):
54
- filtered_history.append({"user": user_message, "assistant": assistant_message})
 
55
  return filtered_history
56
 
57
-
58
  def predict(self, system_prompt, user_message, assistant_message, history, temperature=temperature, max_new_tokens=max_new_tokens, top_p=top_p, repetition_penalty=repetition_penalty):
59
 
60
  # Process the history to remove special commands
 
43
  def process_history(self, history):
44
  if history is None:
45
  return []
46
+
47
+ # Ensure that history is a list of dictionaries
48
+ if not isinstance(history, list):
49
+ return []
50
+
51
  # Filter out special commands from the history
52
  filtered_history = []
53
  for message in history:
54
+ if isinstance(message, dict):
55
+ user_message = message.get("user", "")
56
+ assistant_message = message.get("assistant", "")
57
+ # Check if the user_message is not a special command
58
+ if not user_message.startswith("Falcon:"):
59
+ filtered_history.append({"user": user_message, "assistant": assistant_message})
60
  return filtered_history
61
 
 
62
  def predict(self, system_prompt, user_message, assistant_message, history, temperature=temperature, max_new_tokens=max_new_tokens, top_p=top_p, repetition_penalty=repetition_penalty):
63
 
64
  # Process the history to remove special commands