mirror of
https://github.com/ollama/ollama-python.git
synced 2026-07-21 09:05:23 -04:00
asyncio.run() cannot be called from a running event loop #10
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @chenxizhang on GitHub (Jan 27, 2024).
I am using python 3.11.7 and the latest version of the Ollama pythons SDKs to run the sample code about AsyncClient
I got an error as below.
RuntimeError Traceback (most recent call last)
Cell In[7], line 8
5 message ={ "role":"user","content":"why people smile?"}
6 response = await AsyncClient().chat(model="llama2",message=[message])
----> 8 asyncio.run(chat())
File ~/anaconda3/envs/tedia/lib/python3.11/asyncio/runners.py:186, in run(main, debug)
161 """Execute the coroutine and return the result.
162
163 This function runs the passed coroutine, taking care of
(...)
182 asyncio.run(main())
183 """
184 if events._get_running_loop() is not None:
185 # fail fast with short traceback
--> 186 raise RuntimeError(
187 "asyncio.run() cannot be called from a running event loop")
189 with Runner(debug=debug) as runner:
190 return runner.run(main)
RuntimeError: asyncio.run() cannot be called from a running event loop
@chenxizhang commented on GitHub (Jan 27, 2024):
fixed it, and added some sample code in this pr #36