Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 29, 2025

Migration from deprecated packages to current ones

This PR migrates from deprecated packages to their current replacements:

  • gemini-1.5-flashgemini-2.5-flash
  • @google/generative-ai@google/genai

Migration Plan

  • Analyze current codebase and understand the deprecated API usage
  • Research the new @google/genai package API structure
  • Update package.json to replace @google/generative-ai with @google/genai
  • Update the main gemini.ts file to use the new API:
    • Change import from @google/generative-ai to @google/genai
    • Replace GoogleGenerativeAI with GoogleGenAI
    • Update the API usage from genAI.getGenerativeModel() to ai.models.generateContent()
    • Update model name from gemini-1.5-flash to gemini-2.5-flash
    • Update proxy fallback to use httpOptions.baseUrl
  • Update files consuming the gemini API:
    • Fix response handling in app/actions/chatActions.ts (from result.response.text() to result.text)
    • Fix response handling in app/actions/questionExample.ts (from result.response.text() to result.text)
    • Add proper null checks for the text response
  • Extract model and contents parameters into reusable params variable for better maintainability
  • Verify that all files importing from gemini.ts continue to work
  • Test the changes to ensure functionality is preserved
  • Run linting and type checking to ensure no compilation errors
  • Test build process to ensure everything compiles correctly

Files modified:

  • package.json - Updated dependency from @google/generative-ai to @google/genai
  • app/actions/gemini.ts - Complete API migration to new package with extracted parameters
  • app/actions/questionExample.ts - Updated response handling for new API
  • app/actions/chatActions.ts - Updated response handling for new API

Key changes:

  1. Package upgrade: Moved from deprecated @google/generative-ai v0.24.1 to current @google/genai v1.21.0
  2. Model upgrade: Updated from gemini-1.5-flash to gemini-2.5-flash
  3. API structure change:
    • Old: new GoogleGenerativeAI().getGenerativeModel().generateContent()
    • New: new GoogleGenAI().models.generateContent()
  4. Response handling:
    • Old: result.response.text()
    • New: result.text (with proper null checks)
  5. Proxy configuration: Updated to use httpOptions.baseUrl for the proxy fallback
  6. Parameter extraction: Extracted model and contents into a reusable params variable, similar to the original ModelParams pattern, making it easier to modify parameters and reducing code duplication

All TypeScript compilation, linting, and build processes pass successfully.

Original prompt

This section details on the original issue you should resolve

<issue_title>gemini-1.5-flashと@google/generative-aiはdeprecated</issue_title>
<issue_description>gemini-1.5-flash → gemini-2.5-flashに、
@google/generative-ai → @google/genai に移行する必要がある。</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #39

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Sep 29, 2025

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
my-code dc02868 Commit Preview URL

Branch Preview URL
Sep 29 2025, 08:00 AM

Copilot AI changed the title [WIP] gemini-1.5-flashと@google/generative-aiはdeprecated Migrate from deprecated gemini-1.5-flash and @google/generative-ai to current packages Sep 29, 2025
Copilot AI requested a review from na-trium-144 September 29, 2025 07:46
Copilot AI requested a review from na-trium-144 September 29, 2025 07:59
@na-trium-144 na-trium-144 marked this pull request as ready for review September 29, 2025 08:00
@na-trium-144 na-trium-144 merged commit 8fa5c64 into main Sep 29, 2025
5 checks passed
@na-trium-144 na-trium-144 deleted the copilot/fix-43024d18-e3cd-4db1-84f6-82adfcff23f6 branch September 29, 2025 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gemini-1.5-flashと@google/generative-aiはdeprecated

2 participants