hibobmaster / matrix_chatgpt_bot

A simple matrix bot that supports image generation and chatting using ChatGPT, Langchain
https://matrix.to/#/#public:matrix.qqs.tw
MIT License
75 stars 13 forks source link

What might be the problem? #13

Closed kroschu closed 1 year ago

kroschu commented 1 year ago

After entering the query !gpt Чому земля кругла?

File "/app/bot.py", line 551, in gpt text = text.strip() ^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'strip' 2023-05-20 08:01:07,371 - ERROR - Error: 'NoneType' object has no attribute 'strip' Traceback (most recent call last): File "/app/bot.py", line 551, in gpt text = text.strip() ^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'strip'

hibobmaster commented 1 year ago

How about !chat command?

kroschu commented 1 year ago

2023-05-20 09:38:15,079 - INFO - Login via password 2023-05-20 09:39:16,475 - INFO - Message received in room treba.m-e.pp.ua comment section () root | !chat Чому земля кругла? Task exception was never retrieved future: <Task finished name='Task-25' coro=<Bot.chat() done, defined at /app/bot.py:516> exception=Exception(JSONDecodeError('Expecting value: line 1 column 1 (char 0)'))> Traceback (most recent call last): File "/app/bot.py", line 520, in chat text = await self.chatbot.ask_async(prompt) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/v3.py", line 303, in ask_async full_response: str = "".join([r async for r in response]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/v3.py", line 303, in full_response: str = "".join([r async for r in response]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/v3.py", line 271, in ask_stream_async resp: dict = json.loads(line) ^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/json/init.py", line 346, in loads return _default_decoder.decode(s) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/json/decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/app/bot.py", line 522, in chat raise Exception(e) Exception: Expecting value: line 1 column 1 (char 0)

hibobmaster commented 1 year ago

Can you verify your openai api token is valid? How do you deploy the project? Can you paste your config file here without sensitive info?

kroschu commented 1 year ago

Code in docker-compose.yml:

matrix_chatgpt_bots: image: hibobmaster/matrixchatgptbot:latest container_name: matrix_chatgpt_bot restart: always env_file: "./dev-environment/gpt.env"

config file:

Please remove the option that is blank

HOMESERVER="https://xxxxx" USER_ID="@chatgpt:xxxxx" PASSWORD="xxxxxxxxxx" DEVICE_ID="NREENHDAAA" OPENAI_API_KEY="sk-lbh3mrxxxxxxxxxxxxxxxx" MARKDOWN_FORMATTED="true"

hibobmaster commented 1 year ago

Can you verify your openai api token is valid? sk-lbh3mrx2zeMHAJwqtR3NT3xxxxxxxxxxxxxxxxxxxxxx

Besides, do not use env file and config.json at the same time.

kroschu commented 1 year ago

I just generated a new token and checked its validity. I made the changes in gpt.env :

HOMESERVER="https://xxxxxxxxxx" USER_ID="@cxxxxxxx" PASSWORD="xxxxxxxxxxxo" DEVICE_ID="NREENHDAAA" OPENAI_API_KEY="skxxxxxxxxxxxxxxxxxxxxxxx" MARKDOWN_FORMATTED="true"

Restart container in portainer web interface:

2023-05-20 10:00:14,321 - INFO - matrix chatgpt bot start..... 2023-05-20 10:00:14,489 - INFO - Login via password 2023-05-20 10:00:25,969 - INFO - Message received in room treba.m-e.pp.ua comment section () root | !gpt Чому земля кругла? 2023-05-20 10:00:26,506 - oneTimeAsk - WARNING - Too Many Requests 2023-05-20 10:00:26,506 - WARNING - Too Many Requests 2023-05-20 10:00:29,100 - oneTimeAsk - WARNING - Too Many Requests 2023-05-20 10:00:29,100 - WARNING - Too Many Requests 2023-05-20 10:00:31,102 - gpt - ERROR - Error: 'NoneType' object has no attribute 'strip' Traceback (most recent call last): File "/app/bot.py", line 551, in gpt text = text.strip() ^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'strip' 2023-05-20 10:00:31,102 - ERROR - Error: 'NoneType' object has no attribute 'strip' Traceback (most recent call last): File "/app/bot.py", line 551, in gpt text = text.strip() ^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'strip'

In result

hibobmaster commented 1 year ago

Too Many Requests means you exceed openai rete limit. Free account: 3r/min

AttributeError: 'NoneType' object has no attribute 'strip' means you did not get the response from chatgpt.

kroschu commented 1 year ago

Understood, thank you very much for your attention and time