WaiooT (Tencent Cloud Token Plan, deepseek-v4.1-flash, an agent named nowledge-mem): requests often ended "an empty reply (the model answered nothing; try again) -- cut at its length, the whole output spent on reasoning". Output 4,096, reasoning tokens 4,096, finish length. The request named max_tokens 4096 (the memory tool's own setting; magpie adds no limit to it) and no reasoning. Tencent's DeepSeek runs thinking by default (docs 1823/132248: thinking "enabled", reasoning_effort "high", "max_tokens >= 2048 advised in thinking mode") and counts it in max_tokens, so the thinking spent the whole limit before an answer. A Chat or Responses request to a tencentmaas.com provider's DeepSeek model that names a reply limit of 16384 or less, names no reasoning of its own (reasoning_effort, thinking, enable_thinking, reasoning...) and has no Max output set by the user is sent that limit plus a high effort's room (replyRoom, as side calls are), within the model's own limit where known (withThinkingRoom, maxoutput.go). Scoped to that host and DeepSeek models. The failure itself, a cut void, was already failed at once and asked nowhere (#2972): its text now names the limit the request set and what to do ("raise max_tokens in the agent, or ask for less reasoning"), still holding cutVoidWords, so the group and patience matching is unchanged. Run (mica): TestTencentDeepSeekCapGetsThinkingRoom (4096 gets room; max_completion_tokens too; effort asked, thinking off, a large limit, no limit, and another vendor's DeepSeek go as they came), TestChatLength* (the error names the limit), TestShortDefault*, and gateway tests matching Void|Length|Empty|Cut|Tencent|Output|Thinking|Reasoning; gofmt; go vet darwin, linux nogui, windows of internal/gateway. Broken by hand: withThinkingRoom's call removed, the new test red ("4096 and no reasoning: max_tokens 4096, want 28096"). Not tried: a real Tencent Token Plan key (none here), so that the 4096 came from the agent and not a Tencent default is read from the docs and the reporter's numbers, not seen on the wire; an Anthropic-protocol client in front of Tencent's DeepSeek is not covered; full suite after the tag.
77 lines
3.1 KiB
Go
77 lines
3.1 KiB
Go
package gateway
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// WaiooT on X (Tencent Cloud Token Plan, deepseek-v4.1-flash): a memory tool
|
|
// capped its replies at max_tokens 4096 and named no reasoning. TokenHub runs
|
|
// DeepSeek's thinking by default (thinking "enabled", reasoning_effort
|
|
// "high"), the thinking spent all 4096 and every reply was cut at its length
|
|
// with no answer. A small reply limit sent to Tencent's DeepSeek with no
|
|
// reasoning asked has room to think above it; a limit with reasoning asked,
|
|
// one the user set as Max output, a limit already large, and the same request
|
|
// to another vendor's DeepSeek go as they came.
|
|
func TestTencentDeepSeekCapGetsThinkingRoom(t *testing.T) {
|
|
fresh(t)
|
|
u := &ownOutputUpstream{}
|
|
up := httptest.NewServer(u)
|
|
t.Cleanup(up.Close)
|
|
for _, p := range []provider.Provider{
|
|
{ID: "tencent", Name: "Tencent", Key: "k", Models: []string{"deepseek/deepseek-flash"},
|
|
Chat: "http://tokenhub.tencentmaas.com/plan/v3"},
|
|
{ID: "relay", Name: "Relay", Key: "k", Models: []string{"deepseek/deepseek-flash"},
|
|
Chat: "http://relay.example.com/v1"},
|
|
} {
|
|
if err := provider.Save(p); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
s := New()
|
|
addr := strings.TrimPrefix(up.URL, "http://")
|
|
s.client = &http.Client{Transport: &http.Transport{DialContext: func(ctx context.Context, network, _ string) (net.Conn, error) {
|
|
return (&net.Dialer{}).DialContext(ctx, network, addr)
|
|
}}}
|
|
const msg = `"messages":[{"role":"user","content":"hi"}]`
|
|
for _, c := range []struct {
|
|
name, body string
|
|
want int
|
|
}{
|
|
{"4096 and no reasoning", `{"model":"tencent/deepseek/deepseek-flash","max_tokens":4096,` + msg + `}`, 4096 + 24000},
|
|
{"max_completion_tokens", `{"model":"tencent/deepseek/deepseek-flash","max_completion_tokens":2000,` + msg + `}`, 0},
|
|
{"effort asked", `{"model":"tencent/deepseek/deepseek-flash","max_tokens":4096,"reasoning_effort":"low",` + msg + `}`, 4096},
|
|
{"thinking off", `{"model":"tencent/deepseek/deepseek-flash","max_tokens":4096,"thinking":{"type":"disabled"},` + msg + `}`, 4096},
|
|
{"a large limit", `{"model":"tencent/deepseek/deepseek-flash","max_tokens":32000,` + msg + `}`, 32000},
|
|
{"no limit", `{"model":"tencent/deepseek/deepseek-flash",` + msg + `}`, -1},
|
|
{"another vendor's", `{"model":"relay/deepseek/deepseek-flash","max_tokens":4096,` + msg + `}`, 4096},
|
|
} {
|
|
if code, raw := postJSON(t, s, "/v1/chat/completions", c.body); code != 200 {
|
|
t.Fatalf("%s: %d %s", c.name, code, raw)
|
|
}
|
|
got := u.take()
|
|
if len(got) != 1 {
|
|
t.Fatalf("%s: %d requests upstream", c.name, len(got))
|
|
}
|
|
field := "max_tokens"
|
|
if _, ok := got[0]["max_completion_tokens"]; ok {
|
|
field = "max_completion_tokens"
|
|
}
|
|
n, sent := got[0][field].(float64)
|
|
switch {
|
|
case c.want == 0 && (!sent || int(n) != 2000+24000):
|
|
t.Errorf("%s: %s %v, want %d", c.name, field, n, 2000+24000)
|
|
case c.want == -1 && sent:
|
|
t.Errorf("%s: %s %v sent, want none", c.name, field, n)
|
|
case c.want > 0 && int(n) != c.want:
|
|
t.Errorf("%s: %s %v, want %d", c.name, field, n, c.want)
|
|
}
|
|
}
|
|
}
|