mirror of
https://github.com/HKUDS/LightRAG.git
synced 2025-12-18 02:12:28 +00:00
fix: streaming error when only_need_context=True returns empty results
Prevents NoneType async iteration error by handling None responses in stream_generator and ensuring kg_query returns valid strings.
This commit is contained in:
parent
a506753548
commit
0f51ec48f1
@ -183,6 +183,9 @@ def create_query_routes(rag, api_key: Optional[str] = None, top_k: int = 60):
|
|||||||
if isinstance(response, str):
|
if isinstance(response, str):
|
||||||
# If it's a string, send it all at once
|
# If it's a string, send it all at once
|
||||||
yield f"{json.dumps({'response': response})}\n"
|
yield f"{json.dumps({'response': response})}\n"
|
||||||
|
elif response is None:
|
||||||
|
# Handle None response (e.g., when only_need_context=True but no context found)
|
||||||
|
yield f"{json.dumps({'response': 'No relevant context found for the query.'})}\n"
|
||||||
else:
|
else:
|
||||||
# If it's an async generator, send chunks one by one
|
# If it's an async generator, send chunks one by one
|
||||||
try:
|
try:
|
||||||
|
|||||||
@ -1390,7 +1390,7 @@ async def kg_query(
|
|||||||
)
|
)
|
||||||
|
|
||||||
if query_param.only_need_context:
|
if query_param.only_need_context:
|
||||||
return context
|
return context if context is not None else PROMPTS["fail_response"]
|
||||||
if context is None:
|
if context is None:
|
||||||
return PROMPTS["fail_response"]
|
return PROMPTS["fail_response"]
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user