Skip to content

♻️ refactor(google-genai): migrate from @google/generative-ai to @google/genai #7954

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

kingsword09
Copy link
Contributor

💻 变更类型 | Change Type

  • ✨ feat
  • 🐛 fix
  • ♻️ refactor
  • 💄 style
  • 👷 build
  • ⚡️ perf
  • 📝 docs
  • 🔨 chore

🔀 变更说明 | Description of Change

Update the codebase to use the new @google/genai package, replacing @google/generative-ai and @google-cloud/vertexai.
closes: #7735

📝 补充信息 | Additional Information

Copy link

vercel bot commented May 24, 2025

@kingsword09 is attempting to deploy a commit to the LobeHub Team on Vercel.

A member of the Team first needs to authorize it.

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label May 24, 2025
@lobehubbot
Copy link
Member

👍 @kingsword09

Thank you for raising your pull request and contributing to our Community
Please make sure you have followed our contributing guidelines. We will review it as soon as possible.
If you encounter any problems, please feel free to connect with us.
非常感谢您提出拉取请求并为我们的社区做出贡献,请确保您已经遵循了我们的贡献指南,我们会尽快审查它。
如果您遇到任何问题,请随时与我们联系。

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

This PR migrates LobeChat's Google AI integration from deprecated packages to the new @google/genai SDK, ensuring compatibility with Gemini 2.0 and Vertex AI express mode before the August 2025 deprecation deadline.

  • Updated package.json to replace @google/generative-ai and @google-cloud/vertexai with @google/[email protected]
  • Modified stream handling in src/libs/model-runtime/utils/streams/google-ai.ts to use direct property access instead of method calls
  • Updated error handling and type definitions in src/libs/model-runtime/google/index.ts to match new SDK structure
  • Added support for Vertex AI express mode with apiKey-based authentication in src/libs/model-runtime/vertexai/index.ts
  • Enhanced test coverage in google-ai.test.ts and index.test.ts to verify compatibility with new API structure

💡 (3/5) Reply to the bot's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!

7 file(s) reviewed, 4 comment(s)
Edit PR Review Bot Settings | Greptile

try {
const client = new VertexAI({ ...params });
const client = new GoogleGenAI({ ...params });

return new LobeGoogleAI({ apiKey: 'avoid-error', client, isVertexAi: true });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider removing hardcoded 'avoid-error' API key and use a more descriptive placeholder or handle this differently

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this should be changed.

Copy link

codecov bot commented May 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.67%. Comparing base (fca25e1) to head (4a18810).
Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7954      +/-   ##
==========================================
+ Coverage   88.47%   95.67%   +7.20%     
==========================================
  Files         821       14     -807     
  Lines       60274     2519   -57755     
  Branches     3806      444    -3362     
==========================================
- Hits        53325     2410   -50915     
+ Misses       6949      109    -6840     
Flag Coverage Δ
app ?
server 95.67% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sxjeru
Copy link
Contributor

sxjeru commented May 25, 2025

@kingsword09
Copy link
Contributor Author

@kingsword09 kingsword09 marked this pull request as draft May 25, 2025 06:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Request] 迁移至 Google Gen AI SDK
3 participants