mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-12-06 11:03:52 +00:00
Corrects passthrough metering, the cost gate, credential redaction, reload drain, response headers and the discovery cap.
34 lines
1.3 KiB
Go
34 lines
1.3 KiB
Go
package traefikllmgateway
|
|
|
|
import (
|
|
"io"
|
|
"net/http"
|
|
"testing"
|
|
)
|
|
|
|
func geminiThoughtsBody() string {
|
|
return `{"candidates":[{"content":{"parts":[{"text":"hi"}]}}],"usageMetadata":{"promptTokenCount":700,"candidatesTokenCount":60,"thoughtsTokenCount":29940},"modelVersion":"gemini-x"}`
|
|
}
|
|
|
|
func TestPassthroughGemini_ThoughtsTokensBilledAsCompletion(t *testing.T) {
|
|
gw := newResidualGateway(t, providerTypeGemini, "gemini-x", jsonUpstream(geminiThoughtsBody))
|
|
residualPost(gw, "/up/v1beta/models/gemini-x:generateContent", `{"contents":[]}`)
|
|
in, out := residualCounters(gw)
|
|
if in != residualPrompt || out != residualCompletion {
|
|
t.Fatalf("tokens in/out = %d/%d, want %d/%d", in, out, residualPrompt, residualCompletion)
|
|
}
|
|
}
|
|
|
|
func TestPassthroughGeminiSSE_ThoughtsTokensBilledAsCompletion(t *testing.T) {
|
|
gw := newResidualGateway(t, providerTypeGemini, "gemini-x", func(w http.ResponseWriter, r *http.Request) {
|
|
_, _ = io.Copy(io.Discard, r.Body)
|
|
w.Header().Set("Content-Type", "text/event-stream")
|
|
_, _ = io.WriteString(w, "data: "+geminiThoughtsBody()+"\n\n")
|
|
})
|
|
residualPost(gw, "/up/v1beta/models/gemini-x:streamGenerateContent?alt=sse", `{"contents":[]}`)
|
|
in, out := residualCounters(gw)
|
|
if in != residualPrompt || out != residualCompletion {
|
|
t.Fatalf("tokens in/out = %d/%d, want %d/%d", in, out, residualPrompt, residualCompletion)
|
|
}
|
|
}
|