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 (OpenAI gpt-4). UnboundLocalError: local variable 'image_request' referenced before assignment #1939

Closed
SCVRLET opened this issue May 11, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@SCVRLET
Copy link

SCVRLET commented May 11, 2024

Code
import g4f
from g4f.client import Client

response = Client().chat.completions.create(
model="gpt-4",
provider=g4f.Provider.OpenaiChat,
messages=[{"role": "user", "content": "message"}],
image=open("joined_image.jpeg", "rb"),
image_name='joined_image.jpeg'
)
print(response.choices[0].message.content)

Run result
Traceback (most recent call last):
File "/home/scvrlet/other/study/grad_work/ai_requests.py", line 68, 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/OpenaiChat.py", line 473, in create_async_generator
data["messages"] = cls.create_messages(messages, image_request)
UnboundLocalError: local variable 'image_request' referenced before assignment

@SCVRLET SCVRLET added the bug Something isn't working label May 11, 2024
@hlohaus
Copy link
Collaborator

hlohaus commented May 15, 2024

Hey there! So, you'll need a Plus subscription if you want to upload images with OpenAI Chat. Plus, I've made some improvements to the error handling, so things should run a bit smoother now.

@SCVRLET
Copy link
Author

SCVRLET commented May 15, 2024

Hey!
Of course I do have subscription. Thx though

@hlohaus
Copy link
Collaborator

hlohaus commented May 15, 2024

Hey, did the fix work? Have you updated it yet?

@hlohaus hlohaus closed this as completed May 19, 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