alex4cip Claude commited on
Commit
d64290b
Β·
1 Parent(s): 2384d41

fix: Add user message to history in messages format

Browse files

Issue: User input not displaying in chat interface with type='messages'

πŸ”§ Fix:
- Explicitly add user message to history in chat_wrapper
- Updated history = history + [{"role": "user", "content": message}]
- Pass updated history to generate_response function

πŸ“ Behavior:
- User message now displays in chat interface
- Proper message flow: user β†’ assistant
- Maintains conversation context correctly

πŸ€– Generated with [Claude Code](https://claude.com/claude-code)

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

Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -168,7 +168,11 @@ else:
168
 
169
  def chat_wrapper(message, history):
170
  """Wrapper for Gradio ChatInterface"""
171
- return generate_response(message, history)
 
 
 
 
172
 
173
 
174
  # Determine hardware info for UI
@@ -220,7 +224,10 @@ with gr.Blocks(title="πŸ€– Llama-2-Ko Chatbot") as demo:
220
  clear = gr.Button("πŸ—‘οΈ λŒ€ν™” μ΄ˆκΈ°ν™”", size="sm")
221
 
222
  def submit(message, history):
223
- return chat_wrapper(message, history), ""
 
 
 
224
 
225
  btn.click(submit, [msg, chatbot], [chatbot, msg])
226
  msg.submit(submit, [msg, chatbot], [chatbot, msg])
 
168
 
169
  def chat_wrapper(message, history):
170
  """Wrapper for Gradio ChatInterface"""
171
+ # When type="messages", history includes user message already from Gradio
172
+ # So we add it first, then generate response
173
+ updated_history = history + [{"role": "user", "content": message}]
174
+ response_history = generate_response(message, updated_history)
175
+ return response_history
176
 
177
 
178
  # Determine hardware info for UI
 
224
  clear = gr.Button("πŸ—‘οΈ λŒ€ν™” μ΄ˆκΈ°ν™”", size="sm")
225
 
226
  def submit(message, history):
227
+ # Gradio automatically adds user message when type="messages"
228
+ # We just need to get the bot response
229
+ response_history = chat_wrapper(message, history)
230
+ return response_history, ""
231
 
232
  btn.click(submit, [msg, chatbot], [chatbot, msg])
233
  msg.submit(submit, [msg, chatbot], [chatbot, msg])