|
31 | 31 | ThinkingPart, |
32 | 32 | ToolCallPart, |
33 | 33 | ToolReturnPart, |
| 34 | + UploadedFile, |
34 | 35 | UserPromptPart, |
35 | 36 | VideoUrl, |
36 | 37 | ) |
|
54 | 55 | ContentUnionDict, |
55 | 56 | CountTokensConfigDict, |
56 | 57 | ExecutableCodeDict, |
| 58 | + File, |
57 | 59 | FunctionCallDict, |
58 | 60 | FunctionCallingConfigDict, |
59 | 61 | FunctionCallingConfigMode, |
@@ -425,7 +427,7 @@ async def _map_messages(self, messages: list[ModelMessage]) -> tuple[ContentDict |
425 | 427 | if isinstance(part, SystemPromptPart): |
426 | 428 | system_parts.append({'text': part.content}) |
427 | 429 | elif isinstance(part, UserPromptPart): |
428 | | - message_parts.extend(await self._map_user_prompt(part)) |
| 430 | + message_parts.extend(await self._map_user_prompt(part, contents)) |
429 | 431 | elif isinstance(part, ToolReturnPart): |
430 | 432 | message_parts.append( |
431 | 433 | { |
@@ -465,7 +467,7 @@ async def _map_messages(self, messages: list[ModelMessage]) -> tuple[ContentDict |
465 | 467 | system_instruction = ContentDict(role='user', parts=system_parts) if system_parts else None |
466 | 468 | return system_instruction, contents |
467 | 469 |
|
468 | | - async def _map_user_prompt(self, part: UserPromptPart) -> list[PartDict]: |
| 470 | + async def _map_user_prompt(self, part: UserPromptPart, contents: list[ContentUnionDict]) -> list[PartDict]: |
469 | 471 | if isinstance(part.content, str): |
470 | 472 | return [{'text': part.content}] |
471 | 473 | else: |
@@ -499,6 +501,12 @@ async def _map_user_prompt(self, part: UserPromptPart) -> list[PartDict]: |
499 | 501 | content.append( |
500 | 502 | {'file_data': {'file_uri': item.url, 'mime_type': item.media_type}} |
501 | 503 | ) # pragma: lax no cover |
| 504 | + elif isinstance(item, UploadedFile): |
| 505 | + if not isinstance(item.file, File): |
| 506 | + raise UserError('UploadedFile.file must be a genai.types.File object') |
| 507 | + # genai.types.File is its own ContentUnionDict and not a |
| 508 | + # PartDict, so append to the contents directly. |
| 509 | + contents.append(item.file) |
502 | 510 | else: |
503 | 511 | assert_never(item) |
504 | 512 | return content |
|
0 commit comments