Update app.py
Browse files
app.py
CHANGED
|
@@ -59,20 +59,23 @@ demo_ephemeral_chat_history = ChatMessageHistory()
|
|
| 59 |
def get_text_response(message, history):
|
| 60 |
"""
|
| 61 |
Gradio passes the current 'message' and the 'history' list.
|
| 62 |
-
|
| 63 |
"""
|
| 64 |
-
# Convert Gradio history format to LangChain messages
|
| 65 |
formatted_history = []
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
-
# Run the
|
| 71 |
response = chain.invoke({
|
| 72 |
"chat_history": formatted_history,
|
| 73 |
"user_message": message
|
| 74 |
})
|
| 75 |
-
|
| 76 |
return response
|
| 77 |
|
| 78 |
# 6. Launch the Gradio Interface
|
|
|
|
| 59 |
def get_text_response(message, history):
|
| 60 |
"""
|
| 61 |
Gradio passes the current 'message' and the 'history' list.
|
| 62 |
+
With type='messages', history is a list of dicts.
|
| 63 |
"""
|
|
|
|
| 64 |
formatted_history = []
|
| 65 |
+
|
| 66 |
+
# Correctly parse the new Gradio dictionary format
|
| 67 |
+
for msg in history:
|
| 68 |
+
if msg["role"] == "user":
|
| 69 |
+
formatted_history.append(("human", msg["content"]))
|
| 70 |
+
elif msg["role"] == "assistant":
|
| 71 |
+
formatted_history.append(("ai", msg["content"]))
|
| 72 |
|
| 73 |
+
# Run the LangChain invocation
|
| 74 |
response = chain.invoke({
|
| 75 |
"chat_history": formatted_history,
|
| 76 |
"user_message": message
|
| 77 |
})
|
| 78 |
+
|
| 79 |
return response
|
| 80 |
|
| 81 |
# 6. Launch the Gradio Interface
|