gpt4free
gpt4free copied to clipboard
There is no current event loop in thread 'Thread-27
I am getting this in V0.1.4.0.
Most providers are not working anymore. Only Vercel still seems to work - is there a fix?
2023-09-27 20:37:55,292 - INFO - No or invalid response from <class 'g4f.Provider.H2o.H2o'>: There is no current event loop in thread 'Thread-27 (process_request_thread)'. 2023-09-27 20:37:55,293 - INFO - No or invalid response from <class 'g4f.Provider.ChatgptLogin.ChatgptLogin'>: There is no current event loop in thread 'Thread-27 (process_request_thread)'. 2023-09-27 20:37:55,293 - INFO - No or invalid response from <class 'g4f.Provider.Liaobots.Liaobots'>: Liaobots is not working 2023-09-27 20:37:55,293 - INFO - No or invalid response from <class 'g4f.Provider.CodeLinkAva.CodeLinkAva'>: There is no current event loop in thread 'Thread-27 (process_request_thread)'. 2023-09-27 20:37:55,293 - INFO - No or invalid response from <class 'g4f.Provider.Raycast.Raycast'>: ValueError: Raycast requires authentication (use auth='cookie or token or jwt ...' param) 2023-09-27 20:37:55,293 - INFO - No or invalid response from <class 'g4f.Provider.ChatgptAi.ChatgptAi'>: There is no current event loop in thread 'Thread-27 (process_request_thread)'. 2023-09-27 20:37:55,293 - INFO - No or invalid response from <class 'g4f.Provider.DeepAi.DeepAi'>: There is no current event loop in thread 'Thread-27 (process_request_thread)'. 2023-09-27 20:37:55,293 - INFO - No or invalid response from <class 'g4f.Provider.Opchatgpts.Opchatgpts'>: There is no current event loop in thread 'Thread-27 (process_request_thread)'. 2023-09-27 20:37:55,293 - INFO - No or invalid response from <class 'g4f.Provider.Ails.Ails'>: There is no current event loop in thread 'Thread-27 (process_request_thread)'. 2023-09-27 20:37:55,293 - INFO - No or invalid response from <class 'g4f.Provider.AItianhu.AItianhu'>: There is no current event loop in thread 'Thread-27 (process_request_thread)'. 2023-09-27 20:37:55,293 - INFO - No or invalid response from <class 'g4f.Provider.GetGpt.GetGpt'>: GetGpt is not working 2023-09-27 20:37:55,293 - INFO - No or invalid response from <class 'g4f.Provider.Vitalentum.Vitalentum'>: There is no current event loop in thread 'Thread-27 (process_request_thread)'. 2023-09-27 20:37:55,293 - INFO - No or invalid response from <class 'g4f.Provider.Yqcloud.Yqcloud'>: There is no current event loop in thread 'Thread-27 (process_request_thread)'.
Same problem for me.
Get the error when using the streamlit app, not only local but also streamlit cloud.
Code
import g4f
import streamlit as st
response = g4f.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": prompt}],
provider=provider
)
st.write(response)
Error
Traceback (most recent call last):
File "c:\users\appdata\local\programs\python\python38\lib\site-packages\g4f\Provider\helper.py", line 21, in get_event_loop
asyncio.get_running_loop()
RuntimeError: no running event loop
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\users\appdata\local\programs\python\python38\lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 565, in _run_script
exec(code, module.__dict__)
File "D:\Junxiang\Python\docGPT-streamlit\test.py", line 4, in <module>
response = g4f.ChatCompletion.create(
File "c:\users\appdata\local\programs\python\python38\lib\site-packages\g4f\__init__.py", line 55, in create
return result if stream else ''.join(result)
File "c:\users\appdata\local\programs\python\python38\lib\site-packages\g4f\Provider\base_provider.py", line 99, in create_completion
loop = get_event_loop()
File "c:\users\appdata\local\programs\python\python38\lib\site-packages\g4f\Provider\helper.py", line 23, in get_event_loop
return _event_loop_policy.get_event_loop()
File "c:\users\appdata\local\programs\python\python38\lib\asyncio\events.py", line 639, in get_event_loop
raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'ScriptRunner.scriptThread'.
Note
If just use g4f
without streamlit, there will not error happen.
I have this problem too
How to overcome this issue.
Bumping this issue because it has been open for 7 days with no activity. Closing automatically in 7 days unless it becomes active again.