Skip to content

Go: add tools for moonshot, baidu and minimax - #17000

Merged
JinHai-CN merged 2 commits into
infiniflow:mainfrom
Haruko386:monday
Jul 16, 2026
Merged

JinHai-CN merged 2 commits into
infiniflow:mainfrom
Haruko386:monday

Conversation

@Haruko386

@Haruko386 Haruko386 commented Jul 16, 2026 •

Copy link
Copy Markdown
Member

Summary

 ___________________
< plz read #16990 >
 -------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ

As title
related to #16990

@Haruko386 Haruko386 added 💞 feature Feature request, pull request that fullfill a new feature. ci Continue Integration go Pull requests that update go code labels Jul 16, 2026
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 16, 2026
@Haruko386
Haruko386 marked this pull request as draft July 16, 2026 09:43
@coderabbitai

coderabbitai Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Tool-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.

Changes

Provider tool-call support

Layer / File(s) Summary
Endpoint normalization
conf/models/minimax.json, internal/entity/models/base_model.go
Minimax configured endpoints and resolved regional base URLs no longer end with /.
Baidu tool-call handling
internal/entity/models/baidu.go
Baidu requests include optional tool fields, responses expose parsed tool calls, and streaming deltas are merged into ordered results.
Minimax tool-call handling
internal/entity/models/minimax.go
Minimax requests and responses support tool calls, while streaming argument fragments are accumulated by tool-call index.
Moonshot tool-call handling and validation
internal/entity/models/moonshot.go, internal/entity/models/moonshot_test.go
Moonshot supports tool calls in both modes, accepts responses without textual content, and tests request and response parsing.

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
Loading

Suggested labels: 🧪 test

Suggested reviewers: euvre

Poem

I’m a rabbit with tools in my paws,
Parsing calls without trailing slash flaws.
Streams softly unfold,
Arguments are told,
Moonshot hops through validation applause.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The description only repeats the title and issue reference, without the required summary or background context. Add a short Summary explaining what changed, why it was needed, and any relevant context for reviewers.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly states the main change: adding tool support for Moonshot, Baidu, and MiniMax.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Haruko386
Haruko386 marked this pull request as ready for review July 16, 2026 09:43

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 win

Only tolerate absent content when a valid tool call exists.

This now converts any missing, null, or incorrectly typed content into a successful empty answer—even when tool_calls is 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 win

Assert the executable tool-call payload.

The test only checks id; it would still pass if function.name or function.arguments were 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

📥 Commits

Reviewing files that changed from the base of the PR and between feba9e1 and 35cd2aa.

📒 Files selected for processing (6)
  • conf/models/minimax.json
  • internal/entity/models/baidu.go
  • internal/entity/models/base_model.go
  • internal/entity/models/minimax.go
  • internal/entity/models/moonshot.go
  • internal/entity/models/moonshot_test.go

Comment thread internal/entity/models/baidu.go Resolved
Comment thread internal/entity/models/minimax.go Resolved
Comment thread internal/entity/models/moonshot.go Resolved
Comment thread internal/entity/models/moonshot.go Resolved
@Haruko386 Haruko386 linked an issue Jul 16, 2026 that may be closed by this pull request
55 of 66 tasks
@Haruko386 Haruko386 removed a link to an issue Jul 16, 2026
55 of 66 tasks
@JinHai-CN
JinHai-CN merged commit 5307ecd into infiniflow:main Jul 16, 2026
3 checks passed
@Haruko386
Haruko386 deleted the monday branch August 18, 2026 05:05
@Haruko386
Haruko386 restored the monday branch August 18, 2026 05:05
@Haruko386
Haruko386 deleted the monday branch August 18, 2026 05:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration 💞 feature Feature request, pull request that fullfill a new feature. go Pull requests that update go code size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants