knrd1 / chatgpt

ChatGPT IRC bot
https://github.com/knrd1/chatgpt
MIT License
33 stars 7 forks source link

configparser.NoSectionError: No section: 'openai' #31

Closed ph818 closed 8 months ago

ph818 commented 8 months ago

Hi, first of all thank you for providing this code; very interesting to get chatGPT as an IRC bot.

I ran into some trouble with the prerequisites as "pip3 install openai==0.28 pyshorteners" failed with error: externally-managed-environment on Debian 12.

After some research I created a venv with python3 -m venv venv1 and then I was able to run the pip3 command.

However when I did python3 chatgpt/chatgpt.py I got the following traceback

(venv1) root@bot-base:~/threepio# python3 chatgpt/chatgpt.py
Traceback (most recent call last):
  File "/root/threepio/chatgpt/chatgpt.py", line 14, in <module>
    openai.api_key = config.get('openai', 'api_key')
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/configparser.py", line 797, in get
    d = self._unify_values(section, vars)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/configparser.py", line 1168, in _unify_values
    raise NoSectionError(section) from None
configparser.NoSectionError: No section: 'openai'

I am not sure what to do with this but posting here in case anyone knows or it can help someone else.

knrd1 commented 8 months ago

Hey, it seems that application cannot read the configuration file chat.conf. Do you have file chat.conf in place in WORKING directory? Looks like you are not executing the bot from "chatgpt" directory but you are one level above:

(venv1) root@bot-base:~/threepio# python3 chatgpt/chatgpt.py

Either, copy chat.conf to your working (current) directory or enter folder "chatgpt" and execute the bot inside it.


I'm more interested why you have the initial error on Debian 12, I will be installing Debian 12 and test it, thanks for reporting.

knrd1 commented 8 months ago

Ok, I see that Debian 12 introduced new logic and it doesn't recommend to install pip3 packages system-wide. You can override this behaviour using command:

pip3 install openai==0.28 pyshorteners --break-system-packages

Alternatively, use Docker or virtual environments. I will update README.md with these details, thanks for reporting.

ph818 commented 8 months ago

Thanks for the hint -- when I cd'd into the correct working directory, I got a bit further. I was able to install openai==0.28 and pyshorteners in a venv, so they both get found correctly. However I still do run into an ssl error, which I'll post as its own issue #32 .