Spaces:
Running
on
Zero
Running
on
Zero
Y Phung Nguyen
commited on
Commit
·
46971ea
1
Parent(s):
fc23c24
Fix syntax
Browse files- pipeline.py +16 -16
pipeline.py
CHANGED
|
@@ -89,6 +89,12 @@ def stream_chat(
|
|
| 89 |
final_use_rag = use_rag and has_rag_index and not disable_agentic_reasoning
|
| 90 |
final_use_web_search = use_web_search and not disable_agentic_reasoning
|
| 91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
plan = None
|
| 93 |
if not disable_agentic_reasoning:
|
| 94 |
reasoning_stage_start = time.time()
|
|
@@ -119,9 +125,8 @@ def stream_chat(
|
|
| 119 |
pipeline_diagnostics["strategy_decisions"].append("Agentic reasoning disabled by user")
|
| 120 |
|
| 121 |
# Update thoughts after reasoning stage
|
| 122 |
-
if show_thoughts and thought_handler
|
| 123 |
-
|
| 124 |
-
yield updated_history, thoughts_text
|
| 125 |
|
| 126 |
if disable_agentic_reasoning:
|
| 127 |
logger.info("[MAC] Agentic reasoning disabled - using MedSwin alone")
|
|
@@ -138,9 +143,8 @@ def stream_chat(
|
|
| 138 |
logger.info(f"[GEMINI SUPERVISOR] Created {len(breakdown.get('sub_topics', []))} sub-topics")
|
| 139 |
|
| 140 |
# Update thoughts after breakdown
|
| 141 |
-
if show_thoughts and thought_handler
|
| 142 |
-
|
| 143 |
-
yield updated_history, thoughts_text
|
| 144 |
|
| 145 |
search_contexts = []
|
| 146 |
web_urls = []
|
|
@@ -259,11 +263,8 @@ def stream_chat(
|
|
| 259 |
logger.info(f"[MEDSWIN] Executing {len(breakdown.get('sub_topics', []))} tasks sequentially...")
|
| 260 |
medswin_answers = []
|
| 261 |
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
{"role": "assistant", "content": ""}
|
| 265 |
-
]
|
| 266 |
-
thoughts_text = thought_handler.get_thoughts() if thought_handler else ""
|
| 267 |
yield updated_history, thoughts_text
|
| 268 |
|
| 269 |
medswin_stage_start = time.time()
|
|
@@ -302,7 +303,7 @@ def stream_chat(
|
|
| 302 |
|
| 303 |
partial_final = "\n\n".join(medswin_answers)
|
| 304 |
updated_history[-1]["content"] = partial_final
|
| 305 |
-
thoughts_text = thought_handler.get_thoughts() if thought_handler else ""
|
| 306 |
yield updated_history, thoughts_text
|
| 307 |
|
| 308 |
except Exception as e:
|
|
@@ -409,9 +410,8 @@ def stream_chat(
|
|
| 409 |
record_stage("followup_search", followup_stage_start)
|
| 410 |
|
| 411 |
# Update thoughts after followup search
|
| 412 |
-
if show_thoughts and thought_handler
|
| 413 |
-
|
| 414 |
-
yield updated_history, thoughts_text
|
| 415 |
|
| 416 |
citations_text = ""
|
| 417 |
|
|
@@ -434,7 +434,7 @@ def stream_chat(
|
|
| 434 |
final_answer_with_metadata = final_answer + citations_text + speaker_icon
|
| 435 |
|
| 436 |
updated_history[-1]["content"] = final_answer_with_metadata
|
| 437 |
-
thoughts_text = thought_handler.get_thoughts() if thought_handler else ""
|
| 438 |
# Always yield thoughts_text, even if empty, to ensure UI updates
|
| 439 |
yield updated_history, thoughts_text
|
| 440 |
|
|
|
|
| 89 |
final_use_rag = use_rag and has_rag_index and not disable_agentic_reasoning
|
| 90 |
final_use_web_search = use_web_search and not disable_agentic_reasoning
|
| 91 |
|
| 92 |
+
# Initialize updated_history early to avoid UnboundLocalError
|
| 93 |
+
updated_history = history + [
|
| 94 |
+
{"role": "user", "content": original_message},
|
| 95 |
+
{"role": "assistant", "content": ""}
|
| 96 |
+
]
|
| 97 |
+
|
| 98 |
plan = None
|
| 99 |
if not disable_agentic_reasoning:
|
| 100 |
reasoning_stage_start = time.time()
|
|
|
|
| 125 |
pipeline_diagnostics["strategy_decisions"].append("Agentic reasoning disabled by user")
|
| 126 |
|
| 127 |
# Update thoughts after reasoning stage
|
| 128 |
+
thoughts_text = thought_handler.get_thoughts() if (show_thoughts and thought_handler) else ""
|
| 129 |
+
yield updated_history, thoughts_text
|
|
|
|
| 130 |
|
| 131 |
if disable_agentic_reasoning:
|
| 132 |
logger.info("[MAC] Agentic reasoning disabled - using MedSwin alone")
|
|
|
|
| 143 |
logger.info(f"[GEMINI SUPERVISOR] Created {len(breakdown.get('sub_topics', []))} sub-topics")
|
| 144 |
|
| 145 |
# Update thoughts after breakdown
|
| 146 |
+
thoughts_text = thought_handler.get_thoughts() if (show_thoughts and thought_handler) else ""
|
| 147 |
+
yield updated_history, thoughts_text
|
|
|
|
| 148 |
|
| 149 |
search_contexts = []
|
| 150 |
web_urls = []
|
|
|
|
| 263 |
logger.info(f"[MEDSWIN] Executing {len(breakdown.get('sub_topics', []))} tasks sequentially...")
|
| 264 |
medswin_answers = []
|
| 265 |
|
| 266 |
+
# Update thoughts before starting MedSwin tasks
|
| 267 |
+
thoughts_text = thought_handler.get_thoughts() if (show_thoughts and thought_handler) else ""
|
|
|
|
|
|
|
|
|
|
| 268 |
yield updated_history, thoughts_text
|
| 269 |
|
| 270 |
medswin_stage_start = time.time()
|
|
|
|
| 303 |
|
| 304 |
partial_final = "\n\n".join(medswin_answers)
|
| 305 |
updated_history[-1]["content"] = partial_final
|
| 306 |
+
thoughts_text = thought_handler.get_thoughts() if (show_thoughts and thought_handler) else ""
|
| 307 |
yield updated_history, thoughts_text
|
| 308 |
|
| 309 |
except Exception as e:
|
|
|
|
| 410 |
record_stage("followup_search", followup_stage_start)
|
| 411 |
|
| 412 |
# Update thoughts after followup search
|
| 413 |
+
thoughts_text = thought_handler.get_thoughts() if (show_thoughts and thought_handler) else ""
|
| 414 |
+
yield updated_history, thoughts_text
|
|
|
|
| 415 |
|
| 416 |
citations_text = ""
|
| 417 |
|
|
|
|
| 434 |
final_answer_with_metadata = final_answer + citations_text + speaker_icon
|
| 435 |
|
| 436 |
updated_history[-1]["content"] = final_answer_with_metadata
|
| 437 |
+
thoughts_text = thought_handler.get_thoughts() if (show_thoughts and thought_handler) else ""
|
| 438 |
# Always yield thoughts_text, even if empty, to ensure UI updates
|
| 439 |
yield updated_history, thoughts_text
|
| 440 |
|