Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions google/genai/caches.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ def _CreateCachedContentConfig_to_vertex(
if getv(from_object, ['display_name']) is not None:
setv(parent_object, ['displayName'], getv(from_object, ['display_name']))

if getv(from_object, ['labels']) is not None:
setv(parent_object, ['labels'], getv(from_object, ['labels']))

if getv(from_object, ['contents']) is not None:
setv(
parent_object,
Expand Down
43 changes: 43 additions & 0 deletions google/genai/tests/caches/test_cache_labels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from ... import caches
from ... import types


def test_create_cached_content_config_to_vertex_includes_labels():
parent_object = {}

caches._CreateCachedContentConfig_to_vertex(
types.CreateCachedContentConfig(
display_name='test cache',
labels={'team': 'genai', 'use_case': 'billing'},
),
parent_object,
)

assert parent_object['labels'] == {
'team': 'genai',
'use_case': 'billing',
}


def test_cached_content_accepts_labels():
cached_content = types.CachedContent(
name='cachedContents/123',
labels={'team': 'genai'},
)

assert cached_content.labels == {'team': 'genai'}
14 changes: 14 additions & 0 deletions google/genai/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -14333,6 +14333,10 @@ class CreateCachedContentConfig(_common.BaseModel):
description="""The user-generated meaningful display name of the cached content.
""",
)
labels: Optional[dict[str, str]] = Field(
default=None,
description="""User specified labels to track billing usage.""",
)
contents: Optional[ContentListUnion] = Field(
default=None,
description="""The content to cache.
Expand Down Expand Up @@ -14383,6 +14387,9 @@ class CreateCachedContentConfigDict(TypedDict, total=False):
"""The user-generated meaningful display name of the cached content.
"""

labels: Optional[dict[str, str]]
"""User specified labels to track billing usage."""

contents: Optional[ContentListUnionDict]
"""The content to cache.
"""
Expand Down Expand Up @@ -14506,6 +14513,10 @@ class CachedContent(_common.BaseModel):
default=None,
description="""The user-generated meaningful display name of the cached content.""",
)
labels: Optional[dict[str, str]] = Field(
default=None,
description="""User specified labels to track billing usage.""",
)
model: Optional[str] = Field(
default=None,
description="""The name of the publisher model to use for cached content.""",
Expand Down Expand Up @@ -14535,6 +14546,9 @@ class CachedContentDict(TypedDict, total=False):
display_name: Optional[str]
"""The user-generated meaningful display name of the cached content."""

labels: Optional[dict[str, str]]
"""User specified labels to track billing usage."""

model: Optional[str]
"""The name of the publisher model to use for cached content."""

Expand Down