Skip to content

Commit 607ca14

Browse files
authored
Fixes #166. Thanks @piresramon. (#208)
1 parent c3c90f8 commit 607ca14

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

google/generativeai/types/content_types.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ class BlobDict(TypedDict):
9393
def _convert_dict(d: Mapping) -> glm.Content | glm.Part | glm.Blob:
9494
if is_content_dict(d):
9595
content = dict(d)
96+
if isinstance(parts := content["parts"], str):
97+
content["parts"] = [parts]
9698
content["parts"] = [to_part(part) for part in content["parts"]]
9799
return glm.Content(content)
98100
elif is_part_dict(d):

tests/test_content.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,14 @@ def test_strict_to_contents_fails(self, examples):
137137
["glm.Content", [glm.Content(parts=[{"text": "Hello world!"}])]],
138138
["ContentDict", [{"parts": [{"text": "Hello world!"}]}]],
139139
["ContentDict-unwraped", [{"parts": ["Hello world!"]}]],
140+
["ContentDict+str-part", [{"parts": "Hello world!"}]],
140141
)
141142
def test_to_contents(self, example):
142143
contents = content_types.to_contents(example)
143144
part = contents[0].parts[0]
144145

145146
self.assertLen(contents, 1)
147+
146148
self.assertLen(contents[0].parts, 1)
147149
self.assertIsInstance(part, glm.Part)
148150
self.assertEqual(part.text, "Hello world!")

0 commit comments

Comments
 (0)