Repository navigation
feat(api/build): 支持 Build 原生单次调用并修复非流式响应碎片与思考签名规范 - #41
Merged
Merged
Conversation
- 在非流式响应中合并相邻的文本片段与思考片段,对齐官方原生接口表现,避免在酒馆等前端中出现异常换行 - 规范化挂载 thoughtSignature 至对应的 Content Part,消除多余的独立空签名 Part - 补充 geminiOutputParts 单元测试,覆盖相邻合并、思考签名附着及回退场景
- 解锁 Build 通道对免费模型的 Unary 支持,直接调用 ProxyUnaryCall 原生单次接口 - 非流式请求(!stream)统一标记 Unary 并默认路由至 Build 通道 - 适配 Gemini、OpenAI、Anthropic、Responses 全协议端点
Owner
|
非常感谢,合入并进一步进行了修复。 |
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
代码供参考,是gemini3.8f写的,经过了简单的代码质量检测,并且本地实测功能正常,修改成功
📝 PR Description
背景与动机
[{text: "..."}, {text: "..."}]结构,在很多前端渲染时会表现为异常换行破版;且部分附带thoughtSignature的 Part 为空对象,不符合 Gemini 官方输出规范。Unary,免费模型走流式切片。实际上 Google Build 接口具备原生ProxyUnaryCall能力,针对非流式请求直接调用原生单次接口不仅响应更加自然,还能规避流式传输中的中间状态审查与断连问题。
变更说明
1. API 层规范化(Bugfix)
geminiOutputParts时自动将相邻的纯文本或思考内容按流式规范合并,对齐官方真实 REST 接口行为。thoughtSignature准确挂载在对应的 Content Part 上,避免输出独立的空签名 Part。internal/api/gemini_output_test.go中补充了针对相邻文本合并、思考片段聚合及签名挂载的测试用例。2. AIStudio / Build 渠道扩展(Feature)
internal/aistudio/build.go中支持通过request.Unary触发ProxyUnaryCall,不局限于计费模型。GenerateRequest中引入Unary与Channel字段;!stream)统一标记Unary = true;Unary == true且未指定通道时,默认优先路由至ChannelBuild原生单次接口。