Context refusal in llama-server's exceed_context_size_error shape; README for v2.3
Implemented-By: OpenCode session (model recorded in docs/implementer-log.md)
This commit is contained in:
@@ -84,15 +84,31 @@ func TestOversizedPromptWithNoFitIs400(t *testing.T) {
|
||||
if resp.StatusCode != http.StatusBadRequest {
|
||||
t.Fatalf("status %d body %s, want 400", resp.StatusCode, body)
|
||||
}
|
||||
var e map[string]any
|
||||
if err := json.Unmarshal([]byte(body), &e); err != nil || e["error"] != "prompt too large" {
|
||||
t.Fatalf("body = %s, want error 'prompt too large'", body)
|
||||
// v2.3: llama-server's own shape for this error, so a client handles crossbar's refusal the
|
||||
// way it handles the server's (Boxmaker keys on error.type; the error JSON must come first).
|
||||
if !strings.HasPrefix(body, `{"error":`) {
|
||||
t.Errorf("body must start with the error object: %s", body)
|
||||
}
|
||||
if est, _ := e["estimate"].(float64); est < 8000 || est > 13000 {
|
||||
t.Errorf("estimate = %v, want roughly 10000 tokens", e["estimate"])
|
||||
var e struct {
|
||||
Error struct {
|
||||
Code int `json:"code"`
|
||||
Type string `json:"type"`
|
||||
Message string `json:"message"`
|
||||
NPromptTokens float64 `json:"n_prompt_tokens"`
|
||||
NCtx float64 `json:"n_ctx"`
|
||||
} `json:"error"`
|
||||
}
|
||||
if max, _ := e["max"].(float64); max != 4096 {
|
||||
t.Errorf("max = %v, want the largest per-slot context among the route's hosts (4096)", e["max"])
|
||||
if err := json.Unmarshal([]byte(body), &e); err != nil || e.Error.Code != 400 || e.Error.Type != "exceed_context_size_error" || e.Error.Message != "prompt too large" {
|
||||
t.Fatalf("body = %s, want {\"error\":{\"code\":400,\"type\":\"exceed_context_size_error\",\"message\":\"prompt too large\",…}}", body)
|
||||
}
|
||||
if est := e.Error.NPromptTokens; est < 8000 || est > 13000 {
|
||||
t.Errorf("n_prompt_tokens = %v, want roughly 10000 tokens", est)
|
||||
}
|
||||
if max := e.Error.NCtx; max != 4096 {
|
||||
t.Errorf("n_ctx = %v, want the largest per-slot context among the route's hosts (4096)", max)
|
||||
}
|
||||
if ct := resp.Header.Get("Content-Type"); !strings.HasPrefix(ct, "application/json") {
|
||||
t.Errorf("Content-Type = %q, want application/json", ct)
|
||||
}
|
||||
if small.hits.Load()+tiny.hits.Load() != 0 {
|
||||
t.Errorf("a refused prompt must not reach any upstream")
|
||||
|
||||
Reference in New Issue
Block a user