Skip to content

Commit

Permalink
add "name" property for ChatCompletionMessage (sashabaranov#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
fussraider authored Mar 6, 2023
1 parent 71f9f15 commit c5fe874
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
22 changes: 20 additions & 2 deletions api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,33 @@ func TestAPI(t *testing.T) {
Model: GPT3Dot5Turbo,
Messages: []ChatCompletionMessage{
{
Role: "user",
Role: ChatMessageRoleUser,
Content: "Hello!",
},
},
},
)

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{
Expand Down
6 changes: 6 additions & 0 deletions chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit c5fe874

Please sign in to comment.