Skip to content

Commit

Permalink
Make "Content" field in "ChatCompletionMessage" omitempty (#926)
Browse files Browse the repository at this point in the history
  • Loading branch information
saileshd1402 authored Jan 31, 2025
1 parent 9823a8b commit 45aa996
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ type ChatMessagePart struct {

type ChatCompletionMessage struct {
Role string `json:"role"`
Content string `json:"content"`
Content string `json:"content,omitempty"`
Refusal string `json:"refusal,omitempty"`
MultiContent []ChatMessagePart

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

msg := struct {
Role string `json:"role"`
Content string `json:"content"`
Content string `json:"content,omitempty"`
Refusal string `json:"refusal,omitempty"`
MultiContent []ChatMessagePart `json:"-"`
Name string `json:"name,omitempty"`
Expand All @@ -146,7 +146,7 @@ func (m ChatCompletionMessage) MarshalJSON() ([]byte, error) {
func (m *ChatCompletionMessage) UnmarshalJSON(bs []byte) error {
msg := struct {
Role string `json:"role"`
Content string `json:"content"`
Content string `json:"content,omitempty"`
Refusal string `json:"refusal,omitempty"`
MultiContent []ChatMessagePart
Name string `json:"name,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion chat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ func TestMultipartChatMessageSerialization(t *testing.T) {
t.Fatalf("Unexpected error")
}
res = strings.ReplaceAll(string(s), " ", "")
if res != `{"role":"user","content":""}` {
if res != `{"role":"user"}` {
t.Fatalf("invalid message: %s", string(s))
}
}
Expand Down
2 changes: 1 addition & 1 deletion openai_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func setupAzureTestServer() (client *openai.Client, server *test.ServerTest, tea

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

0 comments on commit 45aa996

Please # to comment.