RLD
RLD

Reputation: 2005

What is the Python code to check all the GenerativeAI models supported by Google Gemini?

Being new to GenerativeAI world, I am trying to load a pre-trained text generation model and doing some stuff which is not working. This is how I load the GenerativeAI model.

from vertexai.generative_models import GenerativeModel
generation_model = GenerativeModel("gemini-pro")

Since it does not work, I feel I might have to use some other GenerativeAI model, not "gemini-pro". Even I try following piece of code to check all the models supported by Gemini.

import google.generativeai as genai
for model in genai.list_models():
    if 'generateContent' in model.supported_generation_methods:
        print(model.name)

But I get 'PermissionDenied' error as attached image shows. enter image description here

Now as a programmer I have 2 queries here.

Q1. Can I see the GenerativeAI models supported by Gemini or not?

Q2. If answer is 'Yes', what is the Python code?

Upvotes: 1

Views: 579

Answers (2)

sam
sam

Reputation: 1896

Upvotes: 0

Linda Lawton - DaImTo
Linda Lawton - DaImTo

Reputation: 117186

List models sample for AI studio Gemini. Did you forget the configure?

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

load_dotenv()
genai.configure(api_key=os.getenv("API_KEY"))
genai.configure(transport='grpc')

def list_models():
    for i, m in zip(range(5), genai.list_models()):
        print(f"Name: {m.name} Description: {m.description} support: {m.supported_generation_methods}")

if __name__ == "__main__":
    list_models()

Upvotes: 1

Related Questions