AI-Talent-Force Claude Sonnet 4.5 commited on
Commit
6a3b5fa
·
1 Parent(s): ecb4524

Fix history format for ChatInterface

Browse files

- ChatInterface passes history as tuples [(user, bot), ...]
- Convert tuple format to dict format for tokenizer
- Fixed conversation.extend() to proper loop conversion

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -53,14 +53,16 @@ def chat_with_ceo(message, history):
53
  Chat function that responds like the CEO
54
  Args:
55
  message: User's current message
56
- history: List of previous message dictionaries
57
  """
58
  # Build conversation context (limit history to last 5 exchanges for speed)
59
  conversation = []
60
 
61
- # Process history - in Gradio ChatInterface, history is a list of dicts
62
- recent_history = history[-10:] if len(history) > 10 else history # Last 5 exchanges (10 messages)
63
- conversation.extend(recent_history)
 
 
64
 
65
  # Add current message
66
  conversation.append({"role": "user", "content": message})
 
53
  Chat function that responds like the CEO
54
  Args:
55
  message: User's current message
56
+ history: List of previous message tuples [(user_msg, bot_msg), ...]
57
  """
58
  # Build conversation context (limit history to last 5 exchanges for speed)
59
  conversation = []
60
 
61
+ # Process history - ChatInterface passes history as list of tuples
62
+ recent_history = history[-5:] if len(history) > 5 else history # Last 5 exchanges
63
+ for user_msg, bot_msg in recent_history:
64
+ conversation.append({"role": "user", "content": user_msg})
65
+ conversation.append({"role": "assistant", "content": bot_msg})
66
 
67
  # Add current message
68
  conversation.append({"role": "user", "content": message})