-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
PIL Image conversion issues with Gemini API Parts #5033
Comments
Thanks for the issue. I believe this has already been fixed in 0.4.1. The code you are showing is using 0.2 API. Would you like to submit a fix to the 0.2 package? Make sure you are using |
I went back and double-checked - I was using the following versions:
Following your comment, I created a new virtual env with Error message: Traceback (most recent call last):
File "/home/xwang3/Projects/test/main.py", line 31, in <module>
user_agent.initiate_chat(
File "/home/xwang3/Projects/test/test-autogen-ver/lib/python3.10/site-packages/autogen/agentchat/conversable_agent.py", line 1106, in initiate_chat
self.send(msg2send, recipient, silent=silent)
File "/home/xwang3/Projects/test/test-autogen-ver/lib/python3.10/site-packages/autogen/agentchat/conversable_agent.py", line 741, in send
recipient.receive(message, self, request_reply, silent)
File "/home/xwang3/Projects/test/test-autogen-ver/lib/python3.10/site-packages/autogen/agentchat/conversable_agent.py", line 906, in receive
reply = self.generate_reply(messages=self.chat_messages[sender], sender=sender)
File "/home/xwang3/Projects/test/test-autogen-ver/lib/python3.10/site-packages/autogen/agentchat/conversable_agent.py", line 2060, in generate_reply
final, reply = reply_func(self, messages=messages, sender=sender, config=reply_func_tuple["config"])
File "/home/xwang3/Projects/test/test-autogen-ver/lib/python3.10/site-packages/autogen/agentchat/contrib/multimodal_conversable_agent.py", line 120, in generate_oai_reply
response = client.create(
File "/home/xwang3/Projects/test/test-autogen-ver/lib/python3.10/site-packages/autogen/oai/client.py", line 832, in create
response = client.create(params)
File "/home/xwang3/Projects/test/test-autogen-ver/lib/python3.10/site-packages/autogen/oai/gemini.py", line 205, in create
gemini_messages = self._oai_messages_to_gemini_messages(messages)
File "/home/xwang3/Projects/test/test-autogen-ver/lib/python3.10/site-packages/autogen/oai/gemini.py", line 381, in _oai_messages_to_gemini_messages
rst.append(Content(parts=curr_parts, role=role))
File "/home/xwang3/Projects/test/test-autogen-ver/lib/python3.10/site-packages/proto/message.py", line 734, in __init__
super().__setattr__("_pb", self._meta.pb(**params))
TypeError: Parameter to MergeFrom() must be instance of same class: expected <class 'Part'> got <class 'PIL.PngImagePlugin.PngImageFile'>. Pip list
|
We do not publish the For the code you are referencing you need to use |
I am confused. My current version is |
@xuefei-wang, your code is using the
**Anyone can publish a package to PyPI and use our import name spaces. So, it is very important to check what you actually installed. ** My suggestion is:
|
@xuefei-wang please see #4217 |
Got it. Thanks for the clarification, everyone! It was very helpful. |
What happened?
I encountered type compatibility issues when trying to pass images to Gemini API. The images were converted into PIL Images, but not to
Part
, therefore causing issues.I created this conversion function (see below) that works for my use case and added it to
autogen/oai/gemini.py
. Just wanted to post it in case anyone needs it.What did you expect to happen?
Error message:
TypeError: Parameter to MergeFrom() must be instance of same class: expected Part got PIL.PngImagePlugin.PngImageFile.
How can we reproduce it (as minimally and precisely as possible)?
AutoGen version
0.4.1
Which package was this bug in
Core
Model used
gemini
Python version
No response
Operating system
No response
Any additional info you think would be helpful for fixing this bug
The text was updated successfully, but these errors were encountered: