From 341e551da61710772a18a689df627143f3e89881 Mon Sep 17 00:00:00 2001 From: Jeff Huang Date: Fri, 21 Jun 2024 10:00:08 -0700 Subject: [PATCH] Use strings.builder --- go/plugins/ollama/ollama.go | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/go/plugins/ollama/ollama.go b/go/plugins/ollama/ollama.go index 03816fb5c..4d76595fa 100644 --- a/go/plugins/ollama/ollama.go +++ b/go/plugins/ollama/ollama.go @@ -23,6 +23,7 @@ import ( "fmt" "io" "net/http" + "strings" "time" "github.com/firebase/genkit/go/ai" @@ -325,19 +326,15 @@ func translateGenerateChunk(input string) (*ai.GenerateResponseChunk, error) { // concatMessages translates a list of messages into a prompt-style format func concatMessages(input *ai.GenerateRequest, roles []ai.Role) string { - prompt := "" roleSet := make(map[ai.Role]bool) - for _, role := range roles { roleSet[role] = true } - + var sb strings.Builder // Create a strings.Builder instance for _, message := range input.Messages { - if roleSet[message.Role] { - for _, part := range message.Content { - prompt += part.Text - } + for _, part := range message.Content { + sb.WriteString(part.Text) // Write the text directly to the builder } } - return prompt + return sb.String() // Get the final concatenated string }