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)
LindaLawton commented 8 months ago

First you need to be white listed for Google Gemini-1.5-pro If you are then you should know that Google Gemini-1.5-pro doesn't work though the Gemini api which is what this library is for.

I have heard that the api works via Google Gemini-1.5-pro going though vertex but you have to be whitelisted for that as well. I have only heard it exits I don't know anyone who managed to got into that whitelist. I haven't even heard of way of applying.

haseeb-heaven commented 8 months ago

First you need to be white listed for Google Gemini-1.5-pro If you are then you should know that Google Gemini-1.5-pro doesnt work though the gemini api which is what this library is for.

If you do have access and really want to try Google Gemini-1.5-pro try going though vertex and use the vertex library i hear it works there.

But still in vertex-ai Gemini 1.5 pro is not available via API?

LindaLawton commented 8 months ago

@haseeb-heaven That's a completely different white list. I have only heard that it exits i don't know anyone that got access to that yet. Its not the same as the white list to access it in Google Ai Studio.

Im not even sure how to get on the Vertex ai whitelist for gemini pro 1.5

You need to test via ai studio.

SeanTolstoyevski commented 8 months ago

I can see version 1.5 in ai studio, I can selected this version. And when I examine the network panel after the prompt sending and receive response, requests are sent to google services with the 1.5 version parameter. However, when I try to access the 1.5 version via the API, I get 404, which is the error our friend received.

I think even though we are whitelisted, this does not mean that we can access the API.

haseeb-heaven commented 8 months ago

@haseeb-heaven That's a completely different white list. I have only heard that it exits i don't know anyone that got access to that yet. Its not the same as the white list to access it in Google Ai Studio.

Im not even sure how to get on the Vertex ai whitelist for gemini pro 1.5

You need to test via ai studio.

Okay i will test via Vertex AI API but i prefer Google AI Studio API because it need only single API key for authorization.

LindaLawton commented 8 months ago

@SeanTolstoyevski I think you need to reread what you are white Listed for

There is NO api currently for Gemini pro 1.5 the white list only gives you access to test in Google ai studio they haven't implemented an API for it they just gave us ai studio testing

flexchar commented 8 months ago

I've got whitelisted on AI Studio too. Shame it's blocked in Denmark (or whole EU in that regard). If someone reverse-engineers, it feels like GPT-5 for some tasks and I am excited to integrate.

@LindaLawton do you have any idea where to find application/form for use in VertexAI?

LindaLawton commented 8 months ago

I have been using it from Denmark since it first came out via AI Studio start your favorite VPN and your all set. VeePN if you don't want to pay for it has a chrome extension that works. I used that before I grabbed PureVPN.

No i don't know of any one with access or I suspect its only company's directly associated with Google already. I am a GDE and they wont give me access either.

OlegRuban-ai commented 8 months ago

I have access to 1.5 in AIStudio, but there is no API access in version 0.4.1. Does anyone know when they plan to add it? The following packages are currently available:

models/chat-bison-001 models/text-bison-001 models/embedding-gecko-001 models/gemini-1.0-pro models/gemini-1.0-pro-001 models/gemini-1.0-pro-latest models/gemini-1.0-pro-vision-latest models/gemini-pro models/gemini-pro-vision models/embedding-001 models/aqa

LindaLawton commented 8 months ago

I got access today it's comming.

Arkm20 commented 8 months ago

Same here

davidogbonnaeze commented 8 months ago

@LindaLawton @Arkm20 , please how did you get access. i need it

LindaLawton commented 8 months ago

Im a google developer expert for ai/ml some on at google sent me a hangout message and asked for the project i wanted white listed. If GDE's are getting access its only a matter of time before the others white listed for 1.5 on ai studio get access hang in there.

Heads up the model name is gemini-1.5-pro-latest when you get access.

Any code you are using for gemini-pro will work for 1.5 as well. from what i can see

davidogbonnaeze commented 8 months ago

Thank you @LindaLawton

manbeardave commented 8 months ago

@LindaLawton are you leveraging pro-1.5 in the python SDK? or in the console?

LindaLawton commented 8 months ago

Im using this library to work with Gemini pro 1.5 the code is the same its just a different model. You use gemini-1.5-pro-latest instead of gemini-pro and your good to go.

you need to be whitelisted.

haseeb-heaven commented 8 months ago

Im using this library to work with Gemini pro 1.5 the code is the same its just a different model. You use gemini-1.5-pro-latest instead of gemini-pro and your good to go.

you need to be whitelisted.

But how to get whitelisted please explain that in details thanks

LindaLawton commented 8 months ago

If you are white Listed for ai studio you will get in eventually

If you're not you need to apply to be white Listed

In both cases you just wait

haseeb-heaven commented 8 months ago

If you are white Listed for ai studio you will get in eventually

If you're not you need to apply to be white Listed

In both cases you just wait

I tried to list all the models available and i got this list.

def list_all_models():
    try:
        models = genai.list_models()
        for model in models:
            print(f"Name: {model.name}, Display Name: {model.display_name}")
    except Exception as exception:
        print("Error listing models:", exception)

Output:

Name: models/chat-bison-001, Display Name: PaLM 2 Chat (Legacy)
Name: models/text-bison-001, Display Name: PaLM 2 (Legacy)
Name: models/embedding-gecko-001, Display Name: Embedding Gecko
Name: models/gemini-1.0-pro, Display Name: Gemini 1.0 Pro
Name: models/gemini-1.0-pro-001, Display Name: Gemini 1.0 Pro 001 (Tuning)
Name: models/gemini-1.0-pro-latest, Display Name: Gemini 1.0 Pro Latest
Name: models/gemini-1.0-pro-vision-latest, Display Name: Gemini 1.0 Pro Vision
Name: models/gemini-pro, Display Name: Gemini 1.0 Pro
Name: models/gemini-pro-vision, Display Name: Gemini 1.0 Pro Vision
Name: models/embedding-001, Display Name: Embedding 001
Name: models/aqa, Display Name: Model that performs Attributed Question Answering.
Name: models/chat-bison-001, Display Name: PaLM 2 Chat (Legacy)
Name: models/text-bison-001, Display Name: PaLM 2 (Legacy)
Name: models/embedding-gecko-001, Display Name: Embedding Gecko
Name: models/gemini-1.0-pro, Display Name: Gemini 1.0 Pro
Name: models/gemini-1.0-pro-001, Display Name: Gemini 1.0 Pro 001 (Tuning)
Name: models/gemini-1.0-pro-latest, Display Name: Gemini 1.0 Pro Latest
Name: models/gemini-1.0-pro-vision-latest, Display Name: Gemini 1.0 Pro Vision
Name: models/gemini-pro, Display Name: Gemini 1.0 Pro
Name: models/gemini-pro-vision, Display Name: Gemini 1.0 Pro Vision
Name: models/embedding-001, Display Name: Embedding 001
Name: models/aqa, Display Name: Model that performs Attributed Question Answering.

My Google generativeai version:

pip show google-generativeai
Name: google-generativeai
Version: 0.4.1

See the gemini-1.5-pro-latest isn't even listed.

LindaLawton commented 8 months ago

It will be when they give you access I had to have my project whitelist

danh-conduit commented 8 months ago

I too get the same result (404) and the same (non-1.5) list of models as everyone else except @LindaLawton, using google-generativeai v 0.4.1. I have AI Studio 1.5 access via both a personal account and a Google Workspace account. I generated API keys from both those accounts but neither of them yields gemini-1.5-pro-latest. Google, please show us the love 🙏

LindaLawton commented 8 months ago

I can not you must wait to be white Listed to the API it's comming they are releasing it slowly

MarkDaoust commented 8 months ago

It looks like they've removed the whitelist and opened up access to 1.5 in AI Studio. Hopefully that means it will be accessible in the API soon.

haseeb-heaven commented 8 months ago

It looks like they've removed the whitelist and opened up access to 1.5 in AI Studio. Hopefully that means it will be accessible in the API soon.

Yes i saw Twitter post about this hopefully we will get the API access soon.

davidogbonnaeze commented 8 months ago

https://twitter.com/JeffDean/status/1770653917543870571

SomebodySysop commented 8 months ago

Any idea if the pricing for Gemini Pro 1.5 will be the same as 1.0?

https://ai.google.dev/pricing

shuimu5418 commented 8 months ago

Gemini 1.5 pro api is avaliable now.

LET19 commented 8 months ago

Gemini 1.5 pro api is avaliable now.

sry friend, how do you get it? I checked my google dev studio, its "code" button still unavailable. and it's not listed in model list api either. image

shuimu5418 commented 8 months ago

Gemini 1.5 pro api is avaliable now.

sry friend, how do you get it? I checked my google dev studio, its "code" button still unavailable. and it's not listed in model list api either. image

i got an email....

[Preview] Gemini API Access External
Hello,
We're thrilled to announce that we’ve started rolling out access to the Gemini 1.5 Pro API! This lets you bring the power of Gemini 1.5 Pro beyond Google AI Studio.

so i got it.

LET19 commented 8 months ago

Gemini 1.5 pro api is avaliable now.

sry friend, how do you get it? I checked my google dev studio, its "code" button still unavailable. and it's not listed in model list api either. image

i got an email....

[Preview] Gemini API Access External
Hello,
We're thrilled to announce that we’ve started rolling out access to the Gemini 1.5 Pro API! This lets you bring the power of Gemini 1.5 Pro beyond Google AI Studio.

so i got it.

ok. thx. maybe what I can do is just waiting.

formvoltron commented 8 months ago

so i got it.

Did you need to ask for it? Or are they just handing it out to everyone on the gemini 1.5 early access list? Thanks!

ReEnMikki commented 8 months ago

I am also curious how to ask or apply to get access to Gemini 1.5 Pro API. I have already sent the application to get early access to it weeks ago, but they never responded. Anyone who knows please help!

LET19 commented 8 months ago

i got access through mail but getting error in trying to access image

did u tried with created a new key?

ReEnMikki commented 8 months ago

i got access through mail but getting error in trying to access image

So how did you get access to begin with ? Is it because you already had access to Gemini 1.5 Pro waitlist before they removed the waitlist ? Is it because you have a Google Workspace account ?

ReEnMikki commented 8 months ago

Searching through internet I only saw some pages or some people saying Google rolled out Gemini 1.5 Pro API to "some developers", but regarding how is this process decided, like how do they decide who to give access to - no one said anything to clarify. Wtf.

LindaLawton commented 8 months ago

Most of these questions are out of scope for this library I recommend you join discord channel gemini-api You can get help there from other developers

goodanthony commented 8 months ago

Hope this helps

Firstly Google would send you an invite to join. Then fill that form and you have to specify your project id. Make sure you remember the project id!

First email from Google Hello, We're thrilled to announce that we've started rolling out access to the Gemini 1.5 Pro API! This lets you bring the power of Gemini 1.5 Pro beyond Google AI Studio. How to request access: Submit one Google Cloud Project Number (digits only) using this form. We'll email you if access is enabled for your project. Gemini 1.5 Pro:

Fill form

Reply from Google: Hello, We're excited to share that you now have access to the Gemini 1.5 Pro API and the File API! Your feedback on this highly-requested preview feature is incredibly valuable. Please share your thoughts and any projects you build! Instructions:

Go to https://aistudio.google.com and create a new key with the "Project ID" that you filled in the form (I had to create a new key. If you already have a key with that project ID, I assume it would work).

Then run the following command:

curl \ -H 'Content-Type: application/json' \ -d '{"contents":[{"parts":[{"text":"Write a story about Wikipedia"}]}]}' \ -X POST 'https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro-latest:generateContent?key=yourkey

The mistake I made was using a key from a different project.

haseeb-heaven commented 8 months ago

Thanks all for confirming i am yet to receive my API key from Google once i receive i will update this issue.

Arkm20 commented 8 months ago

I already filled out the form, but it's been some days now... I still haven't got the email regarding the Api access confirmation

jyx-su commented 8 months ago

@goodanthony @Arkm20 @haseeb-heaven Would you mind sharing the link to the form? Thanks.

Arkm20 commented 7 months ago

So it looks like the Gemini 1.5 rates isn't the same... Sad...

Rate limit 2 queries per minute, 1000 queries per day

according to Official Gemini Docs

Arkm20 commented 7 months ago

@goodanthony I still haven't recieved that reply...

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

jsomeara 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

¯\_(ツ)_/¯

goodanthony commented 7 months ago

@johnomeara1, try creating a new key at https://aistudio.google.com/ with the "Project ID" that you are calling the API.

jsomeara commented 7 months ago

Thanks for the tip!

Here's what ended up working for me:

const model = genAI.getGenerativeModel({ model: "gemini-1.5-pro-latest" }, {
    apiVersion: 'v1beta',
});

The key is using API version v1beta, as that is the only version that supports the gemini-1.5-pro-latest model at this time. Although the above code is for the javascript client library, it can be modified for various languages of google's client for generative AI (python, etc.)

zakcali commented 7 months ago

I wish to code for golang. any chance to modifiy that code: model := client.GenerativeModel("Gemini 1.5 Pro") there are no curly bracets in golang version

LindaLawton commented 7 months ago

@zakcali your in the wrong forum this is for the python client library you should head over to generative-ai-go for help with golang

ewantindale commented 7 months ago

Thanks for the tip!

Here's what ended up working for me:

const model = genAI.getGenerativeModel({ model: "gemini-1.5-pro-latest" }, {
    apiVersion: 'v1beta',
});

The key is using API version v1beta, as that is the only version that supports the gemini-1.5-pro-latest model at this time. Although the above code is for the javascript client library, it can be modified for various languages of google's client for generative AI (python, etc.)

Thanks, spent ages debugging this before I found your post. Was this communicated anywhere or were we just supposed to figure it out on our own?

Arkm20 commented 7 months ago

It works fine for me just without the {apiversion}