Skip to content

Commit

Permalink
fix: Handle TypeError: Could not create Blob in `GoogleAIGeminiChat…
Browse files Browse the repository at this point in the history
…Generator` (#772)

* bugfix 654

aligned _message_to_content to VertexAIGeminiChatGenerator

* Update test_chat_gemini.py

---------

Co-authored-by: Silvano Cerza <[email protected]>
  • Loading branch information
antoniomuzzolini and silvanocerza authored Jun 5, 2024
1 parent 4290d6a commit ab58a23
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,10 @@ def _message_to_content(self, message: ChatMessage) -> Content:
elif message.role == ChatRole.SYSTEM:
part = Part()
part.text = message.content
return part
elif message.role == ChatRole.FUNCTION:
part = Part()
part.function_response.name = message.name
part.function_response.response = message.content
return part
elif message.role == ChatRole.USER:
part = self._convert_part(message.content)
else:
Expand Down
12 changes: 12 additions & 0 deletions integrations/google_ai/tests/generators/chat/test_chat_gemini.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,15 @@ def get_current_weather(location: str, unit: str = "celsius"): # noqa: ARG001

res = gemini_chat.run(messages=messages)
assert len(res["replies"]) > 0


@pytest.mark.skipif("GOOGLE_API_KEY" not in os.environ, reason="GOOGLE_API_KEY not set")
def test_past_conversation():
gemini_chat = GoogleAIGeminiChatGenerator(model="gemini-pro")
messages = [
ChatMessage.from_user(content="What is 2+2?"),
ChatMessage.from_system(content="It's an arithmetic operation."),
ChatMessage.from_user(content="Yeah, but what's the result?"),
]
res = gemini_chat.run(messages=messages)
assert len(res["replies"]) > 0

0 comments on commit ab58a23

Please sign in to comment.