Skip to content

Commit c5fe874

Browse files
authored
add "name" property for ChatCompletionMessage (#123)
1 parent 71f9f15 commit c5fe874

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

api_test.go

+20-2
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,33 @@ func TestAPI(t *testing.T) {
5959
Model: GPT3Dot5Turbo,
6060
Messages: []ChatCompletionMessage{
6161
{
62-
Role: "user",
62+
Role: ChatMessageRoleUser,
6363
Content: "Hello!",
6464
},
6565
},
6666
},
6767
)
6868

6969
if err != nil {
70-
t.Errorf("CreateChatCompletion returned error: %v", err)
70+
t.Errorf("CreateChatCompletion (without name) returned error: %v", err)
71+
}
72+
73+
_, err = c.CreateChatCompletion(
74+
ctx,
75+
ChatCompletionRequest{
76+
Model: GPT3Dot5Turbo,
77+
Messages: []ChatCompletionMessage{
78+
{
79+
Role: ChatMessageRoleUser,
80+
Name: "John_Doe",
81+
Content: "Hello!",
82+
},
83+
},
84+
},
85+
)
86+
87+
if err != nil {
88+
t.Errorf("CreateChatCompletion (with name) returned error: %v", err)
7189
}
7290

7391
stream, err := c.CreateCompletionStream(ctx, CompletionRequest{

chat.go

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ var (
2222
type ChatCompletionMessage struct {
2323
Role string `json:"role"`
2424
Content string `json:"content"`
25+
26+
// This property isn't in the official documentation, but it's in
27+
// the documentation for the official library for python:
28+
// - https://github.com/openai/openai-python/blob/main/chatml.md
29+
// - https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb
30+
Name string `json:"name,omitempty"`
2531
}
2632

2733
// ChatCompletionRequest represents a request structure for chat completion API.

0 commit comments

Comments
 (0)