2222import json
2323import mock
2424import pytest
25- from vertexai .preview import caching
25+ from vertexai .caching import _caching
2626from google .cloud .aiplatform import initializer
2727import vertexai
2828from google .cloud .aiplatform_v1beta1 .types .cached_content import (
3535from google .cloud .aiplatform_v1beta1 .types .tool import (
3636 ToolConfig as GapicToolConfig ,
3737)
38- from google .cloud .aiplatform_v1beta1 .services import (
38+ from google .cloud .aiplatform_v1 .services import (
3939 gen_ai_cache_service ,
4040)
41+ from vertexai .generative_models ._generative_models import (
42+ Content ,
43+ PartsType ,
44+ Tool ,
45+ ToolConfig ,
46+ ContentsType ,
47+ )
4148
4249
4350_TEST_PROJECT = "test-project"
@@ -141,7 +148,7 @@ def list_cached_contents(self, request):
141148
142149@pytest .mark .usefixtures ("google_auth_mock" )
143150class TestCaching :
144- """Unit tests for caching .CachedContent."""
151+ """Unit tests for _caching .CachedContent."""
145152
146153 def setup_method (self ):
147154 vertexai .init (
@@ -156,7 +163,7 @@ def test_constructor_with_full_resource_name(self, mock_get_cached_content):
156163 full_resource_name = (
157164 "projects/123/locations/europe-west1/cachedContents/contents-id"
158165 )
159- cache = caching .CachedContent (
166+ cache = _caching .CachedContent (
160167 cached_content_name = full_resource_name ,
161168 )
162169
@@ -166,7 +173,7 @@ def test_constructor_with_full_resource_name(self, mock_get_cached_content):
166173 def test_constructor_with_only_content_id (self , mock_get_cached_content ):
167174 partial_resource_name = "contents-id"
168175
169- cache = caching .CachedContent (
176+ cache = _caching .CachedContent (
170177 cached_content_name = partial_resource_name ,
171178 )
172179
@@ -179,7 +186,7 @@ def test_constructor_with_only_content_id(self, mock_get_cached_content):
179186 def test_get_with_content_id (self , mock_get_cached_content ):
180187 partial_resource_name = "contents-id"
181188
182- cache = caching .CachedContent .get (
189+ cache = _caching .CachedContent .get (
183190 cached_content_name = partial_resource_name ,
184191 )
185192
@@ -192,7 +199,7 @@ def test_get_with_content_id(self, mock_get_cached_content):
192199 def test_create_with_real_payload (
193200 self , mock_create_cached_content , mock_get_cached_content
194201 ):
195- cache = caching .CachedContent .create (
202+ cache = _caching .CachedContent .create (
196203 model_name = "model-name" ,
197204 system_instruction = GapicContent (
198205 role = "system" , parts = [GapicPart (text = "system instruction" )]
@@ -219,7 +226,7 @@ def test_create_with_real_payload(
219226 def test_create_with_real_payload_and_wrapped_type (
220227 self , mock_create_cached_content , mock_get_cached_content
221228 ):
222- cache = caching .CachedContent .create (
229+ cache = _caching .CachedContent .create (
223230 model_name = "model-name" ,
224231 system_instruction = "Please answer my questions with cool" ,
225232 tools = [],
@@ -239,15 +246,15 @@ def test_create_with_real_payload_and_wrapped_type(
239246 assert cache .display_name == _TEST_DISPLAY_NAME
240247
241248 def test_list (self , mock_list_cached_contents ):
242- cached_contents = caching .CachedContent .list ()
249+ cached_contents = _caching .CachedContent .list ()
243250 for i , cached_content in enumerate (cached_contents ):
244251 assert cached_content .name == f"cached_content{ i + 1 } _from_list_request"
245252 assert cached_content .model_name == f"model-name{ i + 1 } "
246253
247254 def test_print_a_cached_content (
248255 self , mock_create_cached_content , mock_get_cached_content
249256 ):
250- cached_content = caching .CachedContent .create (
257+ cached_content = _caching .CachedContent .create (
251258 model_name = "model-name" ,
252259 system_instruction = "Please answer my questions with cool" ,
253260 tools = [],
0 commit comments