Commit
·
db54eb2
1
Parent(s):
4a3dec8
fix: restarts conversation -> restart state['app']
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import uuid
|
| 2 |
import os
|
| 3 |
import gradio as gr
|
| 4 |
-
|
| 5 |
from langchain_core.messages import HumanMessage, AIMessage
|
| 6 |
|
| 7 |
# Assuming mcpc_graph.py and its setup_graph function are in the same directory.
|
|
@@ -98,7 +98,7 @@ async def chat_logic(
|
|
| 98 |
session_state["is_message_command"] = True
|
| 99 |
yield interruption_message.value
|
| 100 |
return # Stop the stream and wait for the user's next message.
|
| 101 |
-
|
| 102 |
|
| 103 |
def create_gradio_app():
|
| 104 |
"""Creates and launches the Gradio web application."""
|
|
@@ -194,6 +194,28 @@ def create_gradio_app():
|
|
| 194 |
avatar_images=(None, AVATAR_BOT)
|
| 195 |
)
|
| 196 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
|
| 198 |
gr.ChatInterface(
|
| 199 |
fn=chat_logic,
|
|
|
|
| 1 |
import uuid
|
| 2 |
import os
|
| 3 |
import gradio as gr
|
| 4 |
+
from loguru import logger
|
| 5 |
from langchain_core.messages import HumanMessage, AIMessage
|
| 6 |
|
| 7 |
# Assuming mcpc_graph.py and its setup_graph function are in the same directory.
|
|
|
|
| 98 |
session_state["is_message_command"] = True
|
| 99 |
yield interruption_message.value
|
| 100 |
return # Stop the stream and wait for the user's next message.
|
| 101 |
+
|
| 102 |
|
| 103 |
def create_gradio_app():
|
| 104 |
"""Creates and launches the Gradio web application."""
|
|
|
|
| 194 |
avatar_images=(None, AVATAR_BOT)
|
| 195 |
)
|
| 196 |
|
| 197 |
+
# 🆕 add this helper next to create_gradio_app()
|
| 198 |
+
def _reset_agent(state: dict):
|
| 199 |
+
"""
|
| 200 |
+
Runs when the user clicks the 🗑 button.
|
| 201 |
+
|
| 202 |
+
Keeps the API credentials that live in the Textboxes and the env-vars,
|
| 203 |
+
but forgets everything that makes the current LangGraph session unique,
|
| 204 |
+
so the next user message starts from the root node again.
|
| 205 |
+
"""
|
| 206 |
+
logger.info("Resetting the agent")
|
| 207 |
+
state["app"] = None
|
| 208 |
+
return state
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
# 🆕 2. bind it to the built-in clear event --------------
|
| 212 |
+
chatbot.clear(
|
| 213 |
+
_reset_agent, # fn
|
| 214 |
+
inputs=[session_state], # what the fn receives
|
| 215 |
+
outputs=[session_state], # what the fn updates
|
| 216 |
+
)
|
| 217 |
+
# --------------------------------------------------------
|
| 218 |
+
|
| 219 |
|
| 220 |
gr.ChatInterface(
|
| 221 |
fn=chat_logic,
|