Skip to content

Commit

Permalink
Use strings.builder
Browse files Browse the repository at this point in the history
  • Loading branch information
huangjeff5 committed Jun 21, 2024
1 parent ff94eb1 commit 341e551
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions go/plugins/ollama/ollama.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"fmt"
"io"
"net/http"
"strings"
"time"

"github.com/firebase/genkit/go/ai"
Expand Down Expand Up @@ -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
}

0 comments on commit 341e551

Please sign in to comment.