mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-12-06 11:03:52 +00:00
A thinking model spends a small max_tokens on reasoning and returns empty
content with finish_reason length. TensorFold on the d1 DeepSeek server
warns about this and suggests chat_template_kwargs enable_thinking false.
providers.<name>.thinking.offBelowMaxTokens (openai type, default off)
adds chat_template_kwargs: {"enable_thinking": false} to the upstream
body when a chat request caps its output under the value. It also does
this when /v1/messages translates a request for that provider. A request
with no cap, a cap at or above the value, or its own thinking choice
(reasoning_effort, reasoning, thinking, enable_thinking, or
chat_template_kwargs.enable_thinking or .thinking) is not changed. Other
client chat_template_kwargs keys are kept, and the client's map is not
modified. The response cache still keys on the client body.
64 lines
2.6 KiB
Go
64 lines
2.6 KiB
Go
package traefikllmgateway
|
|
|
|
import (
|
|
"reflect"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// nonSecretConfigKeys lists every string-valued JSON key in Config reviewed as
|
|
// non-secret. A new key must be classified here or in the redaction sets.
|
|
var nonSecretConfigKeys = map[string]bool{
|
|
"agents": true, "anonymousGroup": true, "promptCache": true, "inject": true, "key": true, "thinking": true, "offBelowMaxTokens": true, "allowedCIDRs": true, "backoff": true, "cacheTTL": true, "maxDelay": true,
|
|
"card": true, "discoveryInterval": true, "file": true, "group": true,
|
|
"groups": true, "maxOpenDuration": true, "mcpServers": true,
|
|
"kinds": true, "limitExemptKinds": true, "metadataPath": true, "modelAliases": true, "modelBaseUrls": true, "models": true, "name": true,
|
|
"openDuration": true, "passthroughPaths": true, "path": true, "pathBaseUrls": true,
|
|
"probeInterval": true, "providers": true, "requestTimeout": true,
|
|
"ttl": true, "type": true,
|
|
"cachedInputPerM": true, "cacheWritePerM": true, "defaultTier": true, "toolsMinTier": true, "classifier": true, "shadowClassifier": true, "intentTiers": true, "keywords": true, "selection": true, "tier": true, "header": true, "mode": true, "firstByteTimeout": true, "provider": true, "timeout": true, "sharedState": true,
|
|
}
|
|
|
|
func collectStringKeys(t reflect.Type, seen map[reflect.Type]bool, out map[string]bool) {
|
|
for t.Kind() == reflect.Pointer || t.Kind() == reflect.Slice || t.Kind() == reflect.Array || t.Kind() == reflect.Map {
|
|
t = t.Elem()
|
|
}
|
|
if t.Kind() != reflect.Struct || seen[t] {
|
|
return
|
|
}
|
|
seen[t] = true
|
|
for i := 0; i < t.NumField(); i++ {
|
|
f := t.Field(i)
|
|
tag := strings.Split(f.Tag.Get("json"), ",")[0]
|
|
if tag == "-" || !f.IsExported() {
|
|
continue
|
|
}
|
|
if tag == "" {
|
|
tag = f.Name
|
|
}
|
|
ft := f.Type
|
|
for ft.Kind() == reflect.Pointer || ft.Kind() == reflect.Slice || ft.Kind() == reflect.Array || ft.Kind() == reflect.Map {
|
|
ft = ft.Elem()
|
|
}
|
|
if ft.Kind() == reflect.String {
|
|
out[tag] = true
|
|
}
|
|
collectStringKeys(ft, seen, out)
|
|
}
|
|
}
|
|
|
|
func TestRedaction_EveryStringKeyClassified(t *testing.T) {
|
|
keys := map[string]bool{}
|
|
collectStringKeys(reflect.TypeOf(Config{}), map[reflect.Type]bool{}, keys)
|
|
for k := range keys {
|
|
if !redactedConfigKeys[k] && !hiddenConfigKeys[k] && !baseURLLikeConfigKeys[k] && !nonSecretConfigKeys[k] {
|
|
t.Errorf("Config string key %q is unclassified: add it to the redaction sets or nonSecretConfigKeys", k)
|
|
}
|
|
}
|
|
for k := range nonSecretConfigKeys {
|
|
if redactedConfigKeys[k] || hiddenConfigKeys[k] || baseURLLikeConfigKeys[k] {
|
|
t.Errorf("key %q is both redacted and declared non-secret", k)
|
|
}
|
|
}
|
|
}
|