promptfoo: Google provider fails when using gemini 1.5 flash

Describe the bug Using the gemini-1.5-flash model fails with an error that is not intuitive to understand.

The error is

API did not return any candidate responses: {"error":{"code":400,"message":"Invalid JSON payload received. Unknown name \"content\" at 'contents[0]': Cannot find field.\nInvalid JSON payload received. Unknown name \"content\" at 'contents[1]': Cannot find field.","status":"INVALID_ARGUMENT","details":[{"@type":"type.googleapis.com/google.rpc.BadRequest","fieldViolations":[{"field":"contents[0]","description":"Invalid JSON payload received. Unknown name \"content\" at 'contents[0]': Cannot find field."},{"field":"contents[1]","description":"Invalid JSON payload received. Unknown name \"content\" at 'contents[1]': Cannot find field."}]}]}}

In addition to the following log Using unknown Google chat model: gemini-1.5-flash-latest

To Reproduce Try and use the model in providers: e.g

  - id: google:gemini-1.5-flash-latest
    config:
      temperature: 0
      max_tokens: 4096

Expected behavior The model is used to evaluate the prompts.

Screenshots N/A

System information (please complete the following information):

  • Promptfoo version: 0.92.3

Additional context Looks similar to #1393 although that particular issue is specific to using gemini as a grader?

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 19 (10 by maintainers)

Most upvoted comments

It looks like the API request we use is out of date

https://github.com/promptfoo/promptfoo/blob/207469a6a54b3a4123c2f8418d51affe9b04d40d/src/providers/palm.ts#L103-L112

vs the structure used in REST examples here: https://ai.google.dev/gemini-api/docs/text-generation?lang=rest

{
        "contents": [{
            "parts":[
                {"text": "Write a story about a magic backpack."}
            ]
        }],
        "safetySettings": [
            {
                "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
                "threshold": "BLOCK_ONLY_HIGH"
            }
        ],
        "generationConfig": {
            "stopSequences": [
                "Title"
            ],
            "temperature": 1.0,
            "maxOutputTokens": 800,
            "topP": 0.8,
            "topK": 10
        }
    }

Note that there is also a node API client for AI studio: https://github.com/google-gemini/generative-ai-js

@hyusetiawan Promptfoo is using v1 not v1beta so that might be why. I’ve opened a PR that lets you override the API version #2529

This is working for me now on 0.94.0 - thank you!

Hi @aaronstillwell and @danpe,

We’ve made some updates to address the Gemini formatting issue in the latest release. Could you please try updating to version 0.94.0 and see if it resolves the problem? The fix is included in #1947.

If the issue persists, feel free to book some time on my calendar here: https://cal.com/michael-dangelo/15min, and we can troubleshoot it together.

Thanks again for your patience and feedback!

@aaronstillwell I get the same:


API did not return any candidate responses: {"error":{"code":400,"message":"Invalid JSON payload received. Unknown name \"content\" at 'contents[0]': Cannot find field.\nInvalid JSON payload received. Unknown name \"content\" at 'contents[1]': Cannot find field.\nInvalid JSON payload received. Unknown name \"content\" at 'contents[2]': Cannot find field.\nInvalid JSON payload received. Unknown name \"content\" at 'contents[3]': Cannot find field.\nInvalid JSON payload received. Unknown name \"content\" at 'contents[4]': Cannot find field.\nInvalid JSON payload received. Unknown name \"content\" at 'contents[5]': Cannot find field.","status":"INVALID_ARGUMENT","details":[{"@type":"type.googleapis.com/google.rpc.BadRequest","fieldViolations":[{"field":"contents[0]","description":"Invalid JSON payload received. Unknown name \"content\" at 'contents[0]': Cannot find field."},{"field":"contents[1]","description":"Invalid JSON payload received. Unknown name \"content\" at 'contents[1]': Cannot find field."},{"field":"contents[2]","description":"Invalid JSON payload received. Unknown name \"content\" at 'contents[2]': Cannot find field."},{"field":"contents[3]","description":"Invalid JSON payload received. Unknown name \"content\" at 'contents[3]': Cannot find field."},{"field":"contents[4]","description":"Invalid JSON payload received. Unknown name \"content\" at 'contents[4]': Cannot find field."},{"field":"contents[5]","description":"Invalid JSON payload received. Unknown name \"content\" at 'contents[5]': Cannot find field."}]}]}}

@mldangelo there’s some differences between my config and yours:

prompts: [prompts.yaml]

providers:
  - id: openai:gpt-4o-mini
    config:
      temperature: 0
      max_tokens: 4096
   - id: google:gemini-1.5-flash-latest
    config:
      temperature: 0
      max_tokens: 4096

tests: [tests.csv]

and prompts.yaml

- role: system
  content: |
    my sys prompt
- role: user
  content: |
    {{ input | dump }}

The OpenAI provider is working fine with this setup. Gemini returns:

API did not return any candidate responses: {"error":{"code":400,"message":"Invalid JSON payload received. Unknown name \"content\" at 'contents[0]': Cannot find field.\nInvalid JSON payload received. Unknown name \"content\" at 'contents[1]': Cannot find field.","status":"INVALID_ARGUMENT","details":[{"@type":"type.googleapis.com/google.rpc.BadRequest","fieldViolations":[{"field":"contents[0]","description":"Invalid JSON payload received. Unknown name \"content\" at 'contents[0]': Cannot find field."},{"field":"contents[1]","description":"Invalid JSON payload received. Unknown name \"content\" at 'contents[1]': Cannot find field."}]}]}}