mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-10-20 05:56:56 +00:00
perf(anthropic): build text-delta stream chunks without envelope maps
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package traefikllmgateway
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
@@ -1127,3 +1128,18 @@ func TestOpenAIRequestFromAnthropic_NoTools_OmitsToolsAndToolChoiceFields(t *tes
|
||||
t.Errorf(`out["tool_choice"] = %v, want the key absent when no tool_choice was requested`, out["tool_choice"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestAnthropicContentChunkMatchesChunk(t *testing.T) {
|
||||
texts := []string{"", "Hello", "a \"quoted\" <b>&</b>", "line\nbreak\ttab", "unicode é 日本 \u2028\u2029", "bad\xffutf8"}
|
||||
for _, id := range []string{"", "msg_01", "we\"ird"} {
|
||||
st := newAnthropicStreamState("gw-model", 1734000000)
|
||||
st.id = id
|
||||
for _, text := range texts {
|
||||
got := st.contentChunk(text)
|
||||
want := st.chunk(map[string]any{"content": text}, nil)
|
||||
if !bytes.Equal(got, want) {
|
||||
t.Errorf("id=%q text=%q:\n got %s\nwant %s", id, text, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user