Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func buildSystemBlocks(call *lipapi.Call) []anthropic.TextBlockParam {
}

func buildAnthropicMessages(call *lipapi.Call) ([]anthropic.MessageParam, error) {
var out []anthropic.MessageParam
out := make([]anthropic.MessageParam, 0, len(call.Messages))
for _, m := range call.Messages {
if m.Role == lipapi.RoleSystem {
continue
Expand Down Expand Up @@ -170,7 +170,7 @@ func assistantMessageParam(m lipapi.Message) (anthropic.MessageParam, error) {
return anthropic.MessageParam{}, fmt.Errorf("anthropic: assistant message may only contain text parts in this adapter")
}
}
var blocks []anthropic.ContentBlockParamUnion
blocks := make([]anthropic.ContentBlockParamUnion, 0, len(m.Parts))
for _, p := range m.Parts {
if strings.TrimSpace(p.Text) == "" {
continue
Expand All @@ -184,7 +184,7 @@ func assistantMessageParam(m lipapi.Message) (anthropic.MessageParam, error) {
}

func userPartsToBlocks(parts []lipapi.Part) ([]anthropic.ContentBlockParamUnion, error) {
var out []anthropic.ContentBlockParamUnion
out := make([]anthropic.ContentBlockParamUnion, 0, len(parts))
for _, p := range parts {
switch p.Kind {
case lipapi.PartText:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package anthropicmessages

import (
"testing"

"github.com/matdev83/go-llm-interactive-proxy/pkg/lipapi"
)

func BenchmarkUserPartsToBlocks(b *testing.B) {
parts := make([]lipapi.Part, 100)
for i := range 100 {
parts[i] = lipapi.Part{
Kind: lipapi.PartText,
Text: "Hello, world!",
}
}

b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _ = userPartsToBlocks(parts)
}
}