From 284cfd8cbfea9af6e45505b7d653f20c6a94dbe5 Mon Sep 17 00:00:00 2001 From: Simone Vellei Date: Thu, 21 Dec 2023 11:36:58 +0100 Subject: [PATCH] fix --- llm/openai/formatters.go | 22 ++++++++++------------ thread/thread.go | 24 ++++++++++-------------- 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/llm/openai/formatters.go b/llm/openai/formatters.go index 192f1d83..d33823c6 100644 --- a/llm/openai/formatters.go +++ b/llm/openai/formatters.go @@ -28,15 +28,15 @@ func threadToChatCompletionMessages(t *thread.Thread) []openai.ChatCompletionMes case thread.RoleAssistant: if data, isAssistantTextData := message.Contents[0].Data.(string); isAssistantTextData { chatCompletionMessages[i].Content = data - } else if data, isTollCallData := message.Contents[0].Data.([]*thread.ToolCallData); isTollCallData { + } else if data, isTollCallData := message.Contents[0].Data.([]thread.ToolCallData); isTollCallData { var toolCalls []openai.ToolCall for _, toolCallData := range data { toolCalls = append(toolCalls, openai.ToolCall{ ID: toolCallData.ID, Type: "function", Function: openai.FunctionCall{ - Name: toolCallData.Function.Name, - Arguments: toolCallData.Function.Arguments, + Name: toolCallData.Name, + Arguments: toolCallData.Arguments, }, }) } @@ -45,7 +45,7 @@ func threadToChatCompletionMessages(t *thread.Thread) []openai.ChatCompletionMes continue } case thread.RoleTool: - if data, isTollResponseData := message.Contents[0].Data.(*thread.ToolResponseData); isTollResponseData { + if data, isTollResponseData := message.Contents[0].Data.(thread.ToolResponseData); isTollResponseData { chatCompletionMessages[i].ToolCallID = data.ID chatCompletionMessages[i].Name = data.Name chatCompletionMessages[i].Content = data.Result @@ -93,7 +93,7 @@ func threadContentsToChatMessageParts(m *thread.Message) []openai.ChatMessagePar func toolCallResultToThreadMessage(toolCall openai.ToolCall, result string) *thread.Message { return thread.NewToolMessage().AddContent( thread.NewToolResponseContent( - &thread.ToolResponseData{ + thread.ToolResponseData{ ID: toolCall.ID, Name: toolCall.Function.Name, Result: result, @@ -113,14 +113,12 @@ func toolCallsToToolCallMessage(toolCalls []openai.ToolCall) *thread.Message { return nil } - var toolCallData []*thread.ToolCallData + var toolCallData []thread.ToolCallData for _, toolCall := range toolCalls { - toolCallData = append(toolCallData, &thread.ToolCallData{ - ID: toolCall.ID, - Function: thread.ToolCallFunction{ - Name: toolCall.Function.Name, - Arguments: toolCall.Function.Arguments, - }, + toolCallData = append(toolCallData, thread.ToolCallData{ + ID: toolCall.ID, + Name: toolCall.Function.Name, + Arguments: toolCall.Function.Arguments, }) } diff --git a/thread/thread.go b/thread/thread.go index 356b0280..ca34c9c6 100644 --- a/thread/thread.go +++ b/thread/thread.go @@ -38,11 +38,7 @@ type ToolResponseData struct { } type ToolCallData struct { - ID string - Function ToolCallFunction -} - -type ToolCallFunction struct { + ID string Name string Arguments string } @@ -59,21 +55,21 @@ func NewTextContent(text string) *Content { } } -func NewImageContent(mediaData *MediaData) *Content { +func NewImageContent(mediaData MediaData) *Content { return &Content{ Type: ContentTypeImage, Data: mediaData, } } -func NewToolResponseContent(toolResponseData *ToolResponseData) *Content { +func NewToolResponseContent(toolResponseData ToolResponseData) *Content { return &Content{ Type: ContentTypeToolResponse, Data: toolResponseData, } } -func NewToolCallContent(data []*ToolCallData) *Content { +func NewToolCallContent(data []ToolCallData) *Content { return &Content{ Type: ContentTypeToolCall, Data: data, @@ -133,15 +129,15 @@ func (t *Thread) String() string { case ContentTypeImage: str += "\tImage URL: " + *content.Data.(*MediaData).URL + "\n" case ContentTypeToolCall: - for _, toolCallData := range content.Data.([]*ToolCallData) { + for _, toolCallData := range content.Data.([]ToolCallData) { str += "\tTool Call ID: " + toolCallData.ID + "\n" - str += "\tTool Call Function Name: " + toolCallData.Function.Name + "\n" - str += "\tTool Call Function Arguments: " + toolCallData.Function.Arguments + "\n" + str += "\tTool Call Function Name: " + toolCallData.Name + "\n" + str += "\tTool Call Function Arguments: " + toolCallData.Arguments + "\n" } case ContentTypeToolResponse: - str += "\tTool ID: " + content.Data.(*ToolResponseData).ID + "\n" - str += "\tTool Name: " + content.Data.(*ToolResponseData).Name + "\n" - str += "\tTool Result: " + content.Data.(*ToolResponseData).Result + "\n" + str += "\tTool ID: " + content.Data.(ToolResponseData).ID + "\n" + str += "\tTool Name: " + content.Data.(ToolResponseData).Name + "\n" + str += "\tTool Result: " + content.Data.(ToolResponseData).Result + "\n" } } }