Skip to content

Commit 10140a5

Browse files
committed
implement suggestions
1 parent f05c446 commit 10140a5

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

integrations/google_genai/src/haystack_integrations/components/generators/google_genai/chat/chat_generator.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,18 @@ def weather_function(city: str):
138138
messages = [ChatMessage.from_user("What's the weather in Paris?")]
139139
response = chat_generator_with_tools.run(messages=messages)
140140
```
141+
142+
### Usage example with FileContent embedded in a ChatMessage
143+
144+
```python
145+
from haystack.dataclasses import ChatMessage, FileContent
146+
from haystack_integrations.components.generators.google_genai import GoogleGenAIChatGenerator
147+
148+
file_content = FileContent.from_url("https://arxiv.org/pdf/2309.08632")
149+
chat_message = ChatMessage.from_user(content_parts=[file_content, "Summarize this paper in 100 words."])
150+
chat_generator = GoogleGenAIChatGenerator()
151+
response = chat_generator.run(messages=[chat_message])
152+
```
141153
"""
142154

143155
def __init__(
@@ -255,7 +267,6 @@ def _handle_streaming_response(
255267
try:
256268
chunks = []
257269

258-
chunk = None
259270
for i, chunk in enumerate(response_stream):
260271
streaming_chunk = _convert_google_chunk_to_streaming_chunk(
261272
chunk=chunk, index=i, component_info=component_info, model=self._model

integrations/google_genai/src/haystack_integrations/components/generators/google_genai/chat/utils.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,9 @@ def _convert_message_to_google_genai_format(message: ChatMessage) -> types.Conte
233233
msg = f"{cls_name} is only supported for user messages"
234234
raise ValueError(msg)
235235

236-
# Validate image MIME type and format
236+
# MIME type validation: must be provided and, for images, one of the supported types
237237
if not content_part.mime_type:
238-
msg = f"Mime type is required to use {cls_name} with GoogleGenAIChatGenerator"
238+
msg = f"MIME type is required to use {cls_name} with GoogleGenAIChatGenerator"
239239
raise ValueError(msg)
240240

241241
if (
@@ -256,7 +256,6 @@ def _convert_message_to_google_genai_format(message: ChatMessage) -> types.Conte
256256
)
257257
bytes_data = base64.b64decode(base64_data)
258258

259-
# Create Part using from_bytes method
260259
file_part = types.Part.from_bytes(data=bytes_data, mime_type=content_part.mime_type)
261260
parts.append(file_part)
262261

0 commit comments

Comments
 (0)