Make "Content" field in "ChatCompletionMessage" omitempty (#926)
This commit is contained in:
6
chat.go
6
chat.go
@@ -93,7 +93,7 @@ type ChatMessagePart struct {
|
|||||||
|
|
||||||
type ChatCompletionMessage struct {
|
type ChatCompletionMessage struct {
|
||||||
Role string `json:"role"`
|
Role string `json:"role"`
|
||||||
Content string `json:"content"`
|
Content string `json:"content,omitempty"`
|
||||||
Refusal string `json:"refusal,omitempty"`
|
Refusal string `json:"refusal,omitempty"`
|
||||||
MultiContent []ChatMessagePart
|
MultiContent []ChatMessagePart
|
||||||
|
|
||||||
@@ -132,7 +132,7 @@ func (m ChatCompletionMessage) MarshalJSON() ([]byte, error) {
|
|||||||
|
|
||||||
msg := struct {
|
msg := struct {
|
||||||
Role string `json:"role"`
|
Role string `json:"role"`
|
||||||
Content string `json:"content"`
|
Content string `json:"content,omitempty"`
|
||||||
Refusal string `json:"refusal,omitempty"`
|
Refusal string `json:"refusal,omitempty"`
|
||||||
MultiContent []ChatMessagePart `json:"-"`
|
MultiContent []ChatMessagePart `json:"-"`
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
@@ -146,7 +146,7 @@ func (m ChatCompletionMessage) MarshalJSON() ([]byte, error) {
|
|||||||
func (m *ChatCompletionMessage) UnmarshalJSON(bs []byte) error {
|
func (m *ChatCompletionMessage) UnmarshalJSON(bs []byte) error {
|
||||||
msg := struct {
|
msg := struct {
|
||||||
Role string `json:"role"`
|
Role string `json:"role"`
|
||||||
Content string `json:"content"`
|
Content string `json:"content,omitempty"`
|
||||||
Refusal string `json:"refusal,omitempty"`
|
Refusal string `json:"refusal,omitempty"`
|
||||||
MultiContent []ChatMessagePart
|
MultiContent []ChatMessagePart
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
|
|||||||
@@ -631,7 +631,7 @@ func TestMultipartChatMessageSerialization(t *testing.T) {
|
|||||||
t.Fatalf("Unexpected error")
|
t.Fatalf("Unexpected error")
|
||||||
}
|
}
|
||||||
res = strings.ReplaceAll(string(s), " ", "")
|
res = strings.ReplaceAll(string(s), " ", "")
|
||||||
if res != `{"role":"user","content":""}` {
|
if res != `{"role":"user"}` {
|
||||||
t.Fatalf("invalid message: %s", string(s))
|
t.Fatalf("invalid message: %s", string(s))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.
|
// 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:
|
// 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).
|
// TODO: implement an actual tokenizer for GPT-3 and Codex (once available).
|
||||||
func numTokens(s string) int {
|
func numTokens(s string) int {
|
||||||
|
|||||||
Reference in New Issue
Block a user