fix: Support saving text artifacts in GCS artifact service

Resolves https://github.com/google/adk-python/issues/2775

PiperOrigin-RevId: 802850139
This commit is contained in:
Shangjie Chen
2025-09-03 21:55:07 -07:00
committed by Copybara-Service
parent edda922791
commit cecf7e805d
2 changed files with 14 additions and 6 deletions
@@ -180,10 +180,17 @@ class GcsArtifactService(BaseArtifactService):
)
blob = self.bucket.blob(blob_name)
blob.upload_from_string(
data=artifact.inline_data.data,
content_type=artifact.inline_data.mime_type,
)
if artifact.inline_data:
blob.upload_from_string(
data=artifact.inline_data.data,
content_type=artifact.inline_data.mime_type,
)
elif artifact.text:
blob.upload_from_string(
data=artifact.text,
)
else:
raise ValueError("Artifact must have either inline_data or text.")
return version
@@ -258,8 +258,9 @@ async def test_list_versions(service_type):
)
for i in range(3)
]
versions.append(types.Part.from_text(text="hello"))
for i in range(3):
for i in range(4):
await artifact_service.save_artifact(
app_name=app_name,
user_id=user_id,
@@ -275,4 +276,4 @@ async def test_list_versions(service_type):
filename=filename,
)
assert response_versions == list(range(3))
assert response_versions == list(range(4))