Files
dsProject/dsRagAnything/T2_Query.py
2025-08-27 08:04:00 +08:00

29 lines
830 B
Python

import asyncio
import inspect
from Util.LightRagUtil import configure_logging, initialize_rag, print_stream
from lightrag import QueryParam
async def query(user_prompt,rag_path):
try:
rag = await initialize_rag(rag_path)
resp = await rag.aquery(
user_prompt,
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__":
rag_path='./Topic/Geogebra'
user_prompt = "简洁回复。"
configure_logging()
asyncio.run(query(user_prompt,rag_path))