Spaces:
Runtime error
Runtime error
potential fix to return news object type 6
Browse files
crew.py
CHANGED
|
@@ -623,6 +623,22 @@ def _parse_json_output(text: str) -> dict:
|
|
| 623 |
|
| 624 |
raise ValueError(f"Could not parse JSON from: {text[:200]}...")
|
| 625 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 626 |
def run_crewai_lifestyle(docID: str) -> dict:
|
| 627 |
try:
|
| 628 |
lifestyle_data = pull_lifestyle(docID)
|
|
@@ -719,14 +735,14 @@ def run_crewai_news_patient(count: int = 5) -> dict:
|
|
| 719 |
verbose=True,
|
| 720 |
function_calling=True
|
| 721 |
)
|
| 722 |
-
|
| 723 |
-
result = gather_news_patient.run(count)
|
| 724 |
# CrewAI returns ToolOutput → .raw or str — parse if needed
|
| 725 |
|
| 726 |
-
|
| 727 |
-
return result
|
| 728 |
-
|
| 729 |
-
return {"status": "error", "message": "Failed to parse crew output
|
| 730 |
|
| 731 |
def run_crewai_news_doctor(count: int = 5) -> dict:
|
| 732 |
crew = Crew(
|
|
|
|
| 623 |
|
| 624 |
raise ValueError(f"Could not parse JSON from: {text[:200]}...")
|
| 625 |
|
| 626 |
+
def parse_json_from_markdown(s: str) -> dict:
|
| 627 |
+
"""
|
| 628 |
+
Extracts and parses JSON from a string that may be wrapped in ``` or ```json.
|
| 629 |
+
Returns dict on success, or raises ValueError on failure.
|
| 630 |
+
"""
|
| 631 |
+
# Try to find JSON inside ```json ... ``` or ``` ... ```
|
| 632 |
+
match = re.search(r"```(?:json)?\s*({.*})\s*```", s, re.DOTALL | re.IGNORECASE)
|
| 633 |
+
if match:
|
| 634 |
+
json_str = match.group(1)
|
| 635 |
+
else:
|
| 636 |
+
# Fallback: assume whole string is JSON (e.g., raw dict from function_calling=True)
|
| 637 |
+
json_str = s.strip()
|
| 638 |
+
|
| 639 |
+
# Parse
|
| 640 |
+
return json.loads(json_str)
|
| 641 |
+
|
| 642 |
def run_crewai_lifestyle(docID: str) -> dict:
|
| 643 |
try:
|
| 644 |
lifestyle_data = pull_lifestyle(docID)
|
|
|
|
| 735 |
verbose=True,
|
| 736 |
function_calling=True
|
| 737 |
)
|
| 738 |
+
result = crew.kickoff(inputs={"count": count})
|
| 739 |
+
# result = gather_news_patient.run(count)
|
| 740 |
# CrewAI returns ToolOutput → .raw or str — parse if needed
|
| 741 |
|
| 742 |
+
try:
|
| 743 |
+
return parse_json_from_markdown(str(result))
|
| 744 |
+
except Exception as e:
|
| 745 |
+
return {"status": "error", "message": f"Failed to parse crew output, <{e}>", "raw": result}
|
| 746 |
|
| 747 |
def run_crewai_news_doctor(count: int = 5) -> dict:
|
| 748 |
crew = Crew(
|