mirror of
https://github.com/coalaura/whiskr.git
synced 2025-12-02 20:22:52 +00:00
reuse buffers
This commit is contained in:
12
chat.go
12
chat.go
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user