-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cli): serverless ctx mock pkg move bug (#827)
# Description 1. Move `MockContext` back to `serverless/mock` package. 2. Change function signature from `ReadLLMFunctionCall(fnCall any) error` to `ReadLLMFunctionCall() (*ai.FunctionCall, error)`, This can avoid type missing.
- Loading branch information
Showing
12 changed files
with
209 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package ai | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/sashabaranov/go-openai" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestConvertToInvokeResponse(t *testing.T) { | ||
type args struct { | ||
res *openai.ChatCompletionResponse | ||
tcs map[uint32]openai.Tool | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
expected *InvokeResponse | ||
}{ | ||
{ | ||
name: "tool_calls", | ||
args: args{ | ||
res: &openai.ChatCompletionResponse{ | ||
Choices: []openai.ChatCompletionChoice{ | ||
{ | ||
Index: 0, | ||
Message: openai.ChatCompletionMessage{ | ||
Role: "user", | ||
Content: "How is the weather today?", | ||
ToolCalls: []openai.ToolCall{ | ||
{ | ||
Type: openai.ToolTypeFunction, | ||
Function: openai.FunctionCall{Name: "get-weather"}, | ||
}, | ||
}, | ||
ToolCallID: "9TWd1eA2K3rmmtC21oER2a9F0YZif", | ||
}, | ||
FinishReason: openai.FinishReasonToolCalls, | ||
}, | ||
}, | ||
Usage: openai.Usage{ | ||
PromptTokens: 50, | ||
CompletionTokens: 100, | ||
TotalTokens: 150, | ||
}, | ||
}, | ||
tcs: map[uint32]openai.Tool{ | ||
9: { | ||
Type: openai.ToolTypeFunction, | ||
Function: &openai.FunctionDefinition{Name: "get-weather"}, | ||
}, | ||
}, | ||
}, | ||
expected: &InvokeResponse{ | ||
Content: "How is the weather today?", | ||
ToolCalls: map[uint32][]*openai.ToolCall{ | ||
9: { | ||
{Type: openai.ToolTypeFunction, Function: openai.FunctionCall{Name: "get-weather"}}, | ||
}, | ||
}, | ||
FinishReason: "tool_calls", | ||
TokenUsage: TokenUsage{PromptTokens: 50, CompletionTokens: 100}, | ||
AssistantMessage: openai.ChatCompletionMessage{ | ||
Role: "user", | ||
Content: "How is the weather today?", | ||
ToolCalls: []openai.ToolCall{ | ||
{Type: openai.ToolTypeFunction, Function: openai.FunctionCall{Name: "get-weather"}}, | ||
}, | ||
ToolCallID: "9TWd1eA2K3rmmtC21oER2a9F0YZif", | ||
}, | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
actual, _ := ConvertToInvokeResponse(tt.args.res, tt.args.tcs) | ||
assert.Equal(t, tt.expected, actual) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.