You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.2 KiB

import asyncio
import inspect
from Util.LightRagUtil import configure_logging, initialize_rag, print_stream
from lightrag import QueryParam
# 化学
data = [
{"NAME": "Chemistry", "Q": "氧化铁与硝酸的化学反应方程式是什么", "ChineseName": "化学"},
{"NAME": "Math", "Q": "氧化铁与硝酸的化学反应方程式是什么", "ChineseName": "数学"},
{"NAME": "Chinese", "Q": "氧化铁与硝酸的化学反应方程式是什么", "ChineseName": "语文"}]
# 准备查询的科目
KEMU = "Chemistry"
# 查找索引号
idx = [i for i, d in enumerate(data) if d["NAME"] == KEMU][0]
async def main():
try:
rag = await initialize_rag('Topic/' + data[idx]["NAME"])
resp = await rag.aquery(
data[idx]["Q"],
param=QueryParam(mode="hybrid", stream=True),
)
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())