mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
fix(providers): improve context overflow detection and classification
This commit is contained in:
@@ -1949,6 +1949,7 @@ turnLoop:
|
||||
|
||||
isContextError := !isTimeoutError && (strings.Contains(errMsg, "context_length_exceeded") ||
|
||||
strings.Contains(errMsg, "context window") ||
|
||||
strings.Contains(errMsg, "context_window") ||
|
||||
strings.Contains(errMsg, "maximum context length") ||
|
||||
strings.Contains(errMsg, "token limit") ||
|
||||
strings.Contains(errMsg, "too many tokens") ||
|
||||
|
||||
@@ -84,6 +84,15 @@ var (
|
||||
substr("messages.1.content.1.tool_use.id"),
|
||||
substr("invalid request format"),
|
||||
}
|
||||
contextOverflowPatterns = []errorPattern{
|
||||
rxp(`context[_ ]?length[_ ]?exceeded`),
|
||||
rxp(`context[_ ]?window[_ ]?exceeded`),
|
||||
substr("maximum context length"),
|
||||
substr("token limit"),
|
||||
substr("too many tokens"),
|
||||
substr("prompt is too long"),
|
||||
substr("request too large"),
|
||||
}
|
||||
|
||||
imageDimensionPatterns = []errorPattern{
|
||||
rxp(`image dimensions exceed max`),
|
||||
@@ -201,6 +210,9 @@ func classifyByMessage(msg string) FailoverReason {
|
||||
if matchesAny(msg, formatPatterns) {
|
||||
return FailoverFormat
|
||||
}
|
||||
if matchesAny(msg, contextOverflowPatterns) {
|
||||
return FailoverContextOverflow
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
|
||||
@@ -71,13 +71,14 @@ type NativeSearchCapable interface {
|
||||
type FailoverReason string
|
||||
|
||||
const (
|
||||
FailoverAuth FailoverReason = "auth"
|
||||
FailoverRateLimit FailoverReason = "rate_limit"
|
||||
FailoverBilling FailoverReason = "billing"
|
||||
FailoverTimeout FailoverReason = "timeout"
|
||||
FailoverFormat FailoverReason = "format"
|
||||
FailoverOverloaded FailoverReason = "overloaded"
|
||||
FailoverUnknown FailoverReason = "unknown"
|
||||
FailoverAuth FailoverReason = "auth"
|
||||
FailoverRateLimit FailoverReason = "rate_limit"
|
||||
FailoverBilling FailoverReason = "billing"
|
||||
FailoverTimeout FailoverReason = "timeout"
|
||||
FailoverFormat FailoverReason = "format"
|
||||
FailoverContextOverflow FailoverReason = "context_overflow"
|
||||
FailoverOverloaded FailoverReason = "overloaded"
|
||||
FailoverUnknown FailoverReason = "unknown"
|
||||
)
|
||||
|
||||
// FailoverError wraps an LLM provider error with classification metadata.
|
||||
@@ -101,7 +102,7 @@ func (e *FailoverError) Unwrap() error {
|
||||
// IsRetriable returns true if this error should trigger fallback to next candidate.
|
||||
// Non-retriable: Format errors (bad request structure, image dimension/size).
|
||||
func (e *FailoverError) IsRetriable() bool {
|
||||
return e.Reason != FailoverFormat
|
||||
return e.Reason != FailoverFormat && e.Reason != FailoverContextOverflow
|
||||
}
|
||||
|
||||
// ModelConfig holds primary model and fallback list.
|
||||
|
||||
Reference in New Issue
Block a user