Reputation: 2005
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.
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
Reputation: 1896
Setting generation_model = GenerativeModel("gemini-pro")
doesn't mean you're loading an AI model. It only sets internal SDK variables to use Vertex AI - Gen AI model's services.
For the most up-to-date information, I recommend using the google-cloud-aiplatform
package https://pypi.org/project/google-cloud-aiplatform . It's updated frequently, sometimes weekly. You can find helpful examples at https://cloud.google.com/docs/samples and https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/generative_ai.
To learn about the latest Gemini model updates, refer to https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models. Unfortunately, there's no straightforward way to fetch available models using the SDK at this time.
As a workaround, you can check the _GEMINI_STABLE_MODEL_NAMES
variable in the VertexAI Tokenizer feature. Here's the source code link: https://github.com/googleapis/python-aiplatform/blob/819e9ff568798232282e1f6dcf180cff3c788c63/vertexai/tokenization/_tokenizer_loading.py#L38-L42. This is a workaround!
Upvotes: 0
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