Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A cached prompt entry is fixed to a single system prompt #348

Open
zaphod72 opened this issue Feb 14, 2025 · 0 comments
Open

A cached prompt entry is fixed to a single system prompt #348

zaphod72 opened this issue Feb 14, 2025 · 0 comments

Comments

@zaphod72
Copy link

Looking at CreatedCachedContentConfig, the system_instruction is optional. That seems to imply that a cached prompt can be independent of a system prompt. However, I can not find a way to reuse one cached prompt with different system prompts.

Error message: Tool config, tools and system instruction should not be set in therequest [sic] when using cached content.

(First posted at Google Community Forums)

Here's my scenario -

I have a set of system prompts that will run as separate inferences with each element of a set of user prompts. The user prompts consist of large PDFs so I want to cache those.

So if I have
System Prompt A, B, C

and
UserPrompt 1, 2, 3

then I will run inferences
SP_A + UP_1
SP_A + UP_2
SP_A + UP_3
SP_B + UP_1
SP_B + UP_2
etc.

As each User Prompt has a large number of tokens I want to cache these.
However I can't seem to be able to just cache the user prompt.

I have:

        cached_content = client.caches.create(
            model=llm_id,
            config=CreateCachedContentConfig(
                contents=<List of Part.from_uri>,
                ttl=PROMPT_CACHE_TTL,
            ),
        )
...
    generation_config = GenerateContentConfig(
        temperature=params.temperature,
        max_output_tokens=params.max_tokens,
        system_instruction="You are a helpful assistant."
        cached_content=cache_entry_id,
    )
    generation_response = client.chats.create(
        model=params.llm_id,
        config=generation_config,
    ).send_message(message="Summarize the documents")

I get

google.genai.errors.ClientError: 400 INVALID_ARGUMENT. {
  'error': {
    'code': 400,
    'message': 'Tool config, tools and system instruction should not be set in therequest when using cached content.',
    'status': 'INVALID_ARGUMENT'
}}

TIA

@sararob sararob self-assigned this Feb 18, 2025
@sararob sararob removed their assignment Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants