google-gemini / generative-ai-python

The official Python library for the Google Gemini API
https://pypi.org/project/google-generativeai/
Apache License 2.0
1.66k stars 333 forks source link

Google Gemini 1.5 pro via API access #227

Closed haseeb-heaven closed 7 months ago

haseeb-heaven commented 9 months ago

Description of the feature request:

I want to use latest version of Google Gemini-1.5-pro via API or SDK that can be integrated to our projects.

What problem are you trying to solve with this feature?

Solving the whole codebase upload media and more with 1 Million tokens limit to achieve maximum efficiency from this model.

Any other information you'd like to share?

Here is error i got

Error generating response: 404 models/gemini-1.5-pro-latest is not found for API version v1beta, or is not supported for GenerateContent. Call ListModels to see the list of available models and their supported methods.

Here is the code:

import os
import google.generativeai as genai
from dotenv import load_dotenv

def init_api_keys():
    try:
        load_dotenv()
        api_key = os.getenv("GEMINI_API_KEY")
        genai.configure(api_key=api_key)
    except Exception as exception:
        print("Error in initializing API keys:", exception)
        raise

def generate_response(prompt:str):

  # Set up the model
  generation_config = {
    "temperature": 0.1,
    "top_p": 1,
    "top_k": 1,
    "max_output_tokens": 2048,
  }

  model = genai.GenerativeModel(model_name="gemini-1.5-pro-latest",generation_config=generation_config)

  prompt_parts = [prompt]

  try:
    response = model.generate_content(prompt_parts)
    print(response.text)
  except Exception as exception:
    print("Error generating response:", exception)

if __name__ == "__main__":
    init_api_keys()
    prompt = input("> ")
    generate_response(prompt)
haseeb-heaven commented 7 months ago

The API for Google Gen AI 1.5 is now available. https://developers.googleblog.com/2024/04/gemini-15-pro-in-public-preview-with-new-features.html?m=1

Still not working for me... unless I am doing something wrong?

GoogleGenerativeAIError: [404 Not Found] models/gemini-1.5-pro-latest is not found for API version v1, or is not supported for GenerateContent. Call ListModels to see the list of available models and their supported methods.

The code that generated the above error works perfectly fine with the model code gemini-pro, but not with gemini-1.5-pro-latest

¯_(ツ)_/¯

Create new API again and select the project which has access of Gemini 1.5 pro, it’s working for me i created new API key.

Arkm20 commented 7 months ago

All projects have access now to Gemini 1.5 pro.... It's now on Public access.

But I do find the rates to be very annoying. Only 2 requests per minute...

haseeb-heaven commented 7 months ago

All projects have access now to Gemini 1.5 pro.... It's now on Public access.

But I do find the rates to be very annoying. Only 2 requests per minute...

Wait 2 requests per minute is way too less is there any documentation on API of this Gemini 1.5 pro rate limitations? I know Gemini had 60 RPM

Arkm20 commented 7 months ago

Here: https://ai.google.dev/models/gemini#:~:text=2%20queries%20per%20minute%2C%201000%20queries%20per%20day

xuanxuanzzzii commented 7 months ago

Description of the feature request:

I want to use latest version of Google Gemini-1.5-pro via API or SDK that can be integrated to our projects.

What problem are you trying to solve with this feature?

Solving the whole codebase upload media and more with 1 Million tokens limit to achieve maximum efficiency from this model.

Any other information you'd like to share?

Here is error i got

Error generating response: 404 models/gemini-1.5-pro-latest is not found for API version v1beta, or is not supported for GenerateContent. Call ListModels to see the list of available models and their supported methods.

Here is the code:

import os
import google.generativeai as genai
from dotenv import load_dotenv

def init_api_keys():
    try:
        load_dotenv()
        api_key = os.getenv("GEMINI_API_KEY")
        genai.configure(api_key=api_key)
    except Exception as exception:
        print("Error in initializing API keys:", exception)
        raise

def generate_response(prompt:str):

  # Set up the model
  generation_config = {
    "temperature": 0.1,
    "top_p": 1,
    "top_k": 1,
    "max_output_tokens": 2048,
  }

  model = genai.GenerativeModel(model_name="gemini-1.5-pro-latest",generation_config=generation_config)

  prompt_parts = [prompt]

  try:
    response = model.generate_content(prompt_parts)
    print(response.text)
  except Exception as exception:
    print("Error generating response:", exception)

if __name__ == "__main__":
    init_api_keys()
    prompt = input("> ")
    generate_response(prompt)

hello,do you know how to use this api to get answers for video input

xuanxuanzzzii commented 7 months ago

Description of the feature request:

I want to use latest version of Google Gemini-1.5-pro via API or SDK that can be integrated to our projects.

What problem are you trying to solve with this feature?

Solving the whole codebase upload media and more with 1 Million tokens limit to achieve maximum efficiency from this model.

Any other information you'd like to share?

Here is error i got

Error generating response: 404 models/gemini-1.5-pro-latest is not found for API version v1beta, or is not supported for GenerateContent. Call ListModels to see the list of available models and their supported methods.

Here is the code:

import os
import google.generativeai as genai
from dotenv import load_dotenv

def init_api_keys():
    try:
        load_dotenv()
        api_key = os.getenv("GEMINI_API_KEY")
        genai.configure(api_key=api_key)
    except Exception as exception:
        print("Error in initializing API keys:", exception)
        raise

def generate_response(prompt:str):

  # Set up the model
  generation_config = {
    "temperature": 0.1,
    "top_p": 1,
    "top_k": 1,
    "max_output_tokens": 2048,
  }

  model = genai.GenerativeModel(model_name="gemini-1.5-pro-latest",generation_config=generation_config)

  prompt_parts = [prompt]

  try:
    response = model.generate_content(prompt_parts)
    print(response.text)
  except Exception as exception:
    print("Error generating response:", exception)

if __name__ == "__main__":
    init_api_keys()
    prompt = input("> ")
    generate_response(prompt)

hello,do you know how to use this api to get answers for video input

I use the code and here is the error information: Error generating response: Timeout of 60.0s exceeded, last exception: 503 failed to connect to all addresses; last error: UNKNOWN: ipv4:142.251.42.234:443: Failed to connect to remote host: FD Shutdown

haseeb-heaven commented 7 months ago

Description of the feature request:

I want to use latest version of Google Gemini-1.5-pro via API or SDK that can be integrated to our projects.

What problem are you trying to solve with this feature?

Solving the whole codebase upload media and more with 1 Million tokens limit to achieve maximum efficiency from this model.

Any other information you'd like to share?

Here is error i got

Error generating response: 404 models/gemini-1.5-pro-latest is not found for API version v1beta, or is not supported for GenerateContent. Call ListModels to see the list of available models and their supported methods.

Here is the code:

import os
import google.generativeai as genai
from dotenv import load_dotenv

def init_api_keys():
    try:
        load_dotenv()
        api_key = os.getenv("GEMINI_API_KEY")
        genai.configure(api_key=api_key)
    except Exception as exception:
        print("Error in initializing API keys:", exception)
        raise

def generate_response(prompt:str):

  # Set up the model
  generation_config = {
    "temperature": 0.1,
    "top_p": 1,
    "top_k": 1,
    "max_output_tokens": 2048,
  }

  model = genai.GenerativeModel(model_name="gemini-1.5-pro-latest",generation_config=generation_config)

  prompt_parts = [prompt]

  try:
    response = model.generate_content(prompt_parts)
    print(response.text)
  except Exception as exception:
    print("Error generating response:", exception)

if __name__ == "__main__":
    init_api_keys()
    prompt = input("> ")
    generate_response(prompt)

hello,do you know how to use this api to get answers for video input

I use the code and here is the error information: Error generating response: Timeout of 60.0s exceeded, last exception: 503 failed to connect to all addresses; last error: UNKNOWN: ipv4:142.251.42.234:443: Failed to connect to remote host: FD Shutdown

you need to see the documentation on how to send video objects with your request.

IlayBokobza commented 7 months ago

I have read in this stack-overflow post that you need to change to api version to beta. https://stackoverflow.com/questions/78327178/model-not-found-when-using-gemini-1-5-when-i-have-access-to-1-5

And it seems to be supported by this page on the gemini docs. https://ai.google.dev/gemini-api/docs/api-versions

The problem is that I have no idea how to implement this in code (dart). If any has any idea I would appreciate the help.

ewantindale commented 7 months ago

I have read in this stack-overflow post that you need to change to api version to beta. https://stackoverflow.com/questions/78327178/model-not-found-when-using-gemini-1-5-when-i-have-access-to-1-5

And it seems to be supported by this page on the gemini docs. https://ai.google.dev/gemini-api/docs/api-versions

The problem is that I have no idea how to implement this in code (dart). If any has any idea I would appreciate the help.

I'm not a dart guy but looks like you need to use requestOptions: https://github.com/google-gemini/generative-ai-dart/blob/f3be7bbae79534535ef964e5b0fee5874aef9bdc/samples/dart/bin/function_calling.dart#L42

IlayBokobza commented 7 months ago

I have read in this stack-overflow post that you need to change to api version to beta. https://stackoverflow.com/questions/78327178/model-not-found-when-using-gemini-1-5-when-i-have-access-to-1-5 And it seems to be supported by this page on the gemini docs. https://ai.google.dev/gemini-api/docs/api-versions The problem is that I have no idea how to implement this in code (dart). If any has any idea I would appreciate the help.

I'm not a dart guy but looks like you need to use requestOptions: https://github.com/google-gemini/generative-ai-dart/blob/f3be7bbae79534535ef964e5b0fee5874aef9bdc/samples/dart/bin/function_calling.dart#L42

Thanks man that seems to have done it

markmcd commented 7 months ago

The original question seems to be well & truly answered. I'm going to lock this thread now - for any other Python SDK issues you can file a new issue, for other languages find the relevant SDK in https://github.com/google-gemini and ask there.

For general chat, head on over to discord: https://goo.gle/gemini-discord