Spaces:
Build error
Build error
Update app.py
Browse files19 unmodified lines20212223242324252627282915 unmodified lines454647464849505152535455565719 unmodified lines if history is None: history = [] # Initialize empty history if None
# Convert history to the new format formatted_history = "\n".join([f"{h['role']}: {h['content']}" for h in history[-5:]]) # Keep last 5 messages # Convert history to the new "messages" format formatted_history = "\n".join( [f"{msg['role'].capitalize()}: {msg['content']}" for msg in history[-5:]] # Keep last 5 messages )
# Construct prompt with memory + document context prompt = f"""15 unmodified lines # Extract response text answer = response.text if hasattr(response, "text") else "Sorry, I couldn't generate a response."
# Append new message to history in the correct format # Append messages in the correct format history.append({"role": "user", "content": user_input}) history.append({"role": "assistant", "content": answer})
return answer, history # Return both response and updated history
# Create a Gradio chat interface with memory using new "messages" formatiface = gr.ChatInterface(fn=chatbot_response, title="Memory-Enabled Chatbot")
app.py+6-3