Files
dsProject/dsRagAnything/T2_Query.py

28 lines
788 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
async def main():
try:
2025-08-26 14:33:36 +08:00
user_prompt = "简洁回复。"
rag = await initialize_rag('Topic/Geogebra')
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()
asyncio.run(main())