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.62k stars 322 forks source link

Quickstart script is not working as expected #604

Closed codewithnick closed 1 month ago

codewithnick commented 1 month ago

Description of the bug:

I am following the quickstart script to generate content

import os
import google.generativeai as genai
import dotenv
dotenv.load_dotenv()
GEMINI_API_KEY = os.getenv('GEMINI_API_KEY')
#print(GEMINI_API_KEY)
genai.configure(api_key=GEMINI_API_KEY)
model = genai.GenerativeModel("gemini-1.5-flash")
response = model.generate_content("Write a story about a magic backpack.")
print(response.text)

Actual vs expected behavior:

Actual behaviour :

image

nothing is being printed, no error nothing, gemini has got stuck i have no idea how to debug this

Expected behavior: response must be printed

Any other information you'd like to share?

GEMINI_API_KEY is corrrect and new , even tried printing it and it prints correctly python version: 3.12.6 OS: mac

manojssmk commented 1 month ago

Hi @codewithnick

I ran the same code with the same versions in VS Code, and it worked fine. The output may take time since there's an API call involved. Have you tried running it in Google Colab?

Thanks

codewithnick commented 1 month ago

I tried making a postman request with the same api key and it worked,probably something is wrong with the python module , the biggest problem is i don't know how to debug this ,there is no response no error at all it just gets stuck.

manojssmk commented 1 month ago

Can you try downgrading or rolling back to python <= 3.11.x.

codewithnick commented 1 month ago

tried that, same problem

codewithnick commented 1 month ago

ok i fixed that after some trail and error , looks like my venv and python version were different i reinstalled and resetup everything