Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
20851fb
1
Parent(s):
67d8942
Disable RAG and Search at default
Browse files
README.md
CHANGED
|
@@ -16,6 +16,8 @@ tags:
|
|
| 16 |
- building-mcp-track-creative
|
| 17 |
---
|
| 18 |
|
|
|
|
|
|
|
| 19 |
# 🩺 MedLLM Agent
|
| 20 |
|
| 21 |
**Advanced Medical AI Assistant** powered by fine-tuned MedSwin models with comprehensive knowledge retrieval capabilities.
|
|
|
|
| 16 |
- building-mcp-track-creative
|
| 17 |
---
|
| 18 |
|
| 19 |
+
[Demo](https://huggingface.co/spaces/MCP-1st-Birthday/MedLLM-Agent)
|
| 20 |
+
|
| 21 |
# 🩺 MedLLM Agent
|
| 22 |
|
| 23 |
**Advanced Medical AI Assistant** powered by fine-tuned MedSwin models with comprehensive knowledge retrieval capabilities.
|
app.py
CHANGED
|
@@ -498,29 +498,29 @@ def create_execution_plan(reasoning: dict, query: str, has_rag_index: bool) -> d
|
|
| 498 |
logger.info(f"Execution plan created: {len(plan['steps'])} steps")
|
| 499 |
return plan
|
| 500 |
|
| 501 |
-
def autonomous_execution_strategy(reasoning: dict, plan: dict, use_rag: bool, use_web_search: bool) -> dict:
|
| 502 |
"""
|
| 503 |
Autonomous execution: Make decisions on information gathering strategy.
|
| 504 |
-
|
| 505 |
"""
|
| 506 |
strategy = {
|
| 507 |
-
"use_rag": use_rag,
|
| 508 |
"use_web_search": use_web_search,
|
| 509 |
"reasoning_override": False,
|
| 510 |
"rationale": ""
|
| 511 |
}
|
| 512 |
|
| 513 |
-
#
|
| 514 |
-
if reasoning.get("requires_rag", False) and not use_rag:
|
| 515 |
-
strategy["use_rag"] = True
|
| 516 |
-
strategy["reasoning_override"] = True
|
| 517 |
-
strategy["rationale"] += "Reasoning suggests RAG is needed for this query. "
|
| 518 |
-
|
| 519 |
if reasoning.get("requires_web_search", False) and not use_web_search:
|
| 520 |
strategy["use_web_search"] = True
|
| 521 |
strategy["reasoning_override"] = True
|
| 522 |
strategy["rationale"] += "Reasoning suggests web search for current information. "
|
| 523 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 524 |
if strategy["reasoning_override"]:
|
| 525 |
logger.info(f"Autonomous override: {strategy['rationale']}")
|
| 526 |
|
|
@@ -751,10 +751,10 @@ def stream_chat(
|
|
| 751 |
|
| 752 |
# ===== AUTONOMOUS EXECUTION STRATEGY =====
|
| 753 |
logger.info("🎯 Determining execution strategy...")
|
| 754 |
-
execution_strategy = autonomous_execution_strategy(reasoning, plan, use_rag, use_web_search)
|
| 755 |
|
| 756 |
-
# Use autonomous strategy decisions
|
| 757 |
-
final_use_rag = execution_strategy["use_rag"]
|
| 758 |
final_use_web_search = execution_strategy["use_web_search"]
|
| 759 |
|
| 760 |
# Show reasoning override message if applicable
|
|
@@ -777,10 +777,6 @@ def stream_chat(
|
|
| 777 |
|
| 778 |
# Adjust system prompt based on RAG setting and reasoning
|
| 779 |
if final_use_rag:
|
| 780 |
-
if not has_rag_index:
|
| 781 |
-
yield history + [{"role": "assistant", "content": "Please upload documents first to use RAG."}]
|
| 782 |
-
return
|
| 783 |
-
|
| 784 |
base_system_prompt = system_prompt if system_prompt else "As a medical specialist, provide clinical and concise answers based on the provided medical documents and context."
|
| 785 |
else:
|
| 786 |
base_system_prompt = "As a medical specialist, provide short and concise clinical answers. Be brief and avoid lengthy explanations. Focus on key medical facts only."
|
|
@@ -1027,9 +1023,9 @@ def create_demo():
|
|
| 1027 |
with gr.Accordion("⚙️ Advanced Settings", open=False):
|
| 1028 |
with gr.Row():
|
| 1029 |
use_rag = gr.Checkbox(
|
| 1030 |
-
value=
|
| 1031 |
label="Enable Document RAG",
|
| 1032 |
-
info="Answer based on uploaded documents"
|
| 1033 |
)
|
| 1034 |
use_web_search = gr.Checkbox(
|
| 1035 |
value=False,
|
|
|
|
| 498 |
logger.info(f"Execution plan created: {len(plan['steps'])} steps")
|
| 499 |
return plan
|
| 500 |
|
| 501 |
+
def autonomous_execution_strategy(reasoning: dict, plan: dict, use_rag: bool, use_web_search: bool, has_rag_index: bool) -> dict:
|
| 502 |
"""
|
| 503 |
Autonomous execution: Make decisions on information gathering strategy.
|
| 504 |
+
Only suggests web search override, but respects user's RAG disable setting.
|
| 505 |
"""
|
| 506 |
strategy = {
|
| 507 |
+
"use_rag": use_rag, # Respect user's RAG setting
|
| 508 |
"use_web_search": use_web_search,
|
| 509 |
"reasoning_override": False,
|
| 510 |
"rationale": ""
|
| 511 |
}
|
| 512 |
|
| 513 |
+
# Only suggest web search override (RAG requires documents, so we respect user's choice)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 514 |
if reasoning.get("requires_web_search", False) and not use_web_search:
|
| 515 |
strategy["use_web_search"] = True
|
| 516 |
strategy["reasoning_override"] = True
|
| 517 |
strategy["rationale"] += "Reasoning suggests web search for current information. "
|
| 518 |
|
| 519 |
+
# Note: We don't override RAG setting because:
|
| 520 |
+
# 1. User may have explicitly disabled it
|
| 521 |
+
# 2. RAG requires documents to be uploaded
|
| 522 |
+
# 3. We should respect user's explicit choice
|
| 523 |
+
|
| 524 |
if strategy["reasoning_override"]:
|
| 525 |
logger.info(f"Autonomous override: {strategy['rationale']}")
|
| 526 |
|
|
|
|
| 751 |
|
| 752 |
# ===== AUTONOMOUS EXECUTION STRATEGY =====
|
| 753 |
logger.info("🎯 Determining execution strategy...")
|
| 754 |
+
execution_strategy = autonomous_execution_strategy(reasoning, plan, use_rag, use_web_search, has_rag_index)
|
| 755 |
|
| 756 |
+
# Use autonomous strategy decisions (respect user's RAG setting)
|
| 757 |
+
final_use_rag = execution_strategy["use_rag"] and has_rag_index # Only use RAG if enabled AND documents exist
|
| 758 |
final_use_web_search = execution_strategy["use_web_search"]
|
| 759 |
|
| 760 |
# Show reasoning override message if applicable
|
|
|
|
| 777 |
|
| 778 |
# Adjust system prompt based on RAG setting and reasoning
|
| 779 |
if final_use_rag:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 780 |
base_system_prompt = system_prompt if system_prompt else "As a medical specialist, provide clinical and concise answers based on the provided medical documents and context."
|
| 781 |
else:
|
| 782 |
base_system_prompt = "As a medical specialist, provide short and concise clinical answers. Be brief and avoid lengthy explanations. Focus on key medical facts only."
|
|
|
|
| 1023 |
with gr.Accordion("⚙️ Advanced Settings", open=False):
|
| 1024 |
with gr.Row():
|
| 1025 |
use_rag = gr.Checkbox(
|
| 1026 |
+
value=False,
|
| 1027 |
label="Enable Document RAG",
|
| 1028 |
+
info="Answer based on uploaded documents (requires document upload)"
|
| 1029 |
)
|
| 1030 |
use_web_search = gr.Checkbox(
|
| 1031 |
value=False,
|