Runtime issue: module 'openai' has no attribute 'aiosession'
Opened this issue · 3 comments
After starting main.py
I receive the following output. Every time I issue a command to the bot or it otherwise receives an input, I see the same Python error: AttributeError: module 'openai' has no attribute 'aiosession'
. Predictably, no output is returned by the bot.
Context:
[11-20 07:49:02] [client.py:42] WARNING - Discord.active_channels = "all", bot will interact with every channel!
[11-20 07:49:02] [client.py:603] INFO - logging in using static token
[11-20 07:49:03] [gateway.py:563] INFO - Shard ID None has connected to Gateway (Session ID: [REDACTED]).
[11-20 07:49:05] [client.py:497] INFO - Logged in as [REDACTED]
[11-20 07:49:05] [client.py:157] INFO - LLM: openai
[11-20 07:49:05] [oai.py:65] DEBUG - Updating tokenizer encoding for gpt-4
[11-20 07:49:06] [client.py:169] INFO - Current model: gpt-4
[11-20 07:49:06] [client.py:135] INFO - TTS: silero
[11-20 07:49:14] [client.py:515] ERROR - Ignoring exception in on_ready
Traceback (most recent call last):
File "/opt/conda/lib/python3.10/site-packages/discord/client.py", line 441, in _run_event
await coro(*args, **kwargs)
File "/home/ubuntu/LLMChat/llmchat/client.py", line 508, in on_ready
await self.setup_tts()
File "/home/ubuntu/LLMChat/llmchat/client.py", line 146, in setup_tts
self.tts = SileroTTS(*params)
File "/home/ubuntu/LLMChat/llmchat/tts_sources/silero.py", line 20, in __init__
os.mkdir("models/torch/")
FileNotFoundError: [Errno 2] No such file or directory: 'models/torch/'
[11-20 07:49:31] [client.py:515] ERROR - Ignoring exception in on_message
Traceback (most recent call last):
File "/opt/conda/lib/python3.10/site-packages/discord/client.py", line 441, in _run_event
await coro(*args, **kwargs)
File "/home/ubuntu/LLMChat/llmchat/client.py", line 629, in on_message
await self.store_embedding((message.author.id, message.content, message.id))
File "/home/ubuntu/LLMChat/llmchat/client.py", line 519, in store_embedding
openai.aiosession.set(s)
AttributeError: module 'openai' has no attribute 'aiosession'
Anyone else running into this?
EDIT: It appears that the openai
module is no longer using aiosession
in favor of httpx. Possibly a module version issue? Ref: openai/openai-python#742
Figured out that the error I was getting for silero.py was legit because the Python script couldn't do an os.mkdir("models/torch/")
on line 20 of the file. Manually created the directory and now the script initializes properly, but I'm still getting the `module 'openai' has no attribute 'aiosession' error.
Creating another issue for the os.mkdir
weirdness with the silero.py
dependency.
Created #24. Resolution of this issue on my end yields the following output now when running main.py
and issuing any input or query (e.g. /configure
) via Discord:
[11-20 13:28:33] [client.py:42] WARNING - Discord.active_channels = "all", bot will interact with every channel!
[11-20 13:28:33] [client.py:603] INFO - logging in using static token
[11-20 13:28:34] [gateway.py:563] INFO - Shard ID None has connected to Gateway (Session ID: 53d4428565ad06e0b80f103ea3cc9f61).
[11-20 13:28:36] [client.py:497] INFO - Logged in as Hekapoo#7300
[11-20 13:28:36] [client.py:157] INFO - LLM: openai
[11-20 13:28:36] [oai.py:65] DEBUG - Updating tokenizer encoding for gpt-4
[11-20 13:28:37] [client.py:169] INFO - Current model: gpt-4
[11-20 13:28:37] [client.py:135] INFO - TTS: silero
Using cache found in models/torch/snakers4_silero-models_master
[11-20 13:28:40] [silero.py:23] INFO - Silero loaded.
[11-20 13:28:40] [client.py:172] INFO - Speech recognition service: whisper
/opt/conda/lib/python3.10/site-packages/torch/cuda/__init__.py:611: UserWarning: Can't initialize NVML
warnings.warn("Can't initialize NVML")
[11-20 13:28:41] [whisper.py:15] INFO - Loading whisper model on cpu
Special tokens have been added in the vocabulary, make sure the associated word embeddings are fine-tuned or trained.
[11-20 13:28:45] [client.py:513] INFO - Initialization complete.
[11-20 13:29:12] [client.py:515] ERROR - Ignoring exception in on_message
Traceback (most recent call last):
File "/opt/conda/lib/python3.10/site-packages/discord/client.py", line 441, in _run_event
await coro(*args, **kwargs)
File "/home/ubuntu/LLMChat/llmchat/client.py", line 629, in on_message
await self.store_embedding((message.author.id, message.content, message.id))
File "/home/ubuntu/LLMChat/llmchat/client.py", line 519, in store_embedding
openai.aiosession.set(s)
AttributeError: module 'openai' has no attribute 'aiosession'
Pip appears to be installing the incorrect version of the openai
module during setup:
ubuntu@[REDACTED]:~/LLMChat$ pip3 install openai
Requirement already satisfied: openai in /opt/conda/lib/python3.10/site-packages (1.3.3)
[snip]
ubuntu@[REDACTED]:~/LLMChat$ cat requirements.txt
openai~=0.27.2
[snip]
Resolved the issue by uninstalling openai
(had to also uninstall an incompatible urllib3 dependency version installed in turn by botocore, which I also uninstalled). Then did pip3 install --force-reinstall -v "openai==0.27.2"
followed by pip3 install --force-reinstall -v botocore
to achieve resolution.
Verbose commands/output as follows:
ubuntu@[REDACTED]:~/LLMChat$ pip3 uninstall openai
Found existing installation: openai 1.3.3
Uninstalling openai-1.3.3:
Would remove:
/opt/conda/bin/openai
/opt/conda/lib/python3.10/site-packages/openai-1.3.3.dist-info/*
/opt/conda/lib/python3.10/site-packages/openai/*
Proceed (Y/n)? y
Successfully uninstalled openai-1.3.3
ubuntu@[REDACTED]:~/LLMChat$ pip3 install --force-reinstall -v "openai==0.27.2"
Using pip 23.0 from /opt/conda/lib/python3.10/site-packages/pip (python 3.10)
Collecting openai==0.27.2
Downloading openai-0.27.2-py3-none-any.whl (70 kB)
[snip]
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
botocore 1.32.3 requires urllib3<2.1,>=1.25.4; python_version >= "3.10", but you have urllib3 2.1.0 which is incompatible.
Successfully installed aiohttp-3.9.0 aiosignal-1.3.1 async-timeout-4.0.3 attrs-23.1.0 certifi-2023.11.17 charset-normalizer-3.3.2 frozenlist-1.4.0 idna-3.4 multidict-6.0.4 openai-0.27.2 requests-2.31.0 tqdm-4.66.1 urllib3-2.1.0 yarl-1.9.2
ubuntu@[REDACTED]:~/LLMChat$ pip3 install openai
Requirement already satisfied: openai in /opt/conda/lib/python3.10/site-packages (0.27.2)
Requirement already satisfied: aiohttp in /opt/conda/lib/python3.10/site-packages (from openai) (3.9.0)
Requirement already satisfied: requests>=2.20 in /opt/conda/lib/python3.10/site-packages (from openai) (2.31.0)
Requirement already satisfied: tqdm in /opt/conda/lib/python3.10/site-packages (from openai) (4.66.1)
Requirement already satisfied: idna<4,>=2.5 in /opt/conda/lib/python3.10/site-packages (from requests>=2.20->openai) (3.4)
Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/lib/python3.10/site-packages (from requests>=2.20->openai) (2023.11.17)
Requirement already satisfied: urllib3<3,>=1.21.1 in /opt/conda/lib/python3.10/site-packages (from requests>=2.20->openai) (2.1.0)
Requirement already satisfied: charset-normalizer<4,>=2 in /opt/conda/lib/python3.10/site-packages (from requests>=2.20->openai) (3.3.2)
Requirement already satisfied: async-timeout<5.0,>=4.0 in /opt/conda/lib/python3.10/site-packages (from aiohttp->openai) (4.0.3)
Requirement already satisfied: frozenlist>=1.1.1 in /opt/conda/lib/python3.10/site-packages (from aiohttp->openai) (1.4.0)
Requirement already satisfied: multidict<7.0,>=4.5 in /opt/conda/lib/python3.10/site-packages (from aiohttp->openai) (6.0.4)
Requirement already satisfied: yarl<2.0,>=1.0 in /opt/conda/lib/python3.10/site-packages (from aiohttp->openai) (1.9.2)
Requirement already satisfied: aiosignal>=1.1.2 in /opt/conda/lib/python3.10/site-packages (from aiohttp->openai) (1.3.1)
Requirement already satisfied: attrs>=17.3.0 in /opt/conda/lib/python3.10/site-packages (from aiohttp->openai) (23.1.0)
ubuntu@[REDACTED]:~/LLMChat$ pip3 uninstall urllib3
Found existing installation: urllib3 2.1.0
Uninstalling urllib3-2.1.0:
Would remove:
/opt/conda/lib/python3.10/site-packages/urllib3-2.1.0.dist-info/*
/opt/conda/lib/python3.10/site-packages/urllib3/*
Proceed (Y/n)? y
Successfully uninstalled urllib3-2.1.0
ubuntu@[REDACTED]:~/LLMChat$ pip3 uninstall botocore
Found existing installation: botocore 1.32.3
Uninstalling botocore-1.32.3:
Would remove:
/opt/conda/lib/python3.10/site-packages/botocore-1.32.3.dist-info/*
/opt/conda/lib/python3.10/site-packages/botocore/*
Proceed (Y/n)? y
Successfully uninstalled botocore-1.32.3
ubuntu@[REDACTED]:~/LLMChat$ pip3 install --force-reinstall -v botocore
Using pip 23.0 from /opt/conda/lib/python3.10/site-packages/pip (python 3.10)
Collecting botocore
[snip]
Successfully installed botocore-1.32.3 jmespath-1.0.1 python-dateutil-2.8.2 six-1.16.0 urllib3-2.0.7