Skip to content

修复 CodeBuddy 不支持非流式请求的问题#491

Open
rensumo wants to merge 2 commits intorouter-for-me:mainfrom
Ve-ria:main
Open

修复 CodeBuddy 不支持非流式请求的问题#491
rensumo wants to merge 2 commits intorouter-for-me:mainfrom
Ve-ria:main

Conversation

@rensumo
Copy link
Copy Markdown

@rensumo rensumo commented Apr 6, 2026

变更说明

  • 修复 CodeBuddy 在非流式请求场景下无法正常返回的问题
  • 调整 CodeBuddy 执行器的非流式逻辑:上游统一走 SSE 流式请求,再将返回的 chat.completion.chunk 聚合为单次非流式 chat.completion 响应
  • 保持原有流式行为不变,同时保留 usage、reasoning_content、tool_calls、finish_reason 等关键信息,确保后续响应转换逻辑可正常工作

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements streaming response aggregation for the CodeBuddy executor. Key changes include updating request translation to support streaming, adding required HTTP headers, and introducing the aggregateOpenAIChatCompletionStream function to merge stream chunks into a standard chat completion format. Review feedback identified a critical logic error where the translated payload was being incorrectly overwritten and suggested optimizing redundant JSON parsing during the stream aggregation process.

Comment on lines +403 to +421
root := gjson.ParseBytes(payload)
if responseID == "" {
responseID = root.Get("id").String()
}
if model == "" {
model = root.Get("model").String()
}
if created == 0 {
created = root.Get("created").Int()
}
if serviceTier == "" {
serviceTier = root.Get("service_tier").String()
}
if systemFP == "" {
systemFP = root.Get("system_fingerprint").String()
}
if detail, ok := parseOpenAIStreamUsage(line); ok {
usageDetail = detail
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

aggregateOpenAIChatCompletionStream 的循环内部存在重复的 JSON 解析。gjson.ParseBytes(payload) 已经解析了整个对象,但随后的 parseOpenAIStreamUsage(line) 内部又会再次对同一段数据进行解析。虽然在非流式聚合场景下性能开销通常可接受,但建议优化以减少冗余解析,例如直接从已解析的 root 对象中提取 usage 信息。

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
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.

1 participant