Skip to content

feat(go-models): expand providers (SiliconFlow, Qiniu, Huawei Cloud, Jina) tool call support - #17241

Merged
JinHai-CN merged 3 commits into
infiniflow:mainfrom
Harry-Hz-Zhang:feat/llm-tool-siliconflow-qiniu-huawei-jina
Jul 22, 2026
Merged

JinHai-CN merged 3 commits into
infiniflow:mainfrom
Harry-Hz-Zhang:feat/llm-tool-siliconflow-qiniu-huawei-jina

Conversation

@Harry-Hz-Zhang

@Harry-Hz-Zhang Harry-Hz-Zhang commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add tool call support for SiliconFlow, Qiniu, Huawei Cloud, and Jina while consolidating shared OpenAI-compatible helpers used by Aliyun
  • Handle streaming tool call deltas and advertise tool support for eligible provider models
  • Add cross-provider tool call tests and enable Qiniu connection verification through the models endpoint

Testing

  • bash build.sh --test -c -o /tmp/ragflow-models.test ./internal/entity/models
image image

#16990

@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The change adds shared tool-call request and response handling across Aliyun, Huawei Cloud, Jina, Qiniu, and Siliconflow, declares tool support for configured models, adds streaming accumulation and termination handling, and introduces provider integration tests.

Changes

Tool-calling support

Layer / File(s) Summary
Shared tool-call contracts
internal/entity/models/base_model.go
Shared helpers apply tools and tool_choice settings and extract typed tool calls from response messages.
Provider model capability declarations
conf/models/huaweicloud.json, conf/models/qiniu.json, conf/models/siliconflow.json
Configured model entries now declare tools.support: true.
Provider request and response handling
internal/entity/models/aliyun.go, huaweicloud.go, jina.go, qiniu.go, siliconflow.go
Provider chat requests use shared message and tool configuration helpers; non-streaming responses return parsed tool calls and allow tool-call responses without content.
Streaming tool-call accumulation
internal/entity/models/aliyun.go, huaweicloud.go, qiniu.go, siliconflow.go
Streaming handlers accumulate tool-call deltas, recognize terminal events, finalize sorted results, and validate truncated Qiniu streams.
Integration and connectivity tests
internal/entity/models/*_test.go
Tests cover shared request/response tool calls, streaming behavior, missing content, truncated streams, and Qiniu model-list connectivity.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ChatClient
  participant ModelDriver
  participant ProviderAPI
  participant ChatConfig
  ChatClient->>ModelDriver: submit messages, tools, and tool_choice
  ModelDriver->>ProviderAPI: send normalized chat request
  ProviderAPI-->>ModelDriver: return content or tool-call response
  ModelDriver->>ChatConfig: populate ToolCalls or ToolCallsResult
  ModelDriver-->>ChatClient: return ChatResponse or stream completion
Loading

Possibly related issues

Possibly related PRs

  • infiniflow/ragflow#15237 — Updates the Huawei Cloud integration with the same standardized tool-call helpers and streaming handling.

Suggested reviewers: jinhai-cn, haruko386

Poem

A rabbit packed tools in a clever array,
Sent calls through the clouds on their way.
Streams gathered each part,
Tests checked every chart,
And models now know what to say.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

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.
✅ Passed checks (4 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 reflects the main change: adding tool-call support across multiple model providers.
Description check ✅ Passed The description includes a clear Summary and Testing section and sufficiently explains the PR's purpose.

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.

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 22, 2026
@Harry-Hz-Zhang Harry-Hz-Zhang added the ci Continue Integration label Jul 22, 2026
@dosubot dosubot Bot added the 💞 feature Feature request, pull request that fullfill a new feature. label Jul 22, 2026
@Harry-Hz-Zhang Harry-Hz-Zhang changed the title feat(go-models): expand provider tool call support feat(go-models): expand providers (SiliconFlow, Qiniu, Huawei Cloud, Jina) tool call support Jul 22, 2026
@Harry-Hz-Zhang Harry-Hz-Zhang added ci Continue Integration 🐞 bug Something isn't working, pull request that fix bug. and removed ci Continue Integration labels Jul 22, 2026
@Harry-Hz-Zhang
Harry-Hz-Zhang marked this pull request as draft July 22, 2026 07:39
@Harry-Hz-Zhang
Harry-Hz-Zhang marked this pull request as ready for review July 22, 2026 07:39

@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: 1

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/aliyun.go (1)

167-178: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Reasoning-content check doesn't account for tool-only responses.

toolCalls is now extracted at Line 168, but the Thinking-gated block at Lines 175-177 still requires reasoning_content unconditionally, erroring out even when the response is a valid tool-call-only message with no reasoning_content. qiniu.go's equivalent path (ChatWithMessages, lines 244-245) was updated to allow this via !ok && len(toolCalls) == 0, but this file wasn't. As a result, any Aliyun model invoked with Thinking=true that returns tool calls without reasoning_content will incorrectly fail with "invalid content format", defeating the new tool-calling support for that combination.

🐛 Proposed fix
 	var reasonContent string
 	if chatModelConfig != nil && chatModelConfig.Thinking != nil && *chatModelConfig.Thinking {
 		reasonContent, ok = messageMap["reasoning_content"].(string)
-		if !ok {
+		if !ok && len(toolCalls) == 0 {
 			return nil, fmt.Errorf("invalid content format")
 		}
🤖 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/aliyun.go` around lines 167 - 178, Update the
Thinking-gated reasoning_content validation in the Aliyun response parsing flow
to allow missing reasoning_content when toolCalls contains at least one call.
Preserve the existing “invalid content format” error when reasoning_content is
absent or invalid and no tool calls are present, matching the equivalent
ChatWithMessages behavior in qiniu.go.
🤖 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/tool_call_test.go`:
- Around line 69-104: Strengthen the ChatStreamlyWithSender test by decoding and
validating the streaming request in the httptest server, including the
configured tools and tool_choice values. Expand result assertions beyond
arguments to verify the preserved tool-call id, type, function name, and fully
merged arguments. Keep the existing SSE fragments and success-path behavior
intact.

---

Outside diff comments:
In `@internal/entity/models/aliyun.go`:
- Around line 167-178: Update the Thinking-gated reasoning_content validation in
the Aliyun response parsing flow to allow missing reasoning_content when
toolCalls contains at least one call. Preserve the existing “invalid content
format” error when reasoning_content is absent or invalid and no tool calls are
present, matching the equivalent ChatWithMessages behavior in qiniu.go.
🪄 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: ba4769b1-2bc0-4e44-9950-fe78bd9acb7b

📥 Commits

Reviewing files that changed from the base of the PR and between 86113fb and 849acae.

📒 Files selected for processing (14)
  • conf/models/huaweicloud.json
  • conf/models/qiniu.json
  • conf/models/siliconflow.json
  • internal/entity/models/aliyun.go
  • internal/entity/models/base_model.go
  • internal/entity/models/huaweicloud.go
  • internal/entity/models/huaweicloud_test.go
  • internal/entity/models/jina.go
  • internal/entity/models/jina_test.go
  • internal/entity/models/qiniu.go
  • internal/entity/models/qiniu_test.go
  • internal/entity/models/siliconflow.go
  • internal/entity/models/siliconflow_test.go
  • internal/entity/models/tool_call_test.go

Comment on lines +69 to +104
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != path {
t.Errorf("path = %q, want %q", r.URL.Path, path)
}
w.Header().Set("Content-Type", "text/event-stream")
_, _ = w.Write([]byte(`data: {"choices":[{"delta":{"tool_calls":[{"index":0,"id":"call-1","type":"function","function":{"name":"retrieval","arguments":"{\"query\":\""}}]}}]}

data: {"choices":[{"delta":{"tool_calls":[{"index":0,"function":{"arguments":"ragflow\"}"}}]},"finish_reason":"tool_calls"}]}

`))
}))
defer server.Close()

apiKey, toolChoice := "test-key", "auto"
config := &ChatConfig{
Tools: []map[string]interface{}{{"type": "function"}},
ToolChoice: &toolChoice,
ToolCallsResult: &[]map[string]interface{}{{"id": "stale"}},
}
err := newDriver(server.URL).ChatStreamlyWithSender(
modelName,
[]Message{{Role: "user", Content: "find ragflow"}},
&APIConfig{ApiKey: &apiKey},
config,
nil,
func(_, _ *string) error { return nil },
)
if err != nil {
t.Fatalf("ChatStreamlyWithSender: %v", err)
}
if config.ToolCallsResult == nil || len(*config.ToolCallsResult) != 1 {
t.Fatalf("tool calls = %#v", config.ToolCallsResult)
}
function, _ := (*config.ToolCallsResult)[0]["function"].(map[string]interface{})
if function["arguments"] != `{"query":"ragflow"}` {
t.Errorf("function = %#v", function)

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Assert the complete streaming tool-call contract.

This helper never inspects the streaming request and only checks arguments; a provider may omit tools/tool_choice or lose the call id, type, or function name while every streaming test still passes.

Proposed test strengthening
 func testStreamingToolCall(t *testing.T, modelName, path string, newDriver func(string) ModelDriver) {
 	t.Helper()
+	var requestBody map[string]interface{}
 	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
 		if r.URL.Path != path {
 			t.Errorf("path = %q, want %q", r.URL.Path, path)
 		}
+		if err := json.NewDecoder(r.Body).Decode(&requestBody); err != nil {
+			t.Errorf("decode request: %v", err)
+		}
 		w.Header().Set("Content-Type", "text/event-stream")
 		_, _ = w.Write([]byte(`data: ...`))
 	}))
@@
 	if err != nil {
 		t.Fatalf("ChatStreamlyWithSender: %v", err)
 	}
+	if requestBody["tool_choice"] != toolChoice || requestBody["tools"] == nil {
+		t.Errorf("tool config = %#v", requestBody)
+	}
 	if config.ToolCallsResult == nil || len(*config.ToolCallsResult) != 1 {
 		t.Fatalf("tool calls = %#v", config.ToolCallsResult)
 	}
-	function, _ := (*config.ToolCallsResult)[0]["function"].(map[string]interface{})
+	toolCall := (*config.ToolCallsResult)[0]
+	if toolCall["id"] != "call-1" || toolCall["type"] != "function" {
+		t.Errorf("tool call = %#v", toolCall)
+	}
+	function, _ := toolCall["function"].(map[string]interface{})
+	if function["name"] != "retrieval" {
+		t.Errorf("function = %#v", function)
+	}
 	if function["arguments"] != `{"query":"ragflow"}` {
 		t.Errorf("function = %#v", function)
 	}
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != path {
t.Errorf("path = %q, want %q", r.URL.Path, path)
}
w.Header().Set("Content-Type", "text/event-stream")
_, _ = w.Write([]byte(`data: {"choices":[{"delta":{"tool_calls":[{"index":0,"id":"call-1","type":"function","function":{"name":"retrieval","arguments":"{\"query\":\""}}]}}]}
data: {"choices":[{"delta":{"tool_calls":[{"index":0,"function":{"arguments":"ragflow\"}"}}]},"finish_reason":"tool_calls"}]}
`))
}))
defer server.Close()
apiKey, toolChoice := "test-key", "auto"
config := &ChatConfig{
Tools: []map[string]interface{}{{"type": "function"}},
ToolChoice: &toolChoice,
ToolCallsResult: &[]map[string]interface{}{{"id": "stale"}},
}
err := newDriver(server.URL).ChatStreamlyWithSender(
modelName,
[]Message{{Role: "user", Content: "find ragflow"}},
&APIConfig{ApiKey: &apiKey},
config,
nil,
func(_, _ *string) error { return nil },
)
if err != nil {
t.Fatalf("ChatStreamlyWithSender: %v", err)
}
if config.ToolCallsResult == nil || len(*config.ToolCallsResult) != 1 {
t.Fatalf("tool calls = %#v", config.ToolCallsResult)
}
function, _ := (*config.ToolCallsResult)[0]["function"].(map[string]interface{})
if function["arguments"] != `{"query":"ragflow"}` {
t.Errorf("function = %#v", function)
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != path {
t.Errorf("path = %q, want %q", r.URL.Path, path)
}
if err := json.NewDecoder(r.Body).Decode(&requestBody); err != nil {
t.Errorf("decode request: %v", err)
}
w.Header().Set("Content-Type", "text/event-stream")
_, _ = w.Write([]byte(`data: {"choices":[{"delta":{"tool_calls":[{"index":0,"id":"call-1","type":"function","function":{"name":"retrieval","arguments":"{\"query\":\""}}]}}]}
data: {"choices":[{"delta":{"tool_calls":[{"index":0,"function":{"arguments":"ragflow\"}"}}]},"finish_reason":"tool_calls"}]}
`))
}))
defer server.Close()
apiKey, toolChoice := "test-key", "auto"
config := &ChatConfig{
Tools: []map[string]interface{}{{"type": "function"}},
ToolChoice: &toolChoice,
ToolCallsResult: &[]map[string]interface{}{{"id": "stale"}},
}
err := newDriver(server.URL).ChatStreamlyWithSender(
modelName,
[]Message{{Role: "user", Content: "find ragflow"}},
&APIConfig{ApiKey: &apiKey},
config,
nil,
func(_, _ *string) error { return nil },
)
if err != nil {
t.Fatalf("ChatStreamlyWithSender: %v", err)
}
if requestBody["tool_choice"] != toolChoice || requestBody["tools"] == nil {
t.Errorf("tool config = %#v", requestBody)
}
if config.ToolCallsResult == nil || len(*config.ToolCallsResult) != 1 {
t.Fatalf("tool calls = %#v", config.ToolCallsResult)
}
toolCall := (*config.ToolCallsResult)[0]
if toolCall["id"] != "call-1" || toolCall["type"] != "function" {
t.Errorf("tool call = %#v", toolCall)
}
function, _ := toolCall["function"].(map[string]interface{})
if function["name"] != "retrieval" {
t.Errorf("function = %#v", function)
}
if function["arguments"] != `{"query":"ragflow"}` {
t.Errorf("function = %#v", function)
}
🤖 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/tool_call_test.go` around lines 69 - 104, Strengthen
the ChatStreamlyWithSender test by decoding and validating the streaming request
in the httptest server, including the configured tools and tool_choice values.
Expand result assertions beyond arguments to verify the preserved tool-call id,
type, function name, and fully merged arguments. Keep the existing SSE fragments
and success-path behavior intact.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration 💞 feature Feature request, pull request that fullfill a new feature. 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