Spaces:
Running
on
Zero
Running
on
Zero
Y Phung Nguyen
commited on
Commit
·
0cd2df1
1
Parent(s):
5487be8
Lim search and subtask breaker
Browse files- pipeline.py +3 -2
- supervisor.py +9 -4
pipeline.py
CHANGED
|
@@ -21,7 +21,8 @@ from supervisor import (
|
|
| 21 |
gemini_supervisor_rag_brainstorm, execute_medswin_task,
|
| 22 |
gemini_supervisor_synthesize, gemini_supervisor_challenge,
|
| 23 |
gemini_supervisor_enhance_answer, gemini_supervisor_check_clarity,
|
| 24 |
-
gemini_clinical_intake_triage, gemini_summarize_clinical_insights
|
|
|
|
| 25 |
)
|
| 26 |
|
| 27 |
MAX_CLINICAL_QA_ROUNDS = 5
|
|
@@ -463,7 +464,7 @@ def stream_chat(
|
|
| 463 |
|
| 464 |
all_search_results = []
|
| 465 |
strategy_jobs = []
|
| 466 |
-
for strategy in search_strategies.get("search_strategies", [])[:
|
| 467 |
search_query = strategy.get("strategy", message)
|
| 468 |
target_sources = strategy.get("target_sources", 2)
|
| 469 |
strategy_jobs.append({
|
|
|
|
| 21 |
gemini_supervisor_rag_brainstorm, execute_medswin_task,
|
| 22 |
gemini_supervisor_synthesize, gemini_supervisor_challenge,
|
| 23 |
gemini_supervisor_enhance_answer, gemini_supervisor_check_clarity,
|
| 24 |
+
gemini_clinical_intake_triage, gemini_summarize_clinical_insights,
|
| 25 |
+
MAX_SEARCH_STRATEGIES
|
| 26 |
)
|
| 27 |
|
| 28 |
MAX_CLINICAL_QA_ROUNDS = 5
|
|
|
|
| 464 |
|
| 465 |
all_search_results = []
|
| 466 |
strategy_jobs = []
|
| 467 |
+
for strategy in search_strategies.get("search_strategies", [])[:MAX_SEARCH_STRATEGIES]:
|
| 468 |
search_query = strategy.get("strategy", message)
|
| 469 |
target_sources = strategy.get("target_sources", 2)
|
| 470 |
strategy_jobs.append({
|
supervisor.py
CHANGED
|
@@ -8,6 +8,11 @@ from client import MCP_AVAILABLE, call_agent
|
|
| 8 |
from config import GEMINI_MODEL, GEMINI_MODEL_LITE
|
| 9 |
from utils import format_prompt_manually
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
try:
|
| 12 |
import nest_asyncio
|
| 13 |
except ImportError:
|
|
@@ -28,7 +33,7 @@ async def gemini_supervisor_breakdown_async(query: str, use_rag: bool, use_web_s
|
|
| 28 |
|
| 29 |
estimated_time_per_task = 8
|
| 30 |
max_topics_by_time = max(2, int((remaining_time - 20) / estimated_time_per_task))
|
| 31 |
-
max_topics = min(max_topics_by_time,
|
| 32 |
|
| 33 |
prompt = f"""You are a supervisor agent coordinating with a MedSwin medical specialist model.
|
| 34 |
Break the following medical query into focused sub-topics that MedSwin can answer sequentially.
|
|
@@ -110,9 +115,9 @@ Guidelines:
|
|
| 110 |
|
| 111 |
|
| 112 |
async def gemini_supervisor_search_strategies_async(query: str, time_elapsed: float) -> dict:
|
| 113 |
-
"""Gemini Supervisor: In search mode, break query into
|
| 114 |
prompt = f"""You are supervising web search for a medical query.
|
| 115 |
-
Break this query into 1-
|
| 116 |
|
| 117 |
Query: "{query}"
|
| 118 |
|
|
@@ -127,7 +132,7 @@ Return ONLY valid JSON:
|
|
| 127 |
}},
|
| 128 |
...
|
| 129 |
],
|
| 130 |
-
"max_strategies":
|
| 131 |
}}
|
| 132 |
|
| 133 |
Keep strategies focused and avoid overlap."""
|
|
|
|
| 8 |
from config import GEMINI_MODEL, GEMINI_MODEL_LITE
|
| 9 |
from utils import format_prompt_manually
|
| 10 |
|
| 11 |
+
# Maximum number of subtasks for query breakdown
|
| 12 |
+
MAX_SUBTASKS = 5
|
| 13 |
+
# Maximum number of search strategies
|
| 14 |
+
MAX_SEARCH_STRATEGIES = 3
|
| 15 |
+
|
| 16 |
try:
|
| 17 |
import nest_asyncio
|
| 18 |
except ImportError:
|
|
|
|
| 33 |
|
| 34 |
estimated_time_per_task = 8
|
| 35 |
max_topics_by_time = max(2, int((remaining_time - 20) / estimated_time_per_task))
|
| 36 |
+
max_topics = min(max_topics_by_time, MAX_SUBTASKS)
|
| 37 |
|
| 38 |
prompt = f"""You are a supervisor agent coordinating with a MedSwin medical specialist model.
|
| 39 |
Break the following medical query into focused sub-topics that MedSwin can answer sequentially.
|
|
|
|
| 115 |
|
| 116 |
|
| 117 |
async def gemini_supervisor_search_strategies_async(query: str, time_elapsed: float) -> dict:
|
| 118 |
+
"""Gemini Supervisor: In search mode, break query into searching strategies"""
|
| 119 |
prompt = f"""You are supervising web search for a medical query.
|
| 120 |
+
Break this query into 1-{MAX_SEARCH_STRATEGIES} focused search strategies (each targeting 1-2 sources).
|
| 121 |
|
| 122 |
Query: "{query}"
|
| 123 |
|
|
|
|
| 132 |
}},
|
| 133 |
...
|
| 134 |
],
|
| 135 |
+
"max_strategies": {MAX_SEARCH_STRATEGIES}
|
| 136 |
}}
|
| 137 |
|
| 138 |
Keep strategies focused and avoid overlap."""
|