Skip to content

Commit 45aa996

Browse files
authored
Make "Content" field in "ChatCompletionMessage" omitempty (#926)
1 parent 9823a8b commit 45aa996

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

chat.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ type ChatMessagePart struct {
9393

9494
type ChatCompletionMessage struct {
9595
Role string `json:"role"`
96-
Content string `json:"content"`
96+
Content string `json:"content,omitempty"`
9797
Refusal string `json:"refusal,omitempty"`
9898
MultiContent []ChatMessagePart
9999

@@ -132,7 +132,7 @@ func (m ChatCompletionMessage) MarshalJSON() ([]byte, error) {
132132

133133
msg := struct {
134134
Role string `json:"role"`
135-
Content string `json:"content"`
135+
Content string `json:"content,omitempty"`
136136
Refusal string `json:"refusal,omitempty"`
137137
MultiContent []ChatMessagePart `json:"-"`
138138
Name string `json:"name,omitempty"`
@@ -146,7 +146,7 @@ func (m ChatCompletionMessage) MarshalJSON() ([]byte, error) {
146146
func (m *ChatCompletionMessage) UnmarshalJSON(bs []byte) error {
147147
msg := struct {
148148
Role string `json:"role"`
149-
Content string `json:"content"`
149+
Content string `json:"content,omitempty"`
150150
Refusal string `json:"refusal,omitempty"`
151151
MultiContent []ChatMessagePart
152152
Name string `json:"name,omitempty"`

chat_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ func TestMultipartChatMessageSerialization(t *testing.T) {
631631
t.Fatalf("Unexpected error")
632632
}
633633
res = strings.ReplaceAll(string(s), " ", "")
634-
if res != `{"role":"user","content":""}` {
634+
if res != `{"role":"user"}` {
635635
t.Fatalf("invalid message: %s", string(s))
636636
}
637637
}

openai_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func setupAzureTestServer() (client *openai.Client, server *test.ServerTest, tea
2929

3030
// numTokens Returns the number of GPT-3 encoded tokens in the given text.
3131
// This function approximates based on the rule of thumb stated by OpenAI:
32-
// https://beta.openai.com/tokenizer
32+
// https://beta.openai.com/tokenizer/
3333
//
3434
// TODO: implement an actual tokenizer for GPT-3 and Codex (once available).
3535
func numTokens(s string) int {

0 commit comments

Comments
 (0)