Skip to content

feat: support third-party base URL for Gemini image generation#123

Open
Cn-cpjl wants to merge 4 commits intoop7418:mainfrom
Cn-cpjl:feat/gemini-image-thirdparty-api
Open

feat: support third-party base URL for Gemini image generation#123
Cn-cpjl wants to merge 4 commits intoop7418:mainfrom
Cn-cpjl:feat/gemini-image-thirdparty-api

Conversation

@Cn-cpjl
Copy link

@Cn-cpjl Cn-cpjl commented Feb 28, 2026

Summary

  • image-generator.ts: 从数据库读取 base_url 并传递给 createGoogleGenerativeAI,支持第三方 Gemini 兼容 API 端点用于图片生成,与 text-generator.ts 已有的处理方式保持一致
  • ProviderManager.tsx: 在 Media Providers 区域新增「Gemini Image Third-party API」快捷预设,用户可填写自定义 Base URL 和 API Key 连接第三方图片生成服务

改动说明

目前 Gemini 图片生成 API 的 base_url 虽然存储在数据库中,但 image-generator.ts 并未读取和使用它(只读了 api_keyextra_env),导致无法使用第三方兼容 API。

本 PR 修复了这个问题,并新增了一个第三方预设入口,方便用户配置代理或区域镜像等兼容服务。

Test plan

  • 使用官方 Google Gemini API Key 测试图片生成,确认原有功能不受影响
  • 配置第三方 Gemini 兼容 API(自定义 Base URL + API Key),验证图片生成正常工作
  • 在设置页面确认新增的「Gemini Image Third-party API」预设显示正确,表单包含 Base URL 和 API Key 字段

- image-generator.ts: 从数据库读取 base_url 并传递给 createGoogleGenerativeAI,
  支持第三方 Gemini 兼容的 API 端点(如代理、区域镜像)用于图片生成。
  与 text-generator.ts 中已有的 base_url 处理方式保持一致。

- ProviderManager.tsx: 在 Media Providers 区域新增「Gemini Image Third-party API」
  快捷预设,用户可以填写自定义 Base URL 和 API Key 来连接兼容 Gemini API 的
  第三方图片生成服务。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Cn-cpjl
Copy link
Author

Cn-cpjl commented Feb 28, 2026

Hi,方便的时候帮忙看一下这个 PR 🙏 改动很小,主要是让 Gemini 图片生成支持第三方 API 的 base URL,和 text-generator 保持一致。

Cn-cpjl and others added 3 commits March 3, 2026 14:20
- ProviderManager: gemini-image preset 新增 model_names 字段,允许用户配置模型
- ProviderManager: 模型名写入环境变量时区分 provider 类型,gemini-image 使用 GEMINI_IMAGE_MODEL

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- src/app/api/media/generate/route.ts:
  图片生成失败时提取 AI SDK APICallError 的 url、statusCode、responseBody,
  方便排查第三方 API 代理返回格式不匹配的问题

- src/app/layout.tsx, src/app/fonts/:
  将 Google Fonts (Geist/Geist_Mono) 替换为本地 woff2 字体文件,
  避免 Electron 离线环境下字体加载失败

- package-lock.json: 同步依赖锁文件

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Owner

@op7418 op7418 left a comment

Choose a reason for hiding this comment

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

Review: PR #123 — Third-party base URL for Gemini image generation

Overall: Sensible feature that aligns Gemini image generation with the existing text generation pattern. The code reads base_url from the database and passes it to createGoogleGenerativeAI.

Observations

  1. Large lock file diff: The PR includes significant package-lock.json changes (removing peer: true from many packages). This appears to be a side effect of running npm install in a different environment. These lock file changes are unrelated to the feature and could cause merge conflicts or unexpected dependency resolution changes. Recommend regenerating the lock file from a clean state or splitting the lock file changes into a separate PR.

  2. Feature logic looks correct: Adding the base_url parameter to the Gemini image generator matches how text-generator.ts already handles it.

  3. New preset in ProviderManager: Adding a "Gemini Image Third-party API" quick preset is user-friendly.

  4. Deletion count (242 lines): The large deletion count is mainly from lock file changes, not actual code removal. The actual feature changes are small and focused.

Action Required

  • Please rebase on main and regenerate package-lock.json cleanly, or separate the lock file changes. The current lock file diff makes it hard to review and could introduce unintended dependency changes.

Verdict: Feature code looks good. Needs lock file cleanup before merge.

Copy link
Owner

@op7418 op7418 left a comment

Choose a reason for hiding this comment

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

PR #123 Review: support third-party base URL for Gemini image generation

总体评价

功能本身很简单——允许 Gemini 图片生成使用第三方 base URL。核心代码改动仅涉及 3 个源文件,改动量很小。但 PR 存在严重的 package-lock.json 污染问题。

需要改进的地方

1. package-lock.json 变更过大且无关
PR 标题为 +86/-242,但实际源代码改动很少。package-lock.json 的大量 "peer": true 增删改动(数百行)看起来是由不同的 npm 版本或 npm install 环境差异导致的。这些变更:

  • 没有对应 package.json 中的依赖增删
  • 大量 peer dependency 标记变动与本 PR 功能无关
  • 可能导致其他开发者 merge 后遇到依赖问题

建议: 基于最新 main 分支重新 npm install 生成干净的 lock 文件,只提交功能相关的变更。

2. 字体文件变更无关
src/app/fonts/GeistMonoVF.woff2src/app/fonts/GeistVF.woff2 出现在 diff 中,这些二进制字体文件的变更与 Gemini base URL 功能完全无关。请确认这些文件是否被意外修改,如果是请移除。

3. 新增 preset 的 extra_env 默认值冗余

extra_env: '{"GEMINI_API_KEY":""}',

GEMINI_API_KEYextra_env 中默认为空字符串。但 api_key 字段已经在 fields 中声明,用户会在表单中填写 API key。这个空的 GEMINI_API_KEY 在 extra_env 中是否有实际用途?如果 image-generator.ts 不从 extra_env 读取 GEMINI_API_KEY,这个默认值就是多余的。

4. image-generator.ts 的 base URL 没有做规范化

baseURL: provider.base_url || undefined,

如果用户输入的 URL 末尾有 /(如 https://example.com/v1/),某些 SDK 在拼接路径时可能会出现双斜杠。建议做一个 trimEnd('/') 处理。

5. 错误日志改进过于简单

const apiError = error as { url?: string; statusCode?: number; responseBody?: string };

直接 as 断言 error 的类型是不安全的。建议先检查 error 是否确实有这些属性,或使用 instanceof 检查是否为 AI SDK 的 APICallError

6. 缺少 i18n
新增的 preset 描述有 descriptionZh,这是正确的。但如果有其他用户可见的错误消息或提示需要检查。

优点

  • createGoogleGenerativeAIbaseURL 参数使用正确
  • 新增的 gemini-image-thirdparty preset 与现有的 gemini-image preset 并列,不影响已有用户
  • GEMINI_IMAGE_MODEL 在 extra_env 中的使用区分了 Gemini 和 Anthropic 的 model key

@spiritree
Copy link

有这个需求点,你还继续修改吗,或者我重开个分支改

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.

4 participants