vsakkas / sydney.py

Python Client for Copilot (formerly named Bing Chat), also known as Sydney.
MIT License
257 stars 36 forks source link

not able to upload image using attachment #86

Closed Parampatel07 closed 10 months ago

Parampatel07 commented 10 months ago

I am facing problem while trying to prompt image to the bing thorught attachment but facing the following error

`import asyncio
import os
from sydney import SydneyClient

os.environ["BING_U_COOKIE"] = '''1EGoJt1yjZ4phWsfhRb-jOz_kn02a2aNSJ-ZTepKf9RD5FiP0NBvSRPkrUqOF8qxyG9qs2Zq6U6THoi74O3LzaxWYlXC6o3x3LlygK0JBTwAoLZQ9OFMFa_zCh1E8WAs9XybXsJtmNqjGlnr7qu7DVOsdXfJQv6sH_stxoT44n1pe_XM2hD2nvi2mTHIh4T009XUusjzCk3ESouAZ9lpErBT0mSeB_WwjnS_yMCxJhuo'''

async def main() -> None:
    async with SydneyClient() as sydney:
        while True:
            prompt = input("You: ")

            if prompt == "!reset":
                await sydney.reset_conversation()
                continue
            elif prompt == "!exit":
                break

            # Provide the URL to your image here
            image_url = "https://th.bing.com/th/id/OIP.TILseDM6LQr7VTeARsInPQHaFj?pid=ImgDet&rs=1"

            print("Bing ai: ", end="", flush=True)
            response = await sydney.ask(prompt, attachment=image_url)
            print(response, end="", flush=True)
            print("\n")

if __name__ == "__main__":
    asyncio.run(main())
`

For which i am getting the following error

Traceback (most recent call last):
  File "C:\wamp64\www\project_1\api_demo6.py", line 27, in <module>
    asyncio.run(main())
  File "C:\Users\Dell\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "C:\Users\Dell\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Dell\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "C:\wamp64\www\project_1\api_demo6.py", line 22, in main
    response = await sydney.ask(prompt, attachment=image_url)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Dell\AppData\Local\Programs\Python\Python311\Lib\site-packages\sydney\sydney.py", line 459, in ask
    async for response, suggested_responses in self._ask(
  File "C:\Users\Dell\AppData\Local\Programs\Python\Python311\Lib\site-packages\sydney\sydney.py", line 316, in _ask
    attachment_info = await self._upload_attachment(attachment)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Dell\AppData\Local\Programs\Python\Python311\Lib\site-packages\sydney\sydney.py", line 275, in _upload_attachment  
    raise ImageUploadException(
sydney.exceptions.ImageUploadException: Failed to upload image, received empty image info from Bing Chat
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x0000017F24685D90>
Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x0000017F245E2A50>, 10168.265)]']
connector: <aiohttp.connector.TCPConnector object at 0x0000017F24685E90>
vsakkas commented 10 months ago

Hi @Parampatel07 Which version of the library are you using? There was a small change in the API, so 0.17.0 contains a fix for that

vsakkas commented 10 months ago

Hi @Parampatel07 Using the latest version (0.17.1), I cannot reproduce this error. This is my output:

You: What does this show?
Bing ai: The image you sent shows a pile of okra, both whole and sliced. Okra is a herbaceous hairy annual plant of the mallow family and its edible podlike fruits. Okra is native to the tropics of the Eastern Hemisphere and is widely cultivated in the tropics and subtropics of the Western Hemisphere [^1^]. The tender unripe fruits are commonly cooked as a vegetable [^1^]. The okra in the image is bright green in color, both whole and sliced. The sliced okra is cut into small pieces and is arranged in a pile. The whole okra is arranged in a pile and is pointing in different directions. The background is white [^2^].

I hope this helps!

Please, reopen this issue if the problem persists on you on the latest version, thanks!

Parampatel07 commented 10 months ago

Works well form me too after using latest version , Thanks for the help