Repository navigation
fix(api): 兼容 Chat 纯文本 assistant 尾轮续写 - #49
Merged
Merged
Conversation
Owner
|
我觉得可以做成Anthropic协议一样的造system而不是user,我先去sillytavern试一下效果;以及 这个commit有点过度防御性了,我一起修一下 |
- 续写:上游适配层统一处理末尾连续 assistant 轮,正文与代码执行内容作为系统指令中的续写前缀,响应只返回续写部分,末尾未回传结果的函数调用由模型重新生成;各生成入口与计数接口共用,删除 Anthropic 入口的单独实现与 Chat 入口追加 user 指令的实现 - 请求内容:没有对话内容时以系统提示作为 user 轮;Chat、Responses、Anthropic、Gemini 与 Interactions 入口只要求模型,Anthropic max_tokens 可省略;既无系统提示也无对话内容时在选择账户前返回 400 - 流式:五个协议入口在写出响应头前等待首个事件,首个事件为错误时按非流式返回 HTTP 状态与错误对象,10 秒内没有事件时照常推流 - 测试:删除针对 Chat 单独实现的测试 - 文档:protocol.md 写明续写方式、必需字段与流式错误的返回时机
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.
问题
OpenAI Chat 请求可能以纯文本
assistant结尾;即使原始数组最后一项是system/developer,提取系统提示后也可能变成这种形状。Google 上游会拒绝此类请求:最小合成示例(不含真实对话内容):
{ "model": "gemini-3.8-flash", "messages": [ {"role": "user", "content": "Start a story."}, {"role": "assistant", "content": "Once upon a time,"}, {"role": "system", "content": "Continue the story."} ] }改动
基于当前
main/v0.2.6(e2dd10f),只修改 OpenAI Chat 请求转换、回归测试和协议文档。这是提示驱动的近似续写,不是原生 token 级 prefill。 不保证逐字衔接或绝不重复;响应端不拼接、裁剪前缀。流式与非流式请求共用同一转换。
验证
go test -mod=readonly ./internal/api通过。user结尾。npm ci --no-audit --no-fund、npm run lint、npm run build通过(仅有前端 chunk 体积提示)。go test -mod=readonly ./cmd/... ./internal/...通过。go vet ./...通过。go test -mod=readonly -race ./internal/api ./internal/aistudio通过。git diff --check和三文件范围检查通过。