YanSte commited on
Commit
8746512
·
1 Parent(s): a9313ac
examples/lightrag_openai_compatible_stream_demo.py CHANGED
@@ -1,7 +1,8 @@
 
1
  import os
2
  from lightrag import LightRAG
3
  from lightrag.llm import openai_complete, openai_embed
4
- from lightrag.utils import EmbeddingFunc
5
  from lightrag import QueryParam
6
 
7
  # WorkingDir
@@ -44,3 +45,10 @@ async def print_stream(stream):
44
  async for chunk in stream:
45
  if chunk:
46
  print(chunk, end="", flush=True)
 
 
 
 
 
 
 
 
1
+ import inspect
2
  import os
3
  from lightrag import LightRAG
4
  from lightrag.llm import openai_complete, openai_embed
5
+ from lightrag.utils import EmbeddingFunc, always_get_an_event_loop
6
  from lightrag import QueryParam
7
 
8
  # WorkingDir
 
45
  async for chunk in stream:
46
  if chunk:
47
  print(chunk, end="", flush=True)
48
+
49
+
50
+ loop = always_get_an_event_loop()
51
+ if inspect.isasyncgen(resp):
52
+ loop.run_until_complete(print_stream(resp))
53
+ else:
54
+ print(resp)