Skip to content

Commit 39fa8a2

Browse files
committed
Add unit test
1 parent 3058f9e commit 39fa8a2

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

chat_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,28 @@ func TestMultipartChatMessageSerialization(t *testing.T) {
425425
}
426426
}
427427

428+
func TestToolCallChatMessageSerialization(t *testing.T) {
429+
jsonText := `{"role":"assistant","tool_calls":[{"id":"123","type":"function","function":{"name":"my_func","arguments":"{}"}}]}`
430+
431+
toolCallMsg := openai.ChatCompletionMessage{
432+
Role: openai.ChatMessageRoleAssistant,
433+
ToolCalls: []openai.ToolCall{{
434+
ID: "123",
435+
Type: openai.ToolTypeFunction,
436+
Function: openai.FunctionCall{Name: "my_func", Arguments: "{}"},
437+
}},
438+
}
439+
440+
s, err := json.Marshal(toolCallMsg)
441+
if err != nil {
442+
t.Fatalf("Expected no error: %s", err)
443+
}
444+
res := strings.ReplaceAll(string(s), " ", "")
445+
if res != jsonText {
446+
t.Fatalf("invalid message: %s", string(s))
447+
}
448+
}
449+
428450
// handleChatCompletionEndpoint Handles the ChatGPT completion endpoint by the test server.
429451
func handleChatCompletionEndpoint(w http.ResponseWriter, r *http.Request) {
430452
var err error

0 commit comments

Comments
 (0)