Classify LLM context length errors
This commit is contained in:
@@ -207,6 +207,8 @@ func classifyLLMError(err error) string {
|
|||||||
return "timeout"
|
return "timeout"
|
||||||
case strings.Contains(s, "connection refused") || strings.Contains(s, "connection reset") || strings.Contains(s, "no route to host") || strings.Contains(s, "llm http 5"):
|
case strings.Contains(s, "connection refused") || strings.Contains(s, "connection reset") || strings.Contains(s, "no route to host") || strings.Contains(s, "llm http 5"):
|
||||||
return "model_unavailable"
|
return "model_unavailable"
|
||||||
|
case strings.Contains(s, "maximum context length") || strings.Contains(s, "context length") || strings.Contains(s, "input_tokens"):
|
||||||
|
return "context_length"
|
||||||
case strings.Contains(s, "llm http 4") || strings.Contains(s, "messages are required"):
|
case strings.Contains(s, "llm http 4") || strings.Contains(s, "messages are required"):
|
||||||
return "bad_input"
|
return "bad_input"
|
||||||
case strings.Contains(s, "llm decode") || strings.Contains(s, "empty choices"):
|
case strings.Contains(s, "llm decode") || strings.Contains(s, "empty choices"):
|
||||||
|
|||||||
29
internal/worker/worker_test.go
Normal file
29
internal/worker/worker_test.go
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package worker
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestClassifyLLMError(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
err error
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{name: "timeout", err: errors.New("context deadline exceeded"), want: "timeout"},
|
||||||
|
{name: "unavailable", err: errors.New("llm HTTP 500: internal server error"), want: "model_unavailable"},
|
||||||
|
{name: "context length", err: errors.New("This model's maximum context length is 16384 tokens. input_tokens=16001"), want: "context_length"},
|
||||||
|
{name: "bad input", err: errors.New("llm HTTP 400: messages are required"), want: "bad_input"},
|
||||||
|
{name: "bad response", err: errors.New("llm decode: invalid character '<'"), want: "bad_response"},
|
||||||
|
{name: "unknown", err: errors.New("strange failure"), want: "unknown"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
if got := classifyLLMError(tt.err); got != tt.want {
|
||||||
|
t.Fatalf("classifyLLMError() = %q, want %q", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user