codeinterpreter-api
codeinterpreter-api copied to clipboard
Error: This event loop is already running. RuntimeError: This event loop is already running ./codeinterpreterapi/session.py:448: RuntimeWarning: coroutine 'CodeBox.adownload' was never awaited return CodeInterpreterResponse( RuntimeWarning: Enable tracemalloc to get the object allocation traceback
'CodeBox.adownload' was never awaited return CodeInterpreterResponse(RuntimeWarning: Enable tracemalloc to get the object allocation traceback I have buy api codebox-api, have workable gpt-4 api openai account, installed all necessary packages and run streamlit frontend sucessfuly on http://localhost:8501/ but when I try to write even "Hi!" it's corrupted!
error
(py311) user@Georges-MacBook-Air codeinterpreter-api % PYTHONPATH=$PYTHONPATH:./frontend streamlit run frontend/app.py
You can now view your Streamlit app in your browser.
Local URL: http://localhost:8501
Network URL: http://192.168.1.162:8501
For better performance, install the Watchdog module:
$ xcode-select --install
$ pip install watchdog
<CodeBox id=98ebaa13-****-****-****-0453377bf9f0> started!
DEPRECATION WARNING: Use agenerate_response for async generation.
This function will be converted to sync in the future.
You can use generate_response_sync for now.
Traceback (most recent call last):
File "/Users/user/Programms/projects/openai/gpt/_use/codeinterpreter-api/codeinterpreterapi/session.py", line 442, in agenerate_response
response = await self.agent_executor.arun(input=user_request.content)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/user/miniconda3/envs/py311/lib/python3.11/site-packages/langchain/chains/base.py", line 556, in arun
await self.acall(
File "/Users/user/miniconda3/envs/py311/lib/python3.11/site-packages/langchain/chains/base.py", line 326, in acall
inputs = self.prep_inputs(inputs)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/user/miniconda3/envs/py311/lib/python3.11/site-packages/langchain/chains/base.py", line 411, in prep_inputs
external_context = self.memory.load_memory_variables(inputs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/user/miniconda3/envs/py311/lib/python3.11/site-packages/langchain/memory/buffer.py", line 45, in load_memory_variables
return {self.memory_key: self.buffer}
^^^^^^^^^^^
File "/Users/user/miniconda3/envs/py311/lib/python3.11/site-packages/langchain/memory/buffer.py", line 19, in buffer
return self.buffer_as_messages if self.return_messages else self.buffer_as_str
^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/user/miniconda3/envs/py311/lib/python3.11/site-packages/langchain/memory/buffer.py", line 33, in buffer_as_messages
return self.chat_memory.messages
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/user/Programms/projects/openai/gpt/_use/codeinterpreter-api/codeinterpreterapi/chat_history.py", line 33, in messages
loop.run_until_complete(self.codebox.adownload("history.json"))
File "/Users/user/miniconda3/envs/py311/lib/python3.11/asyncio/base_events.py", line 629, in run_until_complete
self._check_running()
File "/Users/user/miniconda3/envs/py311/lib/python3.11/asyncio/base_events.py", line 588, in _check_running
raise RuntimeError('This event loop is already running')
RuntimeError: This event loop is already running
/Users/user/Programms/projects/openai/gpt/_use/codeinterpreter-api/codeinterpreterapi/session.py:448: RuntimeWarning: coroutine 'CodeBox.adownload' was never awaited
return CodeInterpreterResponse(
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
I got the issue resolved by using the nest_async pip install nest-asyncio
and adding below lines in my file. import nest_asyncio nest_asyncio.apply()
The ipython kernel itself runs on an event loop. Asyncio does not allow its event loop to be nested. So if you are in an environment where the event loop is already running such as a WebServer, a GUI application or a Jupyter notebook in this case, it’s impossible to run tasks and wait for the result. The “nest-asyncio” patches “asyncio” and allows nested usage “loop.run_until_complete”.