Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
greysteil committed Sep 2, 2024
1 parent 3058f9e commit 39fa8a2
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions chat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,28 @@ func TestMultipartChatMessageSerialization(t *testing.T) {
}
}

func TestToolCallChatMessageSerialization(t *testing.T) {
jsonText := `{"role":"assistant","tool_calls":[{"id":"123","type":"function","function":{"name":"my_func","arguments":"{}"}}]}`

Check failure on line 429 in chat_test.go

View workflow job for this annotation

GitHub Actions / Sanity check

the line is 128 characters long, which exceeds the maximum of 120 characters. (lll)

toolCallMsg := openai.ChatCompletionMessage{
Role: openai.ChatMessageRoleAssistant,
ToolCalls: []openai.ToolCall{{
ID: "123",
Type: openai.ToolTypeFunction,
Function: openai.FunctionCall{Name: "my_func", Arguments: "{}"},
}},
}

s, err := json.Marshal(toolCallMsg)
if err != nil {
t.Fatalf("Expected no error: %s", err)
}
res := strings.ReplaceAll(string(s), " ", "")
if res != jsonText {
t.Fatalf("invalid message: %s", string(s))
}
}

// handleChatCompletionEndpoint Handles the ChatGPT completion endpoint by the test server.
func handleChatCompletionEndpoint(w http.ResponseWriter, r *http.Request) {
var err error
Expand Down

0 comments on commit 39fa8a2

Please sign in to comment.