Change OpenAI demo to asyc

This commit is contained in:
yangdx
2025-04-20 21:39:51 +08:00
parent dd4f92dae2
commit 697401fdc3

View File

@@ -24,41 +24,41 @@ async def initialize_rag():
return rag return rag
def main(): async def main():
# Initialize RAG instance # Initialize RAG instance
rag = asyncio.run(initialize_rag()) rag = await initialize_rag()
with open("./book.txt", "r", encoding="utf-8") as f: with open("./book.txt", "r", encoding="utf-8") as f:
rag.insert(f.read()) await rag.ainsert(f.read())
# Perform naive search # Perform naive search
print( print(
rag.query( await rag.aquery(
"What are the top themes in this story?", param=QueryParam(mode="naive") "What are the top themes in this story?", param=QueryParam(mode="naive")
) )
) )
# Perform local search # Perform local search
print( print(
rag.query( await rag.aquery(
"What are the top themes in this story?", param=QueryParam(mode="local") "What are the top themes in this story?", param=QueryParam(mode="local")
) )
) )
# Perform global search # Perform global search
print( print(
rag.query( await rag.aquery(
"What are the top themes in this story?", param=QueryParam(mode="global") "What are the top themes in this story?", param=QueryParam(mode="global")
) )
) )
# Perform hybrid search # Perform hybrid search
print( print(
rag.query( await rag.aquery(
"What are the top themes in this story?", param=QueryParam(mode="hybrid") "What are the top themes in this story?", param=QueryParam(mode="hybrid")
) )
) )
if __name__ == "__main__": if __name__ == "__main__":
main() asyncio.run(main())