diff --git a/generative_ai/context_caching/context_caching_test.py b/generative_ai/context_caching/test_context_caching.py similarity index 99% rename from generative_ai/context_caching/context_caching_test.py rename to generative_ai/context_caching/test_context_caching.py index 7cd8b556c64..beb9bef92ce 100644 --- a/generative_ai/context_caching/context_caching_test.py +++ b/generative_ai/context_caching/test_context_caching.py @@ -11,7 +11,6 @@ # 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. - import os from typing import Generator diff --git a/generative_ai/context_caching/update_context_cache.py b/generative_ai/context_caching/update_context_cache.py index 28a154a4657..15527418b6a 100644 --- a/generative_ai/context_caching/update_context_cache.py +++ b/generative_ai/context_caching/update_context_cache.py @@ -19,7 +19,9 @@ def update_context_cache(cache_id: str) -> str: # [START generativeaionvertexai_gemini_update_context_cache] import vertexai - import datetime + from datetime import datetime as dt + from datetime import timezone as tz + from datetime import timedelta from vertexai.preview import caching @@ -31,8 +33,13 @@ def update_context_cache(cache_id: str) -> str: cached_content = caching.CachedContent(cached_content_name=cache_id) - # Update the expiration time by 1 hour - cached_content.update(ttl=datetime.timedelta(hours=1)) + # Option1: Update the context cache using TTL (Time to live) + cached_content.update(ttl=timedelta(hours=3)) + cached_content.refresh() + + # Option2: Update the context cache using specific time + next_week_utc = dt.now(tz.utc) + timedelta(days=7) + cached_content.update(expire_time=next_week_utc) cached_content.refresh() print(cached_content.expire_time)