Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

fix: drop max_tokens from generic OpenAI-compatible request builder (#17857)

jay77721dc6c0e5de5c1
diff --git a/internal/entity/models/astraflow_test.go b/internal/entity/models/astraflow_test.go
index e7b275d9c9..c6c25eff7b 100644
--- a/internal/entity/models/astraflow_test.go
+++ b/internal/entity/models/astraflow_test.go
@@ -101,9 +101,6 @@ func TestAstraflowChatHappyPath(t *testing.T) {
if body["stream"] != false {
t.Errorf("stream=%v, want false", body["stream"])
}
- if body["max_tokens"] != float64(64) {
- t.Errorf("max_tokens=%v, want 64", body["max_tokens"])
- }
if body["temperature"] != 0.3 {
t.Errorf("temperature=%v, want 0.3", body["temperature"])
}
diff --git a/internal/entity/models/avian_test.go b/internal/entity/models/avian_test.go
index 607bf45c9f..0dac481ae1 100644
--- a/internal/entity/models/avian_test.go
+++ b/internal/entity/models/avian_test.go
@@ -91,9 +91,6 @@ func TestAvianChatHappyPath(t *testing.T) {
if body["stream"] != false {
t.Errorf("stream=%v, want false", body["stream"])
}
- if body["max_tokens"] != float64(64) {
- t.Errorf("max_tokens=%v, want 64", body["max_tokens"])
- }
if body["temperature"] != 0.3 {
t.Errorf("temperature=%v, want 0.3", body["temperature"])
}
diff --git a/internal/entity/models/base_model.go b/internal/entity/models/base_model.go
index 8ab483eefe..07e55a8d72 100644
--- a/internal/entity/models/base_model.go
+++ b/internal/entity/models/base_model.go
@@ -513,10 +513,6 @@ func buildRequestBody(cfg *ChatConfig, modelName string, messages []Message, str
}
if cfg != nil {
- if cfg.MaxTokens != nil {
- reqBody["max_tokens"] = *cfg.MaxTokens
- }
-
if cfg.Temperature != nil {
reqBody["temperature"] = *cfg.Temperature
}
diff --git a/internal/entity/models/cometapi_test.go b/internal/entity/models/cometapi_test.go
index 694c82efba..a682e1b750 100644
--- a/internal/entity/models/cometapi_test.go
+++ b/internal/entity/models/cometapi_test.go
@@ -119,9 +119,6 @@ func TestCometAPIChatPropagatesConfig(t *testing.T) {
withSSRFBypass(t)
ctx := t.Context()
srv := newCometAPIServer(t, "/v1/chat/completions", func(t *testing.T, body map[string]interface{}, w http.ResponseWriter) {
- if body["max_tokens"] != float64(64) {
- t.Errorf("max_tokens=%v want 64", body["max_tokens"])
- }
if body["temperature"] != 0.3 {
t.Errorf("temperature=%v want 0.3", body["temperature"])
}
diff --git a/internal/entity/models/gpustack_test.go b/internal/entity/models/gpustack_test.go
index a8b32d21a4..84c2ad13fd 100644
--- a/internal/entity/models/gpustack_test.go
+++ b/internal/entity/models/gpustack_test.go
@@ -168,7 +168,7 @@ func TestGPUStackChatExtractsReasoningContent(t *testing.T) {
func TestGPUStackChatForwardsDocumentedFields(t *testing.T) {
withSSRFBypass(t)
srv := newGPUStackServer(t, "/v1/chat/completions", func(t *testing.T, body map[string]interface{}, w http.ResponseWriter) {
- for _, k := range []string{"model", "messages", "stream", "max_tokens", "temperature", "top_p", "stop"} {
+ for _, k := range []string{"model", "messages", "stream", "temperature", "top_p", "stop"} {
if _, present := body[k]; !present {
t.Errorf("documented field %q missing from request body", k)
}
diff --git a/internal/entity/models/groq_test.go b/internal/entity/models/groq_test.go
index a9f931036b..f1511b67dd 100644
--- a/internal/entity/models/groq_test.go
+++ b/internal/entity/models/groq_test.go
@@ -127,9 +127,6 @@ func TestGroqChatHappyPath(t *testing.T) {
if body["stream"] != false {
t.Errorf("stream=%v want false", body["stream"])
}
- if body["max_tokens"] != float64(32) {
- t.Errorf("max_tokens=%v", body["max_tokens"])
- }
if body["temperature"] != 0.3 {
t.Errorf("temperature=%v", body["temperature"])
}
diff --git a/internal/entity/models/hunyuan_test.go b/internal/entity/models/hunyuan_test.go
index cdd2de77df..3fa6e7084b 100644
--- a/internal/entity/models/hunyuan_test.go
+++ b/internal/entity/models/hunyuan_test.go
@@ -104,9 +104,6 @@ func TestHunyuanChatHappyPath(t *testing.T) {
if body["stream"] != false {
t.Errorf("stream=%v, want false", body["stream"])
}
- if body["max_tokens"] != float64(64) {
- t.Errorf("max_tokens=%v, want 64", body["max_tokens"])
- }
if body["temperature"] != 0.3 {
t.Errorf("temperature=%v, want 0.3", body["temperature"])
}
diff --git a/internal/entity/models/jina_test.go b/internal/entity/models/jina_test.go
index 9528ddc8cf..27d4448e9f 100644
--- a/internal/entity/models/jina_test.go
+++ b/internal/entity/models/jina_test.go
@@ -134,9 +134,6 @@ func TestJinaChatPropagatesConfig(t *testing.T) {
withSSRFBypass(t)
ctx := t.Context()
srv := newJinaServer(t, "/chat/completions", func(t *testing.T, body map[string]interface{}, w http.ResponseWriter) {
- if body["max_tokens"] != float64(128) {
- t.Errorf("max_tokens=%v want 128", body["max_tokens"])
- }
if body["temperature"] != 0.2 {
t.Errorf("temperature=%v want 0.2", body["temperature"])
}
diff --git a/internal/entity/models/longcat_test.go b/internal/entity/models/longcat_test.go
index 9814eee7aa..37bbb7c0b0 100644
--- a/internal/entity/models/longcat_test.go
+++ b/internal/entity/models/longcat_test.go
@@ -289,9 +289,9 @@ func TestLongCatChatAcceptsReasoningOnlyResponse(t *testing.T) {
// TestLongCatChatDropsUndocumentedFields guards against re-introducing
// stop / reasoning_effort / response_format / tools etc. The LongCat
-// docs only list model, messages, stream, max_tokens, temperature,
-// top_p — anything else is undocumented and must not be sent, since
-// the maintainer specifically flagged this on PR #14809.
+// docs only list model, messages, stream, temperature, top_p — anything
+// else is undocumented and must not be sent, since the maintainer
+// specifically flagged this on PR #14809.
func TestLongCatChatDropsUndocumentedFields(t *testing.T) {
withSSRFBypass(t)
ctx := t.Context()
@@ -302,7 +302,7 @@ func TestLongCatChatDropsUndocumentedFields(t *testing.T) {
}
}
// Documented fields, on the other hand, MUST be forwarded when set.
- for _, k := range []string{"model", "messages", "stream", "max_tokens", "temperature", "top_p"} {
+ for _, k := range []string{"model", "messages", "stream", "temperature", "top_p"} {
if _, present := body[k]; !present {
t.Errorf("documented field %q missing from request body", k)
}
diff --git a/internal/entity/models/mistral_test.go b/internal/entity/models/mistral_test.go
index 099879c190..d4be9bf8e9 100644
--- a/internal/entity/models/mistral_test.go
+++ b/internal/entity/models/mistral_test.go
@@ -110,9 +110,6 @@ func TestMistralChatPropagatesConfig(t *testing.T) {
withSSRFBypass(t)
ctx := t.Context()
srv := newMistralServer(t, "/chat/completions", func(t *testing.T, body map[string]interface{}, w http.ResponseWriter) {
- if body["max_tokens"] != float64(64) {
- t.Errorf("max_tokens=%v want 64", body["max_tokens"])
- }
if body["temperature"] != 0.3 {
t.Errorf("temperature=%v want 0.3", body["temperature"])
}
diff --git a/internal/entity/models/modelscope_test.go b/internal/entity/models/modelscope_test.go
index c3b047979b..3a963efb60 100644
--- a/internal/entity/models/modelscope_test.go
+++ b/internal/entity/models/modelscope_test.go
@@ -128,9 +128,6 @@ func TestModelScopeChatHappyPathNormalizesBaseURLAndOmitsEmptyAuth(t *testing.T)
if seen["stream"] != false {
t.Errorf("stream=%v, want false", seen["stream"])
}
- if seen["max_tokens"] != float64(32) {
- t.Errorf("max_tokens=%v, want 32", seen["max_tokens"])
- }
if seen["temperature"] != 0.2 {
t.Errorf("temperature=%v, want 0.2", seen["temperature"])
}
diff --git a/internal/entity/models/ppio_test.go b/internal/entity/models/ppio_test.go
index 082109957e..8e632d6f73 100644
--- a/internal/entity/models/ppio_test.go
+++ b/internal/entity/models/ppio_test.go
@@ -91,9 +91,6 @@ func TestPPIOChatHappyPath(t *testing.T) {
if _, ok := body["reasoning_effort"]; ok {
t.Errorf("reasoning_effort should not be sent: %v", body["reasoning_effort"])
}
- if body["max_tokens"] != float64(32) {
- t.Errorf("max_tokens=%v", body["max_tokens"])
- }
if body["temperature"] != 0.3 {
t.Errorf("temperature=%v", body["temperature"])
}
diff --git a/internal/entity/models/tokenpony_test.go b/internal/entity/models/tokenpony_test.go
index a4cbd89581..cb3f51e059 100644
--- a/internal/entity/models/tokenpony_test.go
+++ b/internal/entity/models/tokenpony_test.go
@@ -101,9 +101,6 @@ func TestTokenPonyChatHappyPath(t *testing.T) {
if body["stream"] != false {
t.Errorf("stream=%v, want false", body["stream"])
}
- if body["max_tokens"] != float64(64) {
- t.Errorf("max_tokens=%v, want 64", body["max_tokens"])
- }
if body["temperature"] != 0.3 {
t.Errorf("temperature=%v, want 0.3", body["temperature"])
}
diff --git a/internal/entity/models/upstage_test.go b/internal/entity/models/upstage_test.go
index c90ecd0de7..56f5521fc8 100644
--- a/internal/entity/models/upstage_test.go
+++ b/internal/entity/models/upstage_test.go
@@ -204,7 +204,6 @@ func TestUpstageRequestBodyMatchesSolarAPIShape(t *testing.T) {
want := map[string]interface{}{
"model": "solar-pro2",
"stream": false,
- "max_tokens": float64(256),
"temperature": 0.7,
"top_p": 0.9,
"reasoning_effort": "high",
diff --git a/internal/entity/models/xiaomi.go b/internal/entity/models/xiaomi.go
index 70b3a18fea..3065db7e50 100644
--- a/internal/entity/models/xiaomi.go
+++ b/internal/entity/models/xiaomi.go
@@ -77,7 +77,6 @@ func (x *XiaomiModel) ChatWithMessages(ctx context.Context, modelName string, me
// Build request body
reqBody := buildRequestBody(chatModelConfig, modelName, messages, false)
- delete(reqBody, "max_tokens")
if chatModelConfig != nil {
if chatModelConfig.MaxTokens != nil {
@@ -125,7 +124,6 @@ func (x *XiaomiModel) ChatStreamlyWithSender(ctx context.Context, modelName stri
// Build request body with streaming enabled
reqBody := buildRequestBody(modelConfig, modelName, messages, true)
- delete(reqBody, "max_tokens")
reqBody["stream_options"] = map[string]interface{}{
"include_usage": true,
}
diff --git a/internal/entity/models/xinference_test.go b/internal/entity/models/xinference_test.go
index c75ded1c41..15f573070e 100644
--- a/internal/entity/models/xinference_test.go
+++ b/internal/entity/models/xinference_test.go
@@ -95,9 +95,6 @@ func TestXinferenceChatHappyPathNormalizesBaseURLAndOmitsEmptyAuth(t *testing.T)
if seen["stream"] != false {
t.Errorf("stream=%v, want false", seen["stream"])
}
- if seen["max_tokens"] != float64(32) {
- t.Errorf("max_tokens=%v, want 32", seen["max_tokens"])
- }
if seen["temperature"] != 0.2 {
t.Errorf("temperature=%v, want 0.2", seen["temperature"])
}