Skip to content

Commit

Permalink
EscapeString
Browse files Browse the repository at this point in the history
  • Loading branch information
laiqiangbin committed Jul 12, 2023
1 parent c3b2451 commit 64a827b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"net/http"
"strconv"
)

// Chat message role defined by the OpenAI API.
Expand All @@ -21,9 +22,15 @@ var (
ErrChatCompletionStreamNotSupported = errors.New("streaming is not supported with this method, please use CreateChatCompletionStream") //nolint:lll
)

type EscapeString string

func (esc EscapeString) MarshalJSON() ([]byte, error) {
return []byte(strconv.QuoteToASCII(string(esc))), nil
}

type ChatCompletionMessage struct {
Role string `json:"role"`
Content string `json:"content"`
Role string `json:"role"`
Content EscapeString `json:"content"`

// This property isn't in the official documentation, but it's in
// the documentation for the official library for python:
Expand Down

0 comments on commit 64a827b

Please sign in to comment.