Spaces:
Sleeping
Sleeping
Graham Paasch commited on
Commit ·
ad6849b
1
Parent(s): e085479
Fix Gradio State schema error - simplify consultation state to avoid JSON schema processing bug
Browse files
app.py
CHANGED
|
@@ -269,38 +269,40 @@ def build_ui():
|
|
| 269 |
interactive=False,
|
| 270 |
)
|
| 271 |
|
| 272 |
-
# Consultation state
|
| 273 |
-
consultation_state = gr.State(value=
|
| 274 |
|
| 275 |
def start_consultation():
|
| 276 |
"""Initialize a new consultation"""
|
| 277 |
-
return
|
| 278 |
-
"consultant": None,
|
| 279 |
-
"is_complete": False
|
| 280 |
-
}, [], ""
|
| 281 |
|
| 282 |
def send_consultation_message(user_message, state):
|
| 283 |
"""Send a message in the consultation"""
|
| 284 |
if not user_message.strip():
|
| 285 |
-
#
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
chatbot_messages[-1]
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
|
|
|
| 300 |
return state, [], ""
|
| 301 |
|
| 302 |
from agent.consultation import NetworkConsultant
|
| 303 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 304 |
# Get or create consultant
|
| 305 |
consultant = state.get("consultant")
|
| 306 |
first_message = consultant is None
|
|
@@ -342,6 +344,9 @@ def build_ui():
|
|
| 342 |
|
| 343 |
def use_consultation_summary(state):
|
| 344 |
"""Extract the consultation summary for use in the pipeline"""
|
|
|
|
|
|
|
|
|
|
| 345 |
consultant = state.get("consultant")
|
| 346 |
if not consultant or not consultant.conversation_history:
|
| 347 |
return "No consultation history yet. Start a conversation first!"
|
|
|
|
| 269 |
interactive=False,
|
| 270 |
)
|
| 271 |
|
| 272 |
+
# Consultation state - use None as default to avoid Gradio schema issues
|
| 273 |
+
consultation_state = gr.State(value=None)
|
| 274 |
|
| 275 |
def start_consultation():
|
| 276 |
"""Initialize a new consultation"""
|
| 277 |
+
return None, [], ""
|
|
|
|
|
|
|
|
|
|
| 278 |
|
| 279 |
def send_consultation_message(user_message, state):
|
| 280 |
"""Send a message in the consultation"""
|
| 281 |
if not user_message.strip():
|
| 282 |
+
# Return empty if no message
|
| 283 |
+
if state and isinstance(state, dict):
|
| 284 |
+
consultant = state.get("consultant")
|
| 285 |
+
if consultant and hasattr(consultant, 'conversation_history'):
|
| 286 |
+
# Convert conversation history to chatbot format
|
| 287 |
+
chatbot_messages = []
|
| 288 |
+
for msg in consultant.conversation_history:
|
| 289 |
+
if msg.role == "user" and not msg.content.startswith("Initial request:"):
|
| 290 |
+
chatbot_messages.append((msg.content, None))
|
| 291 |
+
elif msg.role == "assistant" and chatbot_messages:
|
| 292 |
+
# Pair with previous user message
|
| 293 |
+
if chatbot_messages[-1][1] is None:
|
| 294 |
+
chatbot_messages[-1] = (chatbot_messages[-1][0], msg.content)
|
| 295 |
+
else:
|
| 296 |
+
chatbot_messages.append((None, msg.content))
|
| 297 |
+
return state, chatbot_messages, ""
|
| 298 |
return state, [], ""
|
| 299 |
|
| 300 |
from agent.consultation import NetworkConsultant
|
| 301 |
|
| 302 |
+
# Initialize state if needed
|
| 303 |
+
if not state:
|
| 304 |
+
state = {}
|
| 305 |
+
|
| 306 |
# Get or create consultant
|
| 307 |
consultant = state.get("consultant")
|
| 308 |
first_message = consultant is None
|
|
|
|
| 344 |
|
| 345 |
def use_consultation_summary(state):
|
| 346 |
"""Extract the consultation summary for use in the pipeline"""
|
| 347 |
+
if not state or not isinstance(state, dict):
|
| 348 |
+
return "No consultation history yet. Start a conversation first!"
|
| 349 |
+
|
| 350 |
consultant = state.get("consultant")
|
| 351 |
if not consultant or not consultant.conversation_history:
|
| 352 |
return "No consultation history yet. Start a conversation first!"
|