mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-11-27 10:16:34 +00:00
fix(router): send the head of the system prompt and ask to the decision model
The decision state now holds the first 1024 bytes of the system prompt and the first 8192 bytes of the newest ask, cut at a character boundary. The classifier scoring inputs stay the same.
This commit is contained in:
+27
-15
@@ -76,20 +76,20 @@ type smartFeatures struct {
|
||||
// prose is the ask without fenced code and paste paragraphs; lower is its lowercase form.
|
||||
prose, lower string
|
||||
system string
|
||||
// ask is the raw newest ask, bounded, for the decision model.
|
||||
ask string
|
||||
intent int
|
||||
hard int
|
||||
codeBytes int
|
||||
logBytes int
|
||||
msgCount int
|
||||
questions int
|
||||
toolSeen int
|
||||
lists int
|
||||
promptBytes int
|
||||
outTokens int64
|
||||
jsonMode int
|
||||
nonLatin bool
|
||||
// sysHead and ask are raw heads of the system text and newest ask, for the decision model.
|
||||
sysHead, ask string
|
||||
intent int
|
||||
hard int
|
||||
codeBytes int
|
||||
logBytes int
|
||||
msgCount int
|
||||
questions int
|
||||
toolSeen int
|
||||
lists int
|
||||
promptBytes int
|
||||
outTokens int64
|
||||
jsonMode int
|
||||
nonLatin bool
|
||||
// foreign marks prose the English markers cannot classify.
|
||||
foreign bool
|
||||
truncated bool
|
||||
@@ -145,6 +145,7 @@ func extractSmartV2(req map[string]any, endpoint string) smartFeatures {
|
||||
}
|
||||
}
|
||||
}
|
||||
f.sysHead = smartRuneHead(f.system, decisionSystemCap)
|
||||
f.system = boundSmartText(f.system, smartSystemCap)
|
||||
|
||||
ask := f.findAsk(msgs)
|
||||
@@ -152,12 +153,23 @@ func extractSmartV2(req map[string]any, endpoint string) smartFeatures {
|
||||
f.truncated = len(msgs) > smartAskScanMax
|
||||
return f
|
||||
}
|
||||
f.ask = boundSmartText(ask, smartTextCap)
|
||||
f.ask = smartRuneHead(ask, decisionAskCap)
|
||||
f.splitAsk(ask)
|
||||
f.classifyIntent()
|
||||
return f
|
||||
}
|
||||
|
||||
// smartRuneHead returns the first limit bytes of s, moved back to a rune start.
|
||||
func smartRuneHead(s string, limit int) string {
|
||||
if len(s) <= limit {
|
||||
return s
|
||||
}
|
||||
for limit > 0 && !utf8.RuneStart(s[limit]) {
|
||||
limit--
|
||||
}
|
||||
return s[:limit]
|
||||
}
|
||||
|
||||
// findAsk scans newest first for the user message that carries text and no tool
|
||||
// parts, and records tool-loop state on the way. It avoids `continue` inside the
|
||||
// switch: yaegi v0.16.1 ends the whole loop there.
|
||||
|
||||
Reference in New Issue
Block a user