@@ -128,7 +128,7 @@ def _convert_dict(d: Mapping) -> glm.Content | glm.Part | glm.Blob:
128
128
if "inline_data" in part :
129
129
part ["inline_data" ] = to_blob (part ["inline_data" ])
130
130
if "file_data" in part :
131
- part ["file_data" ] = to_file_data (part ["file_data" ])
131
+ part ["file_data" ] = file_types . to_file_data (part ["file_data" ])
132
132
return glm .Part (part )
133
133
elif is_blob_dict (d ):
134
134
blob = d
@@ -176,43 +176,21 @@ def to_blob(blob: BlobType) -> glm.Blob:
176
176
)
177
177
178
178
179
- class FileDataDict (TypedDict ):
180
- mime_type : str
181
- file_uri : str
182
-
183
-
184
- FileDataType = Union [FileDataDict , glm .FileData , file_types .File ]
185
-
186
-
187
- def to_file_data (file_data : FileDataType ):
188
- if isinstance (file_data , dict ):
189
- if "file_uri" in file_data :
190
- file_data = glm .FileData (file_data )
191
- else :
192
- file_data = glm .File (file_data )
193
-
194
- if isinstance (file_data , file_types .File ):
195
- file_data = file_data .to_proto ()
196
-
197
- if isinstance (file_data , (glm .File , file_types .File )):
198
- file_data = glm .FileData (
199
- mime_type = file_data .mime_type ,
200
- file_uri = file_data .uri ,
201
- )
202
-
203
- if isinstance (file_data , glm .FileData ):
204
- return file_data
205
- else :
206
- raise TypeError (f"Could not convert a { type (file_data )} to `FileData`" )
207
-
208
-
209
179
class PartDict (TypedDict ):
210
180
text : str
211
181
inline_data : BlobType
212
182
213
183
214
184
# When you need a `Part` accept a part object, part-dict, blob or string
215
- PartType = Union [glm .Part , PartDict , BlobType , str , glm .FunctionCall , glm .FunctionResponse ]
185
+ PartType = Union [
186
+ glm .Part ,
187
+ PartDict ,
188
+ BlobType ,
189
+ str ,
190
+ glm .FunctionCall ,
191
+ glm .FunctionResponse ,
192
+ file_types .FileDataType ,
193
+ ]
216
194
217
195
218
196
def is_part_dict (d ):
@@ -236,7 +214,7 @@ def to_part(part: PartType):
236
214
elif isinstance (part , glm .FileData ):
237
215
return glm .Part (file_data = part )
238
216
elif isinstance (part , (glm .File , file_types .File )):
239
- return glm .Part (file_data = to_file_data (part ))
217
+ return glm .Part (file_data = file_types . to_file_data (part ))
240
218
elif isinstance (part , glm .FunctionCall ):
241
219
return glm .Part (function_call = part )
242
220
elif isinstance (part , glm .FunctionResponse ):
0 commit comments