Files
dsProject/dsRagAnything/T2_Query.py

29 lines
830 B
Python
Raw Normal View History

2025-08-26 14:29:13 +08:00
import asyncio
import inspect
from Util.LightRagUtil import configure_logging, initialize_rag, print_stream
from lightrag import QueryParam
2025-08-26 16:20:00 +08:00
async def query(user_prompt,rag_path):
2025-08-26 14:29:13 +08:00
try:
2025-08-26 16:20:00 +08:00
rag = await initialize_rag(rag_path)
2025-08-26 14:29:13 +08:00
resp = await rag.aquery(
2025-08-26 16:20:00 +08:00
user_prompt,
2025-08-26 14:29:13 +08:00
param=QueryParam(mode="hybrid", stream=True, user_prompt=user_prompt),
)
if inspect.isasyncgen(resp):
await print_stream(resp)
else:
print(resp)
except Exception as e:
print(f"An error occurred: {e}")
finally:
if rag:
await rag.finalize_storages()
if __name__ == "__main__":
2025-08-27 08:04:00 +08:00
rag_path='./Topic/Geogebra'
2025-08-26 16:20:00 +08:00
user_prompt = "简洁回复。"
2025-08-26 14:29:13 +08:00
configure_logging()
2025-08-26 16:20:00 +08:00
asyncio.run(query(user_prompt,rag_path))