Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
henomis committed Dec 21, 2023
1 parent a766086 commit 284cfd8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 26 deletions.
22 changes: 10 additions & 12 deletions llm/openai/formatters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
})
}
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
})
}

Expand Down
24 changes: 10 additions & 14 deletions thread/thread.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ type ToolResponseData struct {
}

type ToolCallData struct {
ID string
Function ToolCallFunction
}

type ToolCallFunction struct {
ID string
Name string
Arguments string
}
Expand All @@ -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,
Expand Down Expand Up @@ -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"
}
}
}
Expand Down

0 comments on commit 284cfd8

Please sign in to comment.