Repository navigation
Go: add tools for moonshot, baidu and minimax - #17000
Conversation
📝 WalkthroughWalkthroughTool-call support was added to Baidu, Minimax, and Moonshot chat integrations for request serialization, non-streaming response parsing, and streaming delta reconstruction. Minimax endpoint configuration and resolved base URLs now omit trailing slashes. Moonshot includes request/response coverage. ChangesProvider tool-call support
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant ChatClient
participant ModelProvider
participant StreamParser
participant ModelConfig
ChatClient->>ModelProvider: send messages, tools, and tool_choice
ModelProvider-->>ChatClient: return content and tool_calls
ModelProvider->>StreamParser: emit tool-call deltas
StreamParser->>StreamParser: merge arguments by index
StreamParser->>ModelConfig: store ordered ToolCallsResult
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/entity/models/moonshot.go (1)
193-220: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winOnly tolerate absent content when a valid tool call exists.
This now converts any missing,
null, or incorrectly typedcontentinto a successful empty answer—even whentool_callsis absent or malformed. Preserve the previous format error unless at least one valid tool call was decoded.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/entity/models/moonshot.go` around lines 193 - 220, Update the response parsing around content extraction and toolCalls so missing, null, or incorrectly typed messageMap["content"] still returns the existing format error unless at least one valid tool call was successfully decoded. Track whether toolCalls contains a valid decoded entry, and only allow an empty content answer when that condition is true; preserve normal content handling and malformed/absent tool-call behavior.
🧹 Nitpick comments (1)
internal/entity/models/moonshot_test.go (1)
175-180: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAssert the executable tool-call payload.
The test only checks
id; it would still pass iffunction.nameorfunction.argumentswere lost. Assert both nested fields returned by the fixture.As per coding guidelines, “Preserve valid behavior with focused tests.”
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/entity/models/moonshot_test.go` around lines 175 - 180, Update the test assertions following the Answer check to validate the complete executable tool-call payload in resp.ToolCalls: retain the existing id assertion and also assert the nested function.name and function.arguments values provided by the fixture. Keep the test focused on preserving these fields.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/entity/models/baidu.go`:
- Around line 411-441: Update the SSE tool-call handling around the tool_calls
accumulation block to continue processing the same delta after merging tool
calls, so finish_reason still reaches the terminal-state logic instead of
returning early. Make accumulation resilient to missing nested function maps by
creating and retaining them when later chunks provide function data, and merge
split string fields including function arguments, function name, and the
tool-call id rather than silently dropping them.
In `@internal/entity/models/minimax.go`:
- Around line 207-224: Relax the content parsing in the non-streaming response
flow before tool-call extraction: update the logic around messageMap["content"]
to default missing or null values to an empty string instead of returning an
error. Likewise, make reasoning_content optional within the existing
chatModelConfig Thinking check, preserving newline trimming when a string is
present, so ChatResponse construction and tool_calls processing remain
reachable.
In `@internal/entity/models/moonshot.go`:
- Line 348: Reset the reused ChatConfig’s ToolCallsResult output at the start of
each stream, before parsing or conditionally assigning tool calls. Update the
stream handling around accumulatedToolCalls and the corresponding logic at the
referenced later block so requests with no tool calls explicitly produce an
empty result instead of retaining data from a previous request.
- Around line 365-394: Remove the early return after processing tool_calls in
the delta-handling logic, while preserving the existing accumulation behavior.
Ensure the same event continues through processing for content,
reasoning_content, and finish_reason, so terminal tool-call events are handled
without requiring a following [DONE].
---
Outside diff comments:
In `@internal/entity/models/moonshot.go`:
- Around line 193-220: Update the response parsing around content extraction and
toolCalls so missing, null, or incorrectly typed messageMap["content"] still
returns the existing format error unless at least one valid tool call was
successfully decoded. Track whether toolCalls contains a valid decoded entry,
and only allow an empty content answer when that condition is true; preserve
normal content handling and malformed/absent tool-call behavior.
---
Nitpick comments:
In `@internal/entity/models/moonshot_test.go`:
- Around line 175-180: Update the test assertions following the Answer check to
validate the complete executable tool-call payload in resp.ToolCalls: retain the
existing id assertion and also assert the nested function.name and
function.arguments values provided by the fixture. Keep the test focused on
preserving these fields.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 134901c4-1cce-4331-b6da-d629934353ac
📒 Files selected for processing (6)
conf/models/minimax.jsoninternal/entity/models/baidu.gointernal/entity/models/base_model.gointernal/entity/models/minimax.gointernal/entity/models/moonshot.gointernal/entity/models/moonshot_test.go
Summary
As title
related to #16990