File tree 2 files changed +14
-1
lines changed
2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -88,8 +88,10 @@ def _prepare_create_request(
88
88
ttl : Optional [caching_types .ExpirationTypes ] = datetime .timedelta (hours = 1 ),
89
89
) -> glm .CreateCachedContentRequest :
90
90
"""Prepares a CreateCachedContentRequest."""
91
- if "cachedContents/" not in name :
91
+ if caching_types . valid_cached_content_name ( name ) :
92
92
name = "cachedContents/" + name
93
+ else :
94
+ raise ValueError (caching_types .NAME_ERROR_MESSAGE .format (name = name ))
93
95
94
96
if "/" not in model :
95
97
model = "models/" + model
Original file line number Diff line number Diff line change 17
17
import datetime
18
18
from typing import Optional , Union
19
19
from typing_extensions import TypedDict
20
+ import re
20
21
21
22
__all__ = ["TTL" ]
22
23
23
24
25
+ _VALID_CACHED_CONTENT_NAME = r"([a-z0-9-\.]+)$"
26
+ NAME_ERROR_MESSAGE = (
27
+ "The `name` must consist of alphanumeric characters (or `-` or `.`). Received: `{name}`"
28
+ )
29
+
30
+
31
+ def valid_cached_content_name (name : str ) -> bool :
32
+ return re .match (_VALID_CACHED_CONTENT_NAME , name ) is not None
33
+
34
+
24
35
class TTL (TypedDict ):
25
36
seconds : int
26
37
You can’t perform that action at this time.
0 commit comments