yangdx commited on
Commit
28e64e8
·
1 Parent(s): 9b94a71

Change OpenAI demo to asyc

Browse files
Files changed (1) hide show
  1. examples/lightrag_openai_demo.py +8 -8
examples/lightrag_openai_demo.py CHANGED
@@ -24,41 +24,41 @@ async def initialize_rag():
24
  return rag
25
 
26
 
27
- def main():
28
  # Initialize RAG instance
29
- rag = asyncio.run(initialize_rag())
30
 
31
  with open("./book.txt", "r", encoding="utf-8") as f:
32
- rag.insert(f.read())
33
 
34
  # Perform naive search
35
  print(
36
- rag.query(
37
  "What are the top themes in this story?", param=QueryParam(mode="naive")
38
  )
39
  )
40
 
41
  # Perform local search
42
  print(
43
- rag.query(
44
  "What are the top themes in this story?", param=QueryParam(mode="local")
45
  )
46
  )
47
 
48
  # Perform global search
49
  print(
50
- rag.query(
51
  "What are the top themes in this story?", param=QueryParam(mode="global")
52
  )
53
  )
54
 
55
  # Perform hybrid search
56
  print(
57
- rag.query(
58
  "What are the top themes in this story?", param=QueryParam(mode="hybrid")
59
  )
60
  )
61
 
62
 
63
  if __name__ == "__main__":
64
- main()
 
24
  return rag
25
 
26
 
27
+ async def main():
28
  # Initialize RAG instance
29
+ rag = await initialize_rag()
30
 
31
  with open("./book.txt", "r", encoding="utf-8") as f:
32
+ await rag.ainsert(f.read())
33
 
34
  # Perform naive search
35
  print(
36
+ await rag.aquery(
37
  "What are the top themes in this story?", param=QueryParam(mode="naive")
38
  )
39
  )
40
 
41
  # Perform local search
42
  print(
43
+ await rag.aquery(
44
  "What are the top themes in this story?", param=QueryParam(mode="local")
45
  )
46
  )
47
 
48
  # Perform global search
49
  print(
50
+ await rag.aquery(
51
  "What are the top themes in this story?", param=QueryParam(mode="global")
52
  )
53
  )
54
 
55
  # Perform hybrid search
56
  print(
57
+ await rag.aquery(
58
  "What are the top themes in this story?", param=QueryParam(mode="hybrid")
59
  )
60
  )
61
 
62
 
63
  if __name__ == "__main__":
64
+ asyncio.run(main())