Standardize SSE event types to "message"
Replaced various custom SSE event types like "tool_update", "tool_result", and "tool_error" with the unified "message" event type. This simplifies event handling logic and ensures consistency across all server-sent event flows.
This commit is contained in:
parent
cda44df1a0
commit
d66bb1cd7a
1 changed files with 6 additions and 6 deletions
|
@ -111,7 +111,7 @@ async def deep_research(query: str) -> AsyncGenerator[str, None]:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
yield format_sse_event(
|
yield format_sse_event(
|
||||||
"tool_update",
|
"message",
|
||||||
{"research_id": research_id, "query": query, "status": "Research initiated"}
|
{"research_id": research_id, "query": query, "status": "Research initiated"}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -123,14 +123,14 @@ async def deep_research(query: str) -> AsyncGenerator[str, None]:
|
||||||
mcp.researchers[research_id] = researcher # Speichere früh, falls benötigt
|
mcp.researchers[research_id] = researcher # Speichere früh, falls benötigt
|
||||||
|
|
||||||
yield format_sse_event(
|
yield format_sse_event(
|
||||||
"tool_update",
|
"message",
|
||||||
{"research_id": research_id, "status": "GPT Researcher initialized. Starting information gathering."}
|
{"research_id": research_id, "status": "GPT Researcher initialized. Starting information gathering."}
|
||||||
)
|
)
|
||||||
await asyncio.sleep(0.1) # Kurze Pause, damit das Event sicher gesendet wird
|
await asyncio.sleep(0.1) # Kurze Pause, damit das Event sicher gesendet wird
|
||||||
|
|
||||||
# Simuliertes Update: Beginn der Recherche
|
# Simuliertes Update: Beginn der Recherche
|
||||||
yield format_sse_event(
|
yield format_sse_event(
|
||||||
"tool_update",
|
"message",
|
||||||
{"research_id": research_id, "status": "Starting web crawling and source analysis...", "progress": 10}
|
{"research_id": research_id, "status": "Starting web crawling and source analysis...", "progress": 10}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ async def deep_research(query: str) -> AsyncGenerator[str, None]:
|
||||||
|
|
||||||
# Simuliertes Update: Recherche abgeschlossen, beginne mit der Verarbeitung
|
# Simuliertes Update: Recherche abgeschlossen, beginne mit der Verarbeitung
|
||||||
yield format_sse_event(
|
yield format_sse_event(
|
||||||
"tool_update",
|
"message",
|
||||||
{"research_id": research_id, "status": "Web crawling finished. Processing and consolidating information...", "progress": 70}
|
{"research_id": research_id, "status": "Web crawling finished. Processing and consolidating information...", "progress": 70}
|
||||||
)
|
)
|
||||||
await asyncio.sleep(0.1)
|
await asyncio.sleep(0.1)
|
||||||
|
@ -167,7 +167,7 @@ async def deep_research(query: str) -> AsyncGenerator[str, None]:
|
||||||
}
|
}
|
||||||
|
|
||||||
# Sende das finale Ergebnis als 'tool_result' Event
|
# Sende das finale Ergebnis als 'tool_result' Event
|
||||||
yield format_sse_event("tool_result", final_data_payload)
|
yield format_sse_event("message", final_data_payload)
|
||||||
logger.info(f"Sent final research result for ID: {research_id}")
|
logger.info(f"Sent final research result for ID: {research_id}")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -180,7 +180,7 @@ async def deep_research(query: str) -> AsyncGenerator[str, None]:
|
||||||
"error_message": str(e),
|
"error_message": str(e),
|
||||||
"error_details": "Check server logs for more information."
|
"error_details": "Check server logs for more information."
|
||||||
}
|
}
|
||||||
yield format_sse_event("tool_error", error_payload) # Eigener Event-Typ für Fehler
|
yield format_sse_event("message", error_payload) # Eigener Event-Typ für Fehler
|
||||||
# Du könntest hier auch handle_exception verwenden, wenn es ein SSE-Event zurückgibt
|
# Du könntest hier auch handle_exception verwenden, wenn es ein SSE-Event zurückgibt
|
||||||
# oder die Exception weiter werfen, wenn FastMCP das besser handhabt.
|
# oder die Exception weiter werfen, wenn FastMCP das besser handhabt.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue