Skip to content
Open
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
20 changes: 11 additions & 9 deletions anthropic.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func MessagesToAnthropic(messages []Message) ([]anthropic.MessageParam, []anthro

for _, message := range messages {
role := anthropic.MessageParamRoleAssistant
content := []anthropic.ContentBlockParamUnion{}
var content []anthropic.ContentBlockParamUnion

switch message.Role {
case "system":
Expand Down Expand Up @@ -106,7 +106,7 @@ func MessagesToAnthropic(messages []Message) ([]anthropic.MessageParam, []anthro
})
content = nil

resultContent := []anthropic.ToolResultBlockParamContentUnion{}
var resultContent []anthropic.ToolResultBlockParamContentUnion
resultParts, err := toolResultToParts(part.ToolInvocation.Result)
if err != nil {
return nil, nil, fmt.Errorf("failed to convert tool call result to parts: %w", err)
Expand Down Expand Up @@ -207,13 +207,15 @@ func MessagesToAnthropic(messages []Message) ([]anthropic.MessageParam, []anthro
// AnthropicToDataStream pipes an Anthropic stream to a DataStream.
func AnthropicToDataStream(stream *ssestream.Stream[anthropic.MessageStreamEventUnion]) DataStream {
return func(yield func(DataStreamPart, error) bool) {
var lastChunk *anthropic.MessageStreamEventUnion
var finalReason FinishReason = FinishReasonUnknown
var finalUsage Usage
var currentToolCall struct {
ID string
Args string
}
var (
lastChunk *anthropic.MessageStreamEventUnion
finalReason = FinishReasonUnknown
finalUsage Usage
currentToolCall struct {
ID string
Args string
}
)

for stream.Next() {
chunk := stream.Current()
Expand Down
2 changes: 1 addition & 1 deletion google.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type GoogleStreamIterator interface {
}

func ToolsToGoogle(tools []Tool) ([]*genai.Tool, error) {
functionDeclarations := []*genai.FunctionDeclaration{}
functionDeclarations := make([]*genai.FunctionDeclaration, 0, len(tools))

var propertyToSchema func(property map[string]any) (*genai.Schema, error)
propertyToSchema = func(property map[string]any) (*genai.Schema, error) {
Expand Down
2 changes: 1 addition & 1 deletion openai.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

// ToolsToOpenAI converts the tool format to OpenAI's API format.
func ToolsToOpenAI(tools []Tool) []openai.ChatCompletionToolParam {
openaiTools := []openai.ChatCompletionToolParam{}
openaiTools := make([]openai.ChatCompletionToolParam, len(tools))
for _, tool := range tools {
var schemaParams map[string]any
if tool.Schema.Properties != nil {
Expand Down
2 changes: 1 addition & 1 deletion stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ type Part struct {

// Type: "step-start" - No additional fields

isComplete bool `json:"-"` // Internal accumulator tracking
isComplete bool // Internal accumulator tracking
}

type Tool struct {
Expand Down