Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't upload an image. UnboundLocalError: local variable 'response' referenced before assignment #1932

Closed
SCVRLET opened this issue May 9, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@SCVRLET
Copy link

SCVRLET commented May 9, 2024

Bug description
Can't upload an image.

Code
from g4f.client import Client
from g4f.cookies import set_cookies

set_cookies(
".google.com",
{
"__Secure-1PSID": "",
"__Secure-1PSIDCC": "",
"__Secure-1PSIDTS": "",
},
)

client = Client()
response = client.chat.completions.create(
model="gemini",
messages=[{"role": "user", "content": "What do you see?"}],
image=open("156_2.jpeg", "rb"),
)

print(response.choices[0].message.content)

Run result
Traceback (most recent call last):
File "/home/scvrlet/other/study/grad_work/ai_requests.py", line 83, in
response = client.chat.completions.create(
File "/home/scvrlet/.local/lib/python3.10/site-packages/g4f/client/client.py", line 114, in create
return response if stream else next(response)
File "/home/scvrlet/.local/lib/python3.10/site-packages/g4f/client/client.py", line 53, in iter_append_model_and_provider
for chunk in response:
File "/home/scvrlet/.local/lib/python3.10/site-packages/g4f/client/client.py", line 28, in iter_response
for idx, chunk in enumerate(response):
File "/home/scvrlet/.local/lib/python3.10/site-packages/g4f/providers/base_provider.py", line 216, in create_completion
yield loop.run_until_complete(await_callback(gen.anext))
File "/usr/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
return future.result()
File "/home/scvrlet/.local/lib/python3.10/site-packages/g4f/providers/base_provider.py", line 45, in await_callback
return await callback()
File "/home/scvrlet/.local/lib/python3.10/site-packages/g4f/Provider/needs_auth/Gemini.py", line 146, in create_async_generator
image_url = await cls.upload_image(base_connector, to_bytes(image), image_name) if image else None
File "/home/scvrlet/.local/lib/python3.10/site-packages/g4f/Provider/needs_auth/Gemini.py", line 229, in upload_image
await raise_for_status(response)
UnboundLocalError: local variable 'response' referenced before assignment

Environment
Python 3.10.12

  • location Switzerland
@SCVRLET SCVRLET added the bug Something isn't working label May 9, 2024
HyiKi added a commit to HyiKi/gpt4free that referenced this issue May 9, 2024
@HyiKi HyiKi mentioned this issue May 9, 2024
@HyiKi
Copy link
Contributor

HyiKi commented May 9, 2024

ok, I'll fix it in the linked mr. cc @hlohaus

@SCVRLET SCVRLET closed this as completed May 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants