Files
dsProject/dsRagAnything/T2_Query.py

28 lines
796 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:10:40 +08:00
async def query():
2025-08-26 14:29:13 +08:00
try:
2025-08-26 14:33:36 +08:00
user_prompt = "简洁回复。"
2025-08-26 16:10:40 +08:00
rag = await initialize_rag('./Topic/HuangWanQiao')
2025-08-26 14:29:13 +08:00
resp = await rag.aquery(
2025-08-26 14:33:36 +08:00
"文档的主要内容是什么",
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__":
configure_logging()
2025-08-26 16:10:40 +08:00
asyncio.run(query())