QuantumNous / QuantumNous/new-api

Playground 切换到 Claude/Opus 后会继续携带 Gemini 生图返回的 data:image;base64 上下文

Open
#3,376 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Go
Stars
48.5k
Forks
11.6k
Avg merge
1d 13h
Merged PRs (30d)
58

Description

例行检查

  • 我已确认目前没有类似 issue
  • 我已确认我已升级到最新版本
  • 我已完整查看过项目 README,尤其是常见问题部分
  • 我理解并愿意跟进此 issue,协助测试和提供反馈
  • 我理解并认可上述内容,并理解项目维护者精力有限,不遵循规则的 issue 可能会被无视或直接关闭

问题描述

在 Playground 中,若先使用 Gemini 聊天式生图模型(例如 gemini-2.0-flash-exp-image-generation / gemini-2.0-flash-exp)生成图片,再不清空上下文切换到 claude-opus-* 或其他非 Gemini 文本模型继续对话,前一次 Gemini 返回的图片会以 ![image](data:image/...;base64,...) 的形式残留在 assistant 历史消息中,并被下一次请求原样带入。

这不是结构化图片输入,而是一大段 base64 文本,因此后续模型会把它当普通文本上下文处理,可能导致:

  • prompt/token 体积异常增大
  • 上下文被污染,回答质量下降
  • 在长图或多图情况下触发上下文过长、请求失败或其他异常

我对当前 upstream/main (ed6ff0f2) 做了复查,这条链路仍然存在。

补充一点:这个问题和“用户手动上传图片(image_url)”不是同一路径,问题点在于 Gemini 生图响应被回写成了纯文本历史消息

复现步骤

  1. 打开 Playground
  2. 选择支持聊天式生图的 Gemini 模型,例如 gemini-2.0-flash-exp-image-generationgemini-2.0-flash-exp
  3. 发送“生成一张图片”之类的请求,让模型返回图片
  4. 不清空上下文,直接切换到 claude-opus-*(或其他非 Gemini 文本模型)
  5. 再发送一条普通文本消息,观察请求预览或后端收到的历史消息

预期结果

切换到不支持此类历史媒体表示的模型时,不应原样转发 Gemini 生图返回的 data:image/...;base64,... 内容。

可以考虑的修复方向:

  • 发送前清洗 assistant 历史里的 data:image/...;base64,...
  • 将其替换为占位文本,例如 [generated image omitted]
  • 或在 Playground 层对“模型生成的图片消息”使用结构化存储,避免作为纯文本回放

实际结果

当前链路看起来是这样的:

  • relay/channel/gemini/relay-gemini.go 中会把 Gemini 返回的图片 inlineData 转成 Markdown:![image](data:...;base64,...)
  • web/src/hooks/playground/useApiRequest.jsx 中直接把 choice.message.content 写回 Playground 历史消息
  • web/src/helpers/api.js 构建 payload 时会把整段历史消息原样重新发送
  • 后续切到 Claude/Opus 时,这段 data: base64 会继续进入上下文

相关位置:

  • relay/channel/gemini/relay-gemini.go:1110
  • relay/channel/gemini/relay-gemini.go:1232
  • web/src/hooks/playground/useApiRequest.jsx:231
  • web/src/helpers/api.js:118

相关截图

Image

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Trace the image conversion in relay/channel/gemini/relay-gemini.go around lines 1110 and 1232, then follow history handling in web/src/hooks/playground/useApiRequest.jsx:231 and payload construction in web/src/helpers/api.js:118. Reproduce the Gemini-to-Claude switch in Playground and inspect the resulting history and request. Done means generated-image data is not forwarded as raw base64 when continuing with a model that does not support that representation.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, javascript
Domain
api, backend, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.