pref:增加事件流字段,修复事件流信息缺口并清理废弃代码#135
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
变更说明
本次 PR 增加返回事件流定义字段,同时解决了事件流架构中的两个问题:
mergeToolCallDeltas函数及相关测试tool_call_start事件缺少ToolCallIndex的信息缺口问题背景
在事件流架构中,Provider 通过
StreamEvent向 Runtime 推送增量事件。原先的实现中:tool_call_start事件只包含ID和Name,缺少Indextool_call_delta事件只包含Index和ArgumentsDelta,缺少ID这导致两个事件无法关联,Runtime 无法从事件流重建完整的
Message。主要改动
1. 删除废弃函数(
openai.go)删除
mergeToolCallDeltas函数(第 437-463 行),该函数已被consumeStream内联处理替代。2. 修复事件流信息缺口
修改
emitToolCallStart函数签名,新增index参数:更新调用处(
openai.go第 255 行):3. 优化事件结构(
types.go)重新组织
StreamEvent字段顺序,按事件类型分组:更新字段注释,明确
ToolCallIndex在tool_call_start和tool_call_delta中都有效。4. 清理不必要的字段设置
移除
emitTextDelta和emitMessageDone中不必要的ToolCallIndex字段设置:func emitTextDelta(...) { events <- domain.StreamEvent{ Type: domain.StreamEventTextDelta, Text: text, - ToolCallIndex: -1, } }5. 更新测试(
openai_test.go)删除废弃测试:
TestMergeToolCallDeltas(约 77 行)TestMergeToolCallDeltasEdgeCases(约 122 行)更新
TestEmitToolCallStartGuards测试:更新
TestProviderChatEmitsFullEventStream测试:移除对
text_delta和message_done事件中ToolCallIndex的检查(不再需要验证-1)。预期收益
1. 代码质量提升
2. 事件流信息完整
修复后的
tool_call_start事件:现在 Runtime 可以:
tool_call_start创建ToolCall条目,用ToolCallIndex作为 map keytool_call_delta根据ToolCallIndex找到对应条目并追加 argumentsMessage{Content, ToolCalls}3. 为未来架构演进铺路
本次修复为"删除
ChatResponse返回值"的重构奠定了基础:ChatResponse,Runtime 直接使用resp.MessageMessage架构演进路径:
4. 事件语义更清晰
修复前后的对比:
tool_call_start携带 index-1测试覆盖
go build ./...编译通过ToolCallIndex的验证FIxes: #134