mirror of
https://github.com/encounter/adk-python.git
synced 2026-07-09 18:19:28 -07:00
feat: update save_files_as_artifacts_plugin to never keep inline data
PiperOrigin-RevId: 834328794
This commit is contained in:
committed by
Copybara-Service
parent
e15e19da05
commit
857de04deb
@@ -116,13 +116,6 @@ class SaveFilesAsArtifactsPlugin(BasePlugin):
|
||||
)
|
||||
if file_part:
|
||||
new_parts.append(file_part)
|
||||
else:
|
||||
logger.debug(
|
||||
'Artifact %s is not exposed via a model-accessible URI; keeping'
|
||||
' inline data in user message.',
|
||||
file_name,
|
||||
)
|
||||
new_parts.append(part)
|
||||
|
||||
modified = True
|
||||
logger.info(f'Successfully saved artifact: {file_name}')
|
||||
|
||||
@@ -173,43 +173,6 @@ class TestSaveFilesAsArtifactsPlugin:
|
||||
)
|
||||
assert result.parts[4].file_data.display_name == "file2.jpg"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_unsupported_canonical_uri_keeps_inline_data(self):
|
||||
"""Fallback to inline data when artifact URI is not model-accessible."""
|
||||
inline_data = types.Blob(
|
||||
display_name="local_only.png",
|
||||
data=b"image data",
|
||||
mime_type="image/png",
|
||||
)
|
||||
|
||||
artifact_service = self.mock_context.artifact_service
|
||||
original_side_effect = artifact_service.get_artifact_version.side_effect
|
||||
|
||||
async def _memory_only_version(**kwargs):
|
||||
return ArtifactVersion(
|
||||
version=kwargs.get("version", 0),
|
||||
canonical_uri=(
|
||||
"memory://apps/test_app/users/test_user/sessions/test_session/"
|
||||
"artifacts/local_only.png/versions/0"
|
||||
),
|
||||
mime_type="image/png",
|
||||
)
|
||||
|
||||
artifact_service.get_artifact_version.side_effect = _memory_only_version
|
||||
|
||||
try:
|
||||
user_message = types.Content(parts=[types.Part(inline_data=inline_data)])
|
||||
result = await self.plugin.on_user_message_callback(
|
||||
invocation_context=self.mock_context, user_message=user_message
|
||||
)
|
||||
|
||||
assert result
|
||||
assert len(result.parts) == 2
|
||||
assert result.parts[0].text == '[Uploaded Artifact: "local_only.png"]'
|
||||
assert result.parts[1].inline_data == inline_data
|
||||
finally:
|
||||
artifact_service.get_artifact_version.side_effect = original_side_effect
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_no_artifact_service(self):
|
||||
"""Test behavior when artifact service is not available."""
|
||||
|
||||
Reference in New Issue
Block a user