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

Grounding Web with Gemini Flash 2.0 - google_search field instead of google_search_retrieval #2914

Closed
fatihyildizhan opened this issue Feb 8, 2025 · 3 comments
Assignees
Labels
samples Issues that are directly related to samples.

Comments

@fatihyildizhan
Copy link

Hello,

I get the following error in the grounding web sample with Gemini Flash 2.0. How can I make this request with C# .Net 8?
Thank you for your time.

Error message:
Status(StatusCode="InvalidArgument", Detail="Unable to submit request because Please use google_search field instead of google_search_retrieval field.. Learn more: https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/gemini")

Sample:
https://github.com/GoogleCloudPlatform/dotnet-docs-samples/blob/main/aiplatform/api/AIPlatform.Samples/GroundingWebSample.cs#L57

var generateContentRequest = new GenerateContentRequest
{
    Model = $"projects/{projectId}/locations/{location}/publishers/{publisher}/models/{model}",
    GenerationConfig = new GenerationConfig
    {
        Temperature = 0.0f
    },
    Contents =
    {
        new Content
        {
            Role = "USER",
            Parts = { new Part { Text = "When is the next total solar eclipse in US?" } }
        }
    },
    Tools =
    {
        new Tool
        {
            GoogleSearchRetrieval = new GoogleSearchRetrieval()
        }
    }
};
@product-auto-label product-auto-label bot added the samples Issues that are directly related to samples. label Feb 8, 2025
@jskeet jskeet assigned meteatamel and unassigned jskeet Feb 10, 2025
@Creatur3245
Copy link

Possible resolution for issue #2914

The error message indicates that the google_search_retrieval field is deprecated and should be replaced with the google_search field when using Gemini Flash 2.0. The provided code snippet from GroundingWebSample.cs uses GoogleSearchRetrieval.

Here's a plan to address this:

  1. Inspect the GroundingWebSample.cs file: I'll retrieve the file content to confirm the usage of GoogleSearchRetrieval.
  2. Identify the correct field: Based on the error message and the Gemini documentation, the GoogleSearchRetrieval field should be replaced with GoogleSearch.
  3. Provide a corrected code snippet: I'll modify the code snippet to use the GoogleSearch field instead of GoogleSearchRetrieval.

Now, let's execute the plan.

Step 1: Retrieve the file content
The error message "Please use google_search field instead of google_search_retrieval field" indicates that the GoogleSearchRetrieval tool is outdated for Gemini Flash 2.0. You need to use the google_search field instead.

Here's how to modify the C# code:

var generateContentRequest = new GenerateContentRequest
{
    Model = $"projects/{projectId}/locations/{location}/publishers/{publisher}/models/{model}",
    GenerationConfig = new GenerationConfig
    {
        Temperature = 0.0f
    },
    Contents =
    {
        new Content
        {
            Role = "USER",
            Parts = { new Part { Text = "When is the next total solar eclipse in US?" } }
        }
    },
    Tools =
    {
        new Tool
        {
            GoogleSearch = new GoogleSearch() // Changed GoogleSearchRetrieval to GoogleSearch
        }
    }
};

Reasoning:

The error message clearly states that the google_search_retrieval field should be replaced with google_search. Looking at the provided code snippet from the issue and the file content, the GoogleSearchRetrieval class is being used. Therefore, the GoogleSearchRetrieval should be replaced with GoogleSearch to align with the API requirements for Gemini Flash 2.0.

@meteatamel
Copy link
Contributor

Sorry for the late response @fatihyildizhan but I just sent a pull request to show what to change

@meteatamel
Copy link
Contributor

I'll close this now. PR should be merged soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
samples Issues that are directly related to samples.
Projects
None yet
Development

No branches or pull requests

4 participants