google-genai / Gemini 2.0 的 Python 调用,实在是太简洁了

image-20241230080515243

1
pip install google-genai

然后:

1
2
3
4
5
6
from google import genai

client = genai.Client(api_key="GEMINI_API_KEY")

response = client.models.generate_content(model='gemini-2.0-flash-exp', contents='How does AI work?')
print(response.text)

https://ai.google.dev/gemini-api/docs/models/gemini-v2

目前用起来还是免费的。