You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to understand why caching works differently between these two libraries. vertexai.preview seems to be agnostic to the model used for creating cache however, genai runs into an error when cache is loaded with a different model than the one used to create it. Does the caching work differently under the hood and is the behaviour of one library more correct than the other?
In vertexai.preview, the model can be loaded with a cache using the following and it works fine.
fromvertexai.previewimportcachingfromvertexai.preview.generative_modelsimportGenerativeModelcached_content=caching.CachedContent.create(
model_name="gemini-1.5-pro-002",
contents= ["The sky is blue."*2000])
model=GenerativeModel(model_name="gemini-2.0-flash-001").from_cached_content(cached_content)
response=model.generate_content("What colour is sky?")
print(response.text)
>>Blue
However, a similar code using genai results in an error.
fromgoogle.genaiimportClient, typesclient=Client()
cached_content=client.caches.create(
model="gemini-1.5-pro-002",
config=types.CreateCachedContentConfig(
contents=["The sky is blue."*2000]))
response=client.models.generate_content(
model="gemini-2.0-flash-001",
contents="What colour is the sky?",
config=types.GenerateContentConfig(cached_content=cached_content.name,))
print(response.text)
>>google.genai.errors.ClientError: 400INVALID_ARGUMENT. {'error': {'code': 400, 'message': 'The model in the inference request gemini-2.0-flash-001 does not match the model in the cached content...'}}
The text was updated successfully, but these errors were encountered:
I am trying to understand why caching works differently between these two libraries. vertexai.preview seems to be agnostic to the model used for creating cache however, genai runs into an error when cache is loaded with a different model than the one used to create it. Does the caching work differently under the hood and is the behaviour of one library more correct than the other?
In vertexai.preview, the model can be loaded with a cache using the following and it works fine.
However, a similar code using genai results in an error.
The text was updated successfully, but these errors were encountered: