n3d1117 / chatgpt-telegram-bot

🤖 A Telegram bot that integrates with OpenAI's official ChatGPT APIs to provide answers, written in Python
GNU General Public License v2.0
2.87k stars 1.32k forks source link

Bugs in the operation of plugins: auto_tts, ddg_ddg_search, and ddg_images_earch (403, HttpError). #562

Open typoBro opened 2 months ago

typoBro commented 2 months ago

When using these plugins in certain ways, errors occur which I would like to share with you.

1.Firstly, let's discuss the auto_tts plugin.

This plugin mostly operates without errors, providing voice responses from the bot to the requests. However, difficulties occur when you ask the bot to act as a translator and respond only in voice. After the second such message, the bot either forgets what it was asked to do (see screenshot below) or the bot throws an error (mentioned below the screenshot).

Screenshot_20240418-195716

ИЛИ

[!CAUTION] Failed to decode the text: unsupported operand type(s) for +=: 'int' and 'str'

Unfortunately, I have no understanding of why this error is specifically revealed in this manner but if you could assist, I would be very grateful.

2. The second issue pertains to the ddg_ddg_search and ddg_image_search plugins.

Revisiting the issue, it is worth mentioning that when I try to search the internet, the bot throws errors into the chat (see the screenshot below) and also reports errors in the terminal (mentioned below the screenshot)

Screenshot_20240418-195648

Error from the terminal 1

``` 2024-04-18 19:49:33,752 - root - INFO - Calling function search_images with arguments { "query": "cat", "type": "photo", "region": "us-en" } 2024-04-18 19:49:35,035 - duckduckgo_search.duckduckgo_search - WARNING - _get_url() https://duckduckgo.com/i.js HTTPStatusError Client error '403 Forbidden' for url 'https://duckduckgo.com/i.js?l=us-en&o=json&s=0&q=cat&vqd=4-24148126955197676858535201361756838909&f=%2C%2C%2Ctype%3Aphoto%2C%2C&p=1' For more information check: https://httpstatuses.com/403 2024-04-18 19:49:38,208 - duckduckgo_search.duckduckgo_search - WARNING - _get_url() https://duckduckgo.com/i.js HTTPStatusError Client error '403 Forbidden' for url 'https://duckduckgo.com/i.js?l=us-en&o=json&s=0&q=cat&vqd=4-24148126955197676858535201361756838909&f=%2C%2C%2Ctype%3Aphoto%2C%2C&p=1' For more information check: https://httpstatuses.com/403 2024-04-18 19:49:41,421 - duckduckgo_search.duckduckgo_search - WARNING - _get_url() https://duckduckgo.com/i.js HTTPStatusError Client error '403 Forbidden' for url 'https://duckduckgo.com/i.js?l=us-en&o=json&s=0&q=cat&vqd=4-24148126955197676858535201361756838909&f=%2C%2C%2Ctype%3Aphoto%2C%2C&p=1' For more information check: https://httpstatuses.com/403 2024-04-18 19:49:41,422 - root - ERROR - Client error '403 Forbidden' for url 'https://duckduckgo.com/i.js?l=us-en&o=json&s=0&q=cat&vqd=4-24148126955197676858535201361756838909&f=%2C%2C%2Ctype%3Aphoto%2C%2C&p=1' For more information check: https://httpstatuses.com/403 Traceback (most recent call last): File "C:\Users\Сергей\Downloads\chatgpt-telegram-bot-0.4.0\bot\telegram_bot.py", line 697, in prompt async for content, tokens in stream_response: File "C:\Users\Сергей\Downloads\chatgpt-telegram-bot-0.4.0\bot\openai_helper.py", line 178, in get_chat_response_stream response, plugins_used = await self.__handle_function_call(chat_id, response, stream=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Сергей\Downloads\chatgpt-telegram-bot-0.4.0\bot\openai_helper.py", line 304, in __handle_function_call function_response = await self.plugin_manager.call_function(function_name, self, arguments) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Сергей\Downloads\chatgpt-telegram-bot-0.4.0\bot\plugin_manager.py", line 59, in call_function return json.dumps(await plugin.execute(function_name, helper, **json.loads(arguments)), default=str) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Сергей\Downloads\chatgpt-telegram-bot-0.4.0\bot\plugins\ddg_image_search.py", line 61, in execute results = list(islice(ddgs_images_gen, 10)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Сергей\Downloads\chatgpt-telegram-bot-0.4.0\venv\Lib\site-packages\duckduckgo_search\duckduckgo_search.py", line 427, in images resp = self._get_url("GET", "https://duckduckgo.com/i.js", params=payload) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Сергей\Downloads\chatgpt-telegram-bot-0.4.0\venv\Lib\site-packages\duckduckgo_search\duckduckgo_search.py", line 89, in _get_url raise ex File "C:\Users\Сергей\Downloads\chatgpt-telegram-bot-0.4.0\venv\Lib\site-packages\duckduckgo_search\duckduckgo_search.py", line 83, in _get_url resp.raise_for_status() File "C:\Users\Сергей\Downloads\chatgpt-telegram-bot-0.4.0\venv\Lib\site-packages\httpx\_models.py", line 749, in raise_for_status raise HTTPStatusError(message, request=request, response=self) httpx.HTTPStatusError: Client error '403 Forbidden' for url 'https://duckduckgo.com/i.js?l=us-en&o=json&s=0&q=cat&vqd=4-24148126955197676858535201361756838909&f=%2C%2C%2Ctype%3Aphoto%2C%2C&p=1' For more information check: https://httpstatuses.com/403 ```

Error from the terminal 2

``` 2024-04-18 19:50:32,590 - root - INFO - Calling function web_search with arguments { "query": "latest news about Pavel Durov", "region": "us-en" } 2024-04-18 19:50:34,395 - duckduckgo_search.duckduckgo_search - WARNING - _get_url() https://links.duckduckgo.com/d.js HTTPError 2024-04-18 19:50:37,594 - duckduckgo_search.duckduckgo_search - WARNING - _get_url() https://links.duckduckgo.com/d.js HTTPError 2024-04-18 19:50:41,037 - duckduckgo_search.duckduckgo_search - WARNING - _get_url() https://links.duckduckgo.com/d.js HTTPError 2024-04-18 19:50:41,038 - root - ERROR - Traceback (most recent call last): File "C:\Users\Сергей\Downloads\chatgpt-telegram-bot-0.4.0\bot\telegram_bot.py", line 697, in prompt async for content, tokens in stream_response: File "C:\Users\Сергей\Downloads\chatgpt-telegram-bot-0.4.0\bot\openai_helper.py", line 178, in get_chat_response_stream response, plugins_used = await self.__handle_function_call(chat_id, response, stream=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Сергей\Downloads\chatgpt-telegram-bot-0.4.0\bot\openai_helper.py", line 304, in __handle_function_call function_response = await self.plugin_manager.call_function(function_name, self, arguments) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Сергей\Downloads\chatgpt-telegram-bot-0.4.0\bot\plugin_manager.py", line 59, in call_function return json.dumps(await plugin.execute(function_name, helper, **json.loads(arguments)), default=str) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Сергей\Downloads\chatgpt-telegram-bot-0.4.0\bot\plugins\ddg_web_search.py", line 56, in execute results = list(islice(ddgs_gen, 3)) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Сергей\Downloads\chatgpt-telegram-bot-0.4.0\venv\Lib\site-packages\duckduckgo_search\duckduckgo_search.py", line 150, in text yield from self._text_api(keywords, region, safesearch, timelimit) File "C:\Users\Сергей\Downloads\chatgpt-telegram-bot-0.4.0\venv\Lib\site-packages\duckduckgo_search\duckduckgo_search.py", line 201, in _text_api resp = self._get_url( ^^^^^^^^^^^^^^ File "C:\Users\Сергей\Downloads\chatgpt-telegram-bot-0.4.0\venv\Lib\site-packages\duckduckgo_search\duckduckgo_search.py", line 89, in _get_url raise ex File "C:\Users\Сергей\Downloads\chatgpt-telegram-bot-0.4.0\venv\Lib\site-packages\duckduckgo_search\duckduckgo_search.py", line 82, in _get_url raise httpx._exceptions.HTTPError("") httpx.HTTPError 2024-04-18 19:51:03,441 - telegram.ext.Application - INFO - Application is stopping. This might take a moment. 2024-04-18 19:51:03,441 - telegram.ext.Application - INFO - Application.stop() complete ```

I have found previous discussions with similar issues, but couldn't figure out how to fix this problem for a regular user. I heard that DuckDuckGo needs to be updated, but I didn't understand how to do it without using Docker. In short, I would appreciate a layman's explanation of how to fix this issue. I would be very grateful for any help in resolving these issues.