1
0
mirror of https://github.com/coalaura/whiskr.git synced 2025-12-02 20:22:52 +00:00

reuse buffers

This commit is contained in:
Laura
2025-08-31 23:46:22 +02:00
parent 2d65c2f484
commit db138324fa
7 changed files with 50 additions and 34 deletions

12
chat.go
View File

@@ -357,11 +357,13 @@ func RunCompletion(ctx context.Context, response *Stream, request *openrouter.Ch
defer stream.Close()
var (
id string
result strings.Builder
tool *ToolCall
id string
tool *ToolCall
)
buf := GetFreeBuffer()
defer pool.Put(buf)
for {
chunk, err := stream.Recv()
if err != nil {
@@ -409,7 +411,7 @@ func RunCompletion(ctx context.Context, response *Stream, request *openrouter.Ch
content := choice.Delta.Content
if content != "" {
result.WriteString(content)
buf.WriteString(content)
response.Send(TextChunk(content))
} else if choice.Delta.Reasoning != nil {
@@ -417,7 +419,7 @@ func RunCompletion(ctx context.Context, response *Stream, request *openrouter.Ch
}
}
return tool, result.String(), nil
return tool, buf.String(), nil
}
func SplitImagePairs(text string) []openrouter.ChatMessagePart {