gemini-api-quickstart icon indicating copy to clipboard operation
gemini-api-quickstart copied to clipboard

Update to new Google Gen AI SDK and Gemini 2.0 Flash

Open logankilpatrick opened this issue 9 months ago • 0 comments

This commit attempts to update your application to use the new Google Gen AI SDK (google-genai) and the gemini-2.0-flash model.

Here's what I've done so far:

  1. Initial Exploration: I identified app.py and requirements.txt as key files.
  2. Documentation Review: I consulted Google AI documentation to understand the new SDK's API (from google import genai, genai.Client, client.chats.create, send_message_stream, get_history).
  3. Requirements Update (Attempt 1 - Incorrect): I initially updated requirements.txt to use a newer version of google-generativeai (0.7.x), believing it supported the new API. This was incorrect.
  4. app.py Update (Attempt 1 - Failed due to SDK mismatch): I modified app.py to use the new API style. Testing revealed that google-generativeai==0.7.2 does not support the new API style (genai.Client etc.), causing errors or reversions of app.py content.
  5. Critical Correction - SDK Package Name: I discovered that the new SDK is under a different package name: google-genai, not google-generativeai.
  6. Requirements Update (Attempt 2 - Corrected):
    • I removed google-generativeai and google-ai-generativelanguage from requirements.txt.
    • I added google-genai>=1.0.0 to requirements.txt. This step has been completed and verified.

Current Status: I believe the requirements.txt file is now correct, pointing to the new google-genai SDK. My next step was to update app.py again, this time with the correct SDK package installed. I haven't completed this yet due to reaching the turn limit.

Challenges: The primary challenge was the misunderstanding of the SDK package name. The old package google-generativeai does not support the genai.Client API even in its 0.7.x versions. The new API is available under the google-genai package. This led to several cycles where I attempted to update app.py, which failed because the underlying library was incorrect.

Next, I would have applied the planned modifications to app.py and then tested your application.

logankilpatrick avatar May 20 '25 00:05 logankilpatrick