Spaces:
Sleeping
Sleeping
fix: Add user message to history in messages format
Browse filesIssue: 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>
app.py
CHANGED
|
@@ -168,7 +168,11 @@ else:
|
|
| 168 |
|
| 169 |
def chat_wrapper(message, history):
|
| 170 |
"""Wrapper for Gradio ChatInterface"""
|
| 171 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
| 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])
|