Reputation: 21
I have checked my quota limits on GCP but it did't exceed
below is a code
sample_file = genai.upload_file(path=image_path,display_name=image_path)
print(f"Uploaded file '{sample_file.display_name}' as: {sample_file.uri}")
model = genai.GenerativeModel(model_name="models/gemini-1.5-pro-latest")
response = model.generate_content(["Generate the tags for the given image. Provide all the information in JSON format.", sample_file])
I tried to check the GCP
Upvotes: 1
Views: 1340
Reputation: 116948
The most common cause for that is not properly configuring your model. If you don't add an api key you will get that error every time.
from dotenv import load_dotenv
import google.generativeai as genai
import os
load_dotenv()
print(os.getenv("API_KEY"))
genai.configure(api_key=os.getenv("API_KEY"))
model = genai.GenerativeModel('gemini-1.5-pro-latest')
response = model.generate_content("What is the meaning of life in two sentences")
print(response.text)
If you get it from time to time its normally due to the fact that the servers are overloaded. this can often be solved by adding retry.
from dotenv import load_dotenv
import google.generativeai as genai
from google.generativeai.types import RequestOptions
from google.api_core import retry
import os
load_dotenv()
print(os.getenv("API_KEY"))
genai.configure(api_key=os.getenv("API_KEY"))
model = genai.GenerativeModel('gemini-1.5-pro-latest')
response = model.generate_content("What is the meaning of life in two sentences",
request_options=RequestOptions(retry=retry.Retry(initial=10, multiplier=2, maximum=60, timeout=300)))
print(response.text)
If it still doesnt work then i would guess its your prompt try asking for help on the discord server.
Upvotes: 1