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

the [get_code] button in aistudio.google.com provide a code that doesn't run when grounding is switched on #658

Closed
hitchhiker3010 opened this issue Dec 26, 2024 · 5 comments
Assignees
Labels
component:python sdk Issue/PR related to Python SDK status:awaiting user response Awaiting a response from the author status:duplicate This Issue/PR already exists

Comments

@hitchhiker3010
Copy link

Description of the bug:

When I switch on the grounding
image

"""
Install an additional SDK for JSON schema support Google AI Python SDK

$ pip install google.ai.generativelanguage
"""

import os
import time
import google.generativeai as genai
from google.ai.generativelanguage_v1beta.types import content

genai.configure(api_key=os.environ["GEMINI_API_KEY"])

# Create the model
generation_config = {
  "temperature": 1,
  "top_p": 0.95,
  "top_k": 40,
  "max_output_tokens": 8192,
  "response_mime_type": "text/plain",
}

model = genai.GenerativeModel(
  model_name="gemini-2.0-flash-exp",
  generation_config=generation_config,
  system_instruction="You're an expert video parser and extracts the places mentioned in the given videos. You're very helpful and harmless.",
  tools = [
    genai.protos.Tool(
      google_search = genai.protos.Tool.GoogleSearch(),
    ),
  ],
)

Below is the error message I'm receiving

image

I've installed google-generativeai==0.8.3

I'm using grounding with video input, please help.

Actual vs expected behavior:

I'm using grounding with video input.
While that's running on the ai studio website, the code given in "Get Code" section doesn't work.

Any other information you'd like to share?

No response

@Gunand3043 Gunand3043 added status:duplicate This Issue/PR already exists component:python sdk Issue/PR related to Python SDK labels Dec 26, 2024
@Gunand3043
Copy link

Hi @hitchhiker3010, We already have similar issue on this #650

For time being, you can try replacing the code below to make grounding work.

model = genai.GenerativeModel(
  model_name="models/gemini-1.5-pro",
  generation_config=generation_config,
  tools="google_search_retrieval"
)

Thanks

@Gunand3043 Gunand3043 added the status:awaiting user response Awaiting a response from the author label Dec 26, 2024
@hitchhiker3010
Copy link
Author

Thank you @Gunand3043 for the reply. Can you please help me with the correct code to get the desired output.
Have gone through the documentation and tried implementing, but I'm getting the following error

InvalidArgument: 400 Search Grounding is supported only for text-only requests

@Gunand3043 Gunand3043 self-assigned this Jan 1, 2025
@Gunand3043 Gunand3043 removed the status:awaiting user response Awaiting a response from the author label Jan 1, 2025
@Gunand3043
Copy link

Alright, to use grounding with multimedia input, you need to use the new Google Gen AI SDK. You can also go through our quick-start cookbook.

I have prepared a sample notebook on how to use grounding with multimedia input. Please have a look.

Thanks.

@Gunand3043 Gunand3043 added the status:awaiting user response Awaiting a response from the author label Jan 1, 2025
@hitchhiker3010
Copy link
Author

hitchhiker3010 commented Jan 1, 2025

Thanks a lot @Gunand3043. The attached notebook was helpful but I was looking for search grounding [which was possible with video in ai studio] as well, I tried using google_search_retrieval tool which gave me the following error ClientError: 400 INVALID_ARGUMENT. {'error': {'code': 400, 'message': 'Search Grounding is supported only for text-only requests.', 'status': 'INVALID_ARGUMENT'}}.

@Gunand3043 Gunand3043 removed the status:awaiting user response Awaiting a response from the author label Jan 3, 2025
@Gunand3043
Copy link

Hi @hitchhiker3010 ,
The code returned by AI Studio uses the Gemini API SDK, which, according to the documentation, does not support multimodal (text-and-image, text-and-audio, etc.) prompts with grounding enabled. The team is already working on fixing the issue.

@Gunand3043 Gunand3043 added the status:awaiting user response Awaiting a response from the author label Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:python sdk Issue/PR related to Python SDK status:awaiting user response Awaiting a response from the author status:duplicate This Issue/PR already exists
Projects
None yet
Development

No branches or pull requests

2 participants