diff --git a/api_test.go b/api_test.go index cb473fb..e8257db 100644 --- a/api_test.go +++ b/api_test.go @@ -59,7 +59,7 @@ func TestAPI(t *testing.T) { Model: GPT3Dot5Turbo, Messages: []ChatCompletionMessage{ { - Role: "user", + Role: ChatMessageRoleUser, Content: "Hello!", }, }, @@ -67,7 +67,25 @@ func TestAPI(t *testing.T) { ) if err != nil { - t.Errorf("CreateChatCompletion returned error: %v", err) + t.Errorf("CreateChatCompletion (without name) returned error: %v", err) + } + + _, err = c.CreateChatCompletion( + ctx, + ChatCompletionRequest{ + Model: GPT3Dot5Turbo, + Messages: []ChatCompletionMessage{ + { + Role: ChatMessageRoleUser, + Name: "John_Doe", + Content: "Hello!", + }, + }, + }, + ) + + if err != nil { + t.Errorf("CreateChatCompletion (with name) returned error: %v", err) } stream, err := c.CreateCompletionStream(ctx, CompletionRequest{ diff --git a/chat.go b/chat.go index 8f49769..cfa86b6 100644 --- a/chat.go +++ b/chat.go @@ -22,6 +22,12 @@ var ( type ChatCompletionMessage struct { Role string `json:"role"` Content string `json:"content"` + + // This property isn't in the official documentation, but it's in + // the documentation for the official library for python: + // - https://github.com/openai/openai-python/blob/main/chatml.md + // - https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb + Name string `json:"name,omitempty"` } // ChatCompletionRequest represents a request structure for chat completion API.