Skip to content

Commit cecf7e8

Browse files
DeanChensjcopybara-github
authored andcommitted
fix: Support saving text artifacts in GCS artifact service
Resolves #2775 PiperOrigin-RevId: 802850139
1 parent edda922 commit cecf7e8

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

‎src/google/adk/artifacts/gcs_artifact_service.py‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,17 @@ def _save_artifact(
180180
)
181181
blob = self.bucket.blob(blob_name)
182182

183-
blob.upload_from_string(
184-
data=artifact.inline_data.data,
185-
content_type=artifact.inline_data.mime_type,
186-
)
183+
if artifact.inline_data:
184+
blob.upload_from_string(
185+
data=artifact.inline_data.data,
186+
content_type=artifact.inline_data.mime_type,
187+
)
188+
elif artifact.text:
189+
blob.upload_from_string(
190+
data=artifact.text,
191+
)
192+
else:
193+
raise ValueError("Artifact must have either inline_data or text.")
187194

188195
return version
189196

‎tests/unittests/artifacts/test_artifact_service.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,9 @@ async def test_list_versions(service_type):
258258
)
259259
for i in range(3)
260260
]
261+
versions.append(types.Part.from_text(text="hello"))
261262

262-
for i in range(3):
263+
for i in range(4):
263264
await artifact_service.save_artifact(
264265
app_name=app_name,
265266
user_id=user_id,
@@ -275,4 +276,4 @@ async def test_list_versions(service_type):
275276
filename=filename,
276277
)
277278

278-
assert response_versions == list(range(3))
279+
assert response_versions == list(range(4))

0 commit comments

Comments
 (0)