Integration-Automation/ReEdgeGPT

Some prompts fails in 0.0.30

theurs opened this issue · 28 comments

if prompt = 'hello' or 'hello + hello' its ok
if prompt = '1+1' or '2+2' it fails with error
all is ok with 0.0.28

TypeError
can only concatenate str (not "NoneType") to str
  File "C:\Users\user\V\4 python\2 telegram bot tesseract\tb1\test.py", line 19, in test_ask
    response = await bot.ask(
               ^^^^^^^^^^^^^^
  File "C:\Users\user\V\4 python\2 telegram bot tesseract\tb1\test.py", line 42, in <module>
    loop.run_until_complete(test_ask())
TypeError: can only concatenate str (not "NoneType") to str


import asyncio
import json
from pathlib import Path

from re_edge_gpt import Chatbot
from re_edge_gpt import ConversationStyle


# If you are using jupyter pls install this package
# from nest_asyncio import apply


async def test_ask() -> None:
    bot = None
    try:
        cookies: list[dict] = json.loads(open(
            str(Path(str(Path.cwd()) + "/bing_cookies.json")), encoding="utf-8").read())
        bot = await Chatbot.create(cookies=cookies)
        response = await bot.ask(
            prompt="1+1",
            conversation_style=ConversationStyle.balanced,
            simplify_response=True
        )
        # If you are using non ascii char you need set ensure_ascii=False
        print(json.dumps(response, indent=2, ensure_ascii=False))
        # Raw response
        # print(response)
        assert response

    finally:
        if bot is not None:
            await bot.close()


if __name__ == "__main__":
    # If you are using jupyter pls use nest_asyncio apply()
    # apply()
    try:
        loop = asyncio.get_running_loop()
    except RuntimeError:
        loop = asyncio.get_event_loop()
    loop.run_until_complete(test_ask())

I can get the result of prompt 1+1 or 2+2 etc.
image
image

For reasons unknown to me, I am unable to set a breakpoint at line 109 in the file c:\Users\user\V\4 python\2 telegram bot tesseract\tb1\.venv\Lib\site-packages\re_edge_gpt\chat\re_edge_gpt.py and observe what's happening at that point.

Traceback (most recent call last):
  File "C:\Program Files\Python311\Lib\runpy.py", line 198, in _run_module_as_main
    return _run_code(code, main_globals, None,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\runpy.py", line 88, in _run_code
    exec(code, run_globals)
  File "c:\Users\user\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy\__main__.py", line 39, in <module>
    cli.main()
  File "c:\Users\user\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 430, in main
    run()
  File "c:\Users\user\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 284, in run_file
    runpy.run_path(target, run_name="__main__")
  File "c:\Users\user\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 321, in run_path
    return _run_module_code(code, init_globals, run_name,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\user\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 135, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "c:\Users\user\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 124, in _run_code
    exec(code, run_globals)
  File "C:\Users\user\V\4 python\2 telegram bot tesseract\tb1\test.py", line 42, in <module>
    loop.run_until_complete(test_ask())
  File "C:\Program Files\Python311\Lib\asyncio\base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "C:\Users\user\V\4 python\2 telegram bot tesseract\tb1\test.py", line 19, in test_ask
    response = await bot.ask(
               ^^^^^^^^^^^^^^
  File "c:\Users\user\V\4 python\2 telegram bot tesseract\tb1\.venv\Lib\site-packages\re_edge_gpt\chat\re_edge_gpt.py", line 109, in ask
    "text": old_message + msg.get("text")
            ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
TypeError: can only concatenate str (not "NoneType") to str

fixed re_edge_gpt\chat\re_edge_gpt.py" near line 109 and now its working ok

                        _old_mess = old_message or ''
                        _new_mess = msg.get("text") or ''
                        message.update({
                            "author": "bot",
                            # "text": old_message + msg.get("text")
                            "text": _old_mess + _new_mess
                        })

upload image also throw error

Traceback (most recent call last):
  File "C:\Program Files\Python311\Lib\runpy.py", line 198, in _run_module_as_main
    return _run_code(code, main_globals, None,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\runpy.py", line 88, in _run_code
    exec(code, run_globals)
  File "c:\Users\user\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy\__main__.py", line 39, in <module>
    cli.main()
  File "c:\Users\user\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 430, in main
    run()
  File "c:\Users\user\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 284, in run_file
    runpy.run_path(target, run_name="__main__")
  File "c:\Users\user\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 321, in run_path
    return _run_module_code(code, init_globals, run_name,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\user\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 135, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "c:\Users\user\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 124, in _run_code
    exec(code, run_globals)
  File "C:\Users\user\V\4 python\2 telegram bot tesseract\tb1\test.py", line 66, in <module>
    loop.run_until_complete(test_ask2())
  File "C:\Program Files\Python311\Lib\asyncio\base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "C:\Users\user\V\4 python\2 telegram bot tesseract\tb1\test.py", line 42, in test_ask2
    response = await bot.ask(
               ^^^^^^^^^^^^^^
  File "c:\Users\user\V\4 python\2 telegram bot tesseract\tb1\.venv\Lib\site-packages\re_edge_gpt\chat\re_edge_gpt.py", line 128, in ask
    source_texts.append(source.get("providerDisplayName"))
                        ^^^^^^^^^^
AttributeError: 'str' object has no attribute 'get'
import asyncio
import base64
import json
from pathlib import Path

from re_edge_gpt import Chatbot
from re_edge_gpt import ConversationStyle


# If you are using jupyter pls install this package
# from nest_asyncio import apply


async def test_ask2() -> None:
    bot = None
    try:
        cookies: list[dict] = json.loads(open(
            str(Path(str(Path.cwd()) + "/bing_cookies.json")), encoding="utf-8").read())
        bot = await Chatbot.create(cookies=cookies)
        response = await bot.ask(
            prompt="What does this image show?",
            conversation_style=ConversationStyle.balanced,
            simplify_response=True,
            #attachment={"image_url": r"https://images.yourstory.com/cs/2/96eabe90392211eb93f18319e8c07a74/Image54nh-1683225460858.jpg"})
            attachment={"base64_image": base64.b64encode(open('1.jpg', 'rb').read()).decode('utf-8')})
        # If you are using non ascii char you need set ensure_ascii=False
        print(json.dumps(response, indent=2, ensure_ascii=False))
        # Raw response
        # print(response)
        assert response

    finally:
        if bot is not None:
            await bot.close()


if __name__ == "__main__":
    # If you are using jupyter pls use nest_asyncio apply()
    # apply()
    try:
        loop = asyncio.get_running_loop()
    except RuntimeError:
        loop = asyncio.get_event_loop()
    loop.run_until_complete(test_ask2())

Can version 0.0.31 fix this issue ?

0.0.31 - ok on my windows developer pc. and error on linux server

Traceback (most recent call last):
  File "/home/ubuntu/tb/./bingai.py", line 116, in chat_async
    r = await DIALOGS[dialog].ask(prompt=query, conversation_style=st, simplify_response=True, search_result=False)
  File "/home/ubuntu/.tb1/lib/python3.10/site-packages/re_edge_gpt/chat/re_edge_gpt.py", line 79, in ask
    async for final, response in self.chat_hub.ask_stream(
  File "/home/ubuntu/.tb1/lib/python3.10/site-packages/re_edge_gpt/chat/chathub.py", line 191, in ask_stream
    raise ResponseError(
re_edge_gpt.utils.exception.exceptions.ResponseError: Throttled: Request is throttled.

re_edge_gpt.utils.exception.exceptions.ResponseError: Throttled: Request is throttled.
Maybe this exception is reach chat limit per day. try use new cookie and run on next day.

I use the same address (proxy) and cookie file. the package versions are also the same pip freeze >123; pip install -r 123

Still have same exception?

Yes. Tried one more server, same result.

Run normal on my ubuntu, can u try use another bing account that have acces of Bing chat, use it's cookie file.
image

new VPS server ubuntu 22, new account and cookie, new venv. it works ok in my windows pc with vpn connected to this VPS

pip freeze
aiohttp==3.9.3
aiosignal==1.3.1
anyio==4.2.0
async-timeout==4.0.3
attrs==23.2.0
Brotli==1.1.0
certifi==2024.2.2
charset-normalizer==3.3.2
exceptiongroup==1.2.0
frozenlist==1.4.1
h11==0.14.0
httpcore==1.0.2
httpx==0.26.0
idna==3.6
markdown-it-py==3.0.0
mdurl==0.1.2
multidict==6.0.5
prompt-toolkit==3.0.43
Pygments==2.17.2
re_edge_gpt==0.0.31
regex==2023.12.25
requests==2.31.0
rich==13.7.0
sniffio==1.3.0
typing_extensions==4.9.0
urllib3==2.2.0
wcwidth==0.2.13
yarl==1.9.4
#!/usr/bin/env python3

import asyncio
import base64
import json
from pathlib import Path

from re_edge_gpt import Chatbot
from re_edge_gpt import ConversationStyle


# If you are using jupyter pls install this package
# from nest_asyncio import apply


async def test_ask() -> None:
    bot = None
    try:
        cookies: list[dict] = json.loads(open(
            str(Path(str(Path.cwd()) + "/bing_cookies.json")), encoding="utf-8").read())
        bot = await Chatbot.create(cookies=cookies)
        response = await bot.ask(
            prompt="1+1",
            conversation_style=ConversationStyle.balanced,
            simplify_response=True
        )
        # If you are using non ascii char you need set ensure_ascii=False
        print(json.dumps(response, indent=2, ensure_ascii=False))
        # Raw response
        # print(response)
        assert response

    finally:
        if bot is not None:
            await bot.close()


if __name__ == "__main__":
    # If you are using jupyter pls use nest_asyncio apply()
    # apply()
    try:
        loop = asyncio.get_running_loop()
    except RuntimeError:
        loop = asyncio.get_event_loop()
    loop.run_until_complete(test_ask())

(.test) ubuntu@kunsun:~/test$ ./1.py
Traceback (most recent call last):
  File "/home/ubuntu/test/./1.py", line 68, in <module>
    loop.run_until_complete(test_ask())
  File "/usr/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/home/ubuntu/test/./1.py", line 22, in test_ask
    response = await bot.ask(
  File "/home/ubuntu/.test/lib/python3.10/site-packages/re_edge_gpt/chat/re_edge_gpt.py", line 79, in ask
    async for final, response in self.chat_hub.ask_stream(
  File "/home/ubuntu/.test/lib/python3.10/site-packages/re_edge_gpt/chat/chathub.py", line 191, in ask_stream
    raise ResponseError(
re_edge_gpt.utils.exception.exceptions.ResponseError: Throttled: Request is throttled.
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7fc4e91787f0>

I will change forwardIP on next version.

Can version 0.0.32 run success ?

Successfully installed re_edge_gpt-0.0.32
(.test) ubuntu@kunsun:~/test$ ./1.py
Traceback (most recent call last):
  File "/home/ubuntu/test/./1.py", line 68, in <module>
    loop.run_until_complete(test_ask())
  File "/usr/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/home/ubuntu/test/./1.py", line 22, in test_ask
    response = await bot.ask(
  File "/home/ubuntu/.test/lib/python3.10/site-packages/re_edge_gpt/chat/re_edge_gpt.py", line 79, in ask
    async for final, response in self.chat_hub.ask_stream(
  File "/home/ubuntu/.test/lib/python3.10/site-packages/re_edge_gpt/chat/chathub.py", line 191, in ask_stream
    raise ResponseError(
re_edge_gpt.utils.exception.exceptions.ResponseError: Throttled: Request is throttled.
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7f1cd5d251b0>

I am still unable to determine what happened. However, both my Ubuntu Desktop 22.04 and Ubuntu Server 22.04 have successfully executed the code you provided.

So, I believe it’s a connection issue with Bing. (Bing block your server connect)

image

image

I have same problem. Some requests failed with this error. I can`t determine what cause this problem.

   response = await bot.ask(
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\re_edge_gpt\re_edge_gpt.py", line 70, in ask
    async for final, response in self.chat_hub.ask_stream(
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\re_edge_gpt\chathub.py", line 179, in ask_stream
    raise Exception(
Exception: Throttled: Request is throttled.
Fatal error on SSL transport
protocol: <asyncio.sslproto.SSLProtocol object at 0x0000023645DB0100>
transport: <_ProactorSocketTransport fd=724 read=<_OverlappedFuture cancelled>>
Traceback (most recent call last):
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\asyncio\sslproto.py", line 690, in _process_write_backlog
    self._transport.write(chunk)
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 361, in write
    self._loop_writing(data=bytes(data))
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 397, in _loop_writing
    self._write_fut = self._loop._proactor.send(self._sock, data)
AttributeError: 'NoneType' object has no attribute 'send'
Exception ignored in: <function ClientResponse.__del__ at 0x0000023645BDF1C0>

Exception: Throttled: Request is throttled.
Fatal error on SSL transport

I have same problem. Some requests failed with this error. I can`t determine what cause this problem.

   response = await bot.ask(
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\re_edge_gpt\re_edge_gpt.py", line 70, in ask
    async for final, response in self.chat_hub.ask_stream(
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\re_edge_gpt\chathub.py", line 179, in ask_stream
    raise Exception(
Exception: Throttled: Request is throttled.
Fatal error on SSL transport
protocol: <asyncio.sslproto.SSLProtocol object at 0x0000023645DB0100>
transport: <_ProactorSocketTransport fd=724 read=<_OverlappedFuture cancelled>>
Traceback (most recent call last):
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\asyncio\sslproto.py", line 690, in _process_write_backlog
    self._transport.write(chunk)
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 361, in write
    self._loop_writing(data=bytes(data))
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 397, in _loop_writing
    self._write_fut = self._loop._proactor.send(self._sock, data)
AttributeError: 'NoneType' object has no attribute 'send'
Exception ignored in: <function ClientResponse.__del__ at 0x0000023645BDF1C0>

Exception: Throttled: Request is throttled. Fatal error on SSL transport

Not this package exception. You can see who threw this exception—it’s the Python 3.10 asyncio sslproto module.

C:\Users\User\AppData\Local\Programs\Python\Python310\lib\asyncio\sslproto.py

I have same problem. Some requests failed with this error. I can`t determine what cause this problem.

   response = await bot.ask(
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\re_edge_gpt\re_edge_gpt.py", line 70, in ask
    async for final, response in self.chat_hub.ask_stream(
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\re_edge_gpt\chathub.py", line 179, in ask_stream
    raise Exception(
Exception: Throttled: Request is throttled.
Fatal error on SSL transport
protocol: <asyncio.sslproto.SSLProtocol object at 0x0000023645DB0100>
transport: <_ProactorSocketTransport fd=724 read=<_OverlappedFuture cancelled>>
Traceback (most recent call last):
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\asyncio\sslproto.py", line 690, in _process_write_backlog
    self._transport.write(chunk)
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 361, in write
    self._loop_writing(data=bytes(data))
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 397, in _loop_writing
    self._write_fut = self._loop._proactor.send(self._sock, data)
AttributeError: 'NoneType' object has no attribute 'send'
Exception ignored in: <function ClientResponse.__del__ at 0x0000023645BDF1C0>

Exception: Throttled: Request is throttled. Fatal error on SSL transport

Not this package exception. You can see who threw this exception—it’s the Python 3.10 asyncio sslproto module.

C:\Users\User\AppData\Local\Programs\Python\Python310\lib\asyncio\sslproto.py

So the error is thrown by “self.chathub.ask_stream”, which incorrectly gives something to the library “asyncio”.

I don’t know why, but even in our daily CI/CD processes, this exception has never been thrown before.

IKDH commented

Exception: Throttled: Request is throttled. --> You have reached the limitation of 300 messages per day I think.

Exception: Throttled: Request is throttled. --> You have reached the limitation of 300 messages per day I think.

I would be glad if that was the case. But I don’t even get 100 messages a day 🌚.I can also assume that the problem occurs if the prompt uses unicode characters. For example, quotes (not those that are ", but left and right quotes).

If your cookie too old, you can only 100 msg per day.
And what version of re-edge-gpt you are using?

I can also assume that the problem occurs if the prompt uses unicode characters. For example, quotes (not those that are ", but left and right quotes).
That is a Python json.dumps problem.
You need to add the parameter ensure_ascii=False.

json.dumps(response, indent=2, ensure_ascii=False)

See Q&A

Finally, I encountered an exception: “Throttled: Request is throttled.
image
When I use a cookie that hasn’t been refreshed for over a week.
Bing sets a cookie with a chat limit of only 10 messages per day if it has been active for over a week.

The only thing you need to do is refresh the cookie.

The only thing you need to do is refresh the cookie.

Are there plans to add functionality to automatically update cookies?

The only thing you need to do is refresh the cookie.

Are there plans to add functionality to automatically update cookies?

Open a new issue to request an enhancement.