-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathcontext_overflow.go
More file actions
33 lines (30 loc) · 1.11 KB
/
Copy pathcontext_overflow.go
File metadata and controls
33 lines (30 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package cogito
import "strings"
// contextOverflowMarkers are fragments of the errors backends return when a
// request does not fit the model's context window:
//
// - llama.cpp / LocalAI: "request (9739 tokens) exceeds the available context size (8192 tokens), try increasing it"
// - OpenAI / vLLM: "This model's maximum context length is 8192 tokens. However, ..."
// - OpenAI error code: "context_length_exceeded"
// - Anthropic: "prompt is too long: 210000 tokens > 200000 maximum"
var contextOverflowMarkers = []string{
"exceeds the available context size",
"maximum context length",
"context_length_exceeded",
"prompt is too long",
}
// isContextOverflowError reports whether err says the request did not fit the
// model's context window. Such a request fails the same way on every attempt,
// so the decision loops return it at once instead of retrying with backoff.
func isContextOverflowError(err error) bool {
if err == nil {
return false
}
msg := strings.ToLower(err.Error())
for _, marker := range contextOverflowMarkers {
if strings.Contains(msg, marker) {
return true
}
}
return false
}