@@ -79,19 +79,20 @@ def _decode_cached_content(cls, cached_content: glm.CachedContent) -> CachedCont
79
79
80
80
@staticmethod
81
81
def _prepare_create_request (
82
- name : str ,
83
82
model : str ,
83
+ name : str = None ,
84
84
system_instruction : Optional [content_types .ContentType ] = None ,
85
85
contents : Optional [content_types .ContentsType ] = None ,
86
86
tools : Optional [content_types .FunctionLibraryType ] = None ,
87
87
tool_config : Optional [content_types .ToolConfigType ] = None ,
88
88
ttl : Optional [caching_types .ExpirationTypes ] = datetime .timedelta (hours = 1 ),
89
89
) -> glm .CreateCachedContentRequest :
90
90
"""Prepares a CreateCachedContentRequest."""
91
- if caching_types .valid_cached_content_name (name ):
91
+ if name is not None :
92
+ if not caching_types .valid_cached_content_name (name ):
93
+ raise ValueError (caching_types .NAME_ERROR_MESSAGE .format (name = name ))
94
+
92
95
name = "cachedContents/" + name
93
- else :
94
- raise ValueError (caching_types .NAME_ERROR_MESSAGE .format (name = name ))
95
96
96
97
if "/" not in model :
97
98
model = "models/" + model
@@ -127,8 +128,8 @@ def _prepare_create_request(
127
128
@classmethod
128
129
def create (
129
130
cls ,
130
- name : str ,
131
131
model : str ,
132
+ name : str = None ,
132
133
system_instruction : Optional [content_types .ContentType ] = None ,
133
134
contents : Optional [content_types .ContentsType ] = None ,
134
135
tools : Optional [content_types .FunctionLibraryType ] = None ,
@@ -139,11 +140,10 @@ def create(
139
140
"""Creates CachedContent resource.
140
141
141
142
Args:
142
- name: The resource name referring to the cached content.
143
- Format: cachedContents/{id}.
144
143
model: The name of the `Model` to use for cached content
145
144
Format: models/{model}. Cached content resource can be only
146
145
used with model it was created for.
146
+ name: The resource name referring to the cached content.
147
147
system_instruction: Developer set system instruction.
148
148
contents: Contents to cache.
149
149
tools: A list of `Tools` the model may use to generate response.
@@ -157,8 +157,8 @@ def create(
157
157
client = get_default_cache_client ()
158
158
159
159
request = cls ._prepare_create_request (
160
- name = name ,
161
160
model = model ,
161
+ name = name ,
162
162
system_instruction = system_instruction ,
163
163
contents = contents ,
164
164
tools = tools ,
0 commit comments