go-openai icon indicating copy to clipboard operation
go-openai copied to clipboard

function_call arguments are garbled characters

Open harry0703 opened this issue 1 year ago • 0 comments

Describe the bug

  1. below is the post data to OPENAI API.
{
  "model": "gpt-3.5-turbo-1106",
  "messages": [
    {
      "role": "system",
      "content": "You are an helpful and kind assistant to answer questions.\nAnswer the question follow the user's instructions carefully."
    },
    {
      "role": "user",
      "content": "人工服务"
    }
  ],
  "temperature": 0.1,
  "top_p": 1,
  "stream": true,
  "functions": [
    {
      "name": "request_human_service",
      "description": "The purpose of this function is to offer manual customer service. It should only be invoked when the user specifically requests to speak with a human agent, requests a refund, or wants to file a complaint. Under no other circumstances should this function be called.",
      "parameters": {
        "properties": {
          "category": {
            "description": "The category of the request",
            "enum": [
              "human",
              "refund",
              "complaint"
            ],
            "type": "string"
          },
          "query": {
            "description": "The request user asked",
            "type": "string"
          }
        },
        "required": [
          "query",
          "category"
        ],
        "type": "object"
      }
    }
  ]
}
  1. below is the response data from OPENAI API. I added a println in stream_reader.go at line 52
func (stream *streamReader[T]) processLines() (T, error) {
	var (
		emptyMessagesCount uint
		hasErrorPrefix     bool
	)

	for {
		rawLine, readErr := stream.reader.ReadBytes('\n')
                 // debug
		fmt.Println("rawLine\n", string(rawLine))

the arguments is garbled characters. for example {"arguments":"无"}

rawLine data: {"id":"chatcmpl-8Rs86FbrQ1h5pbmoLT6OOAxAiGWGt","object":"chat.completion.chunk","created":1701653622,"model":"gpt-3.5-turbo-1106","system_fingerprint":"fp_eeff13170a","choices":[{"index":0,"delta":{"role":"assistant","content":null,"function_call":{"name":"request_human_service","arguments":""}},"finish_reason":null}]}

rawLine 

rawLine data: {"id":"chatcmpl-8Rs86FbrQ1h5pbmoLT6OOAxAiGWGt","object":"chat.completion.chunk","created":1701653622,"model":"gpt-3.5-turbo-1106","system_fingerprint":"fp_eeff13170a","choices":[{"index":0,"delta":{"function_call":{"arguments":"{\""}},"finish_reason":null}]}

rawLine 

rawLine data: {"id":"chatcmpl-8Rs86FbrQ1h5pbmoLT6OOAxAiGWGt","object":"chat.completion.chunk","created":1701653622,"model":"gpt-3.5-turbo-1106","system_fingerprint":"fp_eeff13170a","choices":[{"index":0,"delta":{"function_call":{"arguments":"category"}},"finish_reason":null}]}

rawLine 

rawLine data: {"id":"chatcmpl-8Rs86FbrQ1h5pbmoLT6OOAxAiGWGt","object":"chat.completion.chunk","created":1701653622,"model":"gpt-3.5-turbo-1106","system_fingerprint":"fp_eeff13170a","choices":[{"index":0,"delta":{"function_call":{"arguments":"\":\""}},"finish_reason":null}]}

rawLine 

rawLine data: {"id":"chatcmpl-8Rs86FbrQ1h5pbmoLT6OOAxAiGWGt","object":"chat.completion.chunk","created":1701653622,"model":"gpt-3.5-turbo-1106","system_fingerprint":"fp_eeff13170a","choices":[{"index":0,"delta":{"function_call":{"arguments":"human"}},"finish_reason":null}]}

rawLine 

rawLine data: {"id":"chatcmpl-8Rs86FbrQ1h5pbmoLT6OOAxAiGWGt","object":"chat.completion.chunk","created":1701653622,"model":"gpt-3.5-turbo-1106","system_fingerprint":"fp_eeff13170a","choices":[{"index":0,"delta":{"function_call":{"arguments":"\",\""}},"finish_reason":null}]}

rawLine 

rawLine data: {"id":"chatcmpl-8Rs86FbrQ1h5pbmoLT6OOAxAiGWGt","object":"chat.completion.chunk","created":1701653622,"model":"gpt-3.5-turbo-1106","system_fingerprint":"fp_eeff13170a","choices":[{"index":0,"delta":{"function_call":{"arguments":"query"}},"finish_reason":null}]}

rawLine 

rawLine data: {"id":"chatcmpl-8Rs86FbrQ1h5pbmoLT6OOAxAiGWGt","object":"chat.completion.chunk","created":1701653622,"model":"gpt-3.5-turbo-1106","system_fingerprint":"fp_eeff13170a","choices":[{"index":0,"delta":{"function_call":{"arguments":"\":\""}},"finish_reason":null}]}

rawLine 

rawLine data: {"id":"chatcmpl-8Rs86FbrQ1h5pbmoLT6OOAxAiGWGt","object":"chat.completion.chunk","created":1701653622,"model":"gpt-3.5-turbo-1106","system_fingerprint":"fp_eeff13170a","choices":[{"index":0,"delta":{"function_call":{"arguments":"我"}},"finish_reason":null}]}

rawLine 

rawLine data: {"id":"chatcmpl-8Rs86FbrQ1h5pbmoLT6OOAxAiGWGt","object":"chat.completion.chunk","created":1701653622,"model":"gpt-3.5-turbo-1106","system_fingerprint":"fp_eeff13170a","choices":[{"index":0,"delta":{"function_call":{"arguments":"遇"}},"finish_reason":null}]}

rawLine 

rawLine data: {"id":"chatcmpl-8Rs86FbrQ1h5pbmoLT6OOAxAiGWGt","object":"chat.completion.chunk","created":1701653622,"model":"gpt-3.5-turbo-1106","system_fingerprint":"fp_eeff13170a","choices":[{"index":0,"delta":{"function_call":{"arguments":"到"}},"finish_reason":null}]}

rawLine 

rawLine data: {"id":"chatcmpl-8Rs86FbrQ1h5pbmoLT6OOAxAiGWGt","object":"chat.completion.chunk","created":1701653622,"model":"gpt-3.5-turbo-1106","system_fingerprint":"fp_eeff13170a","choices":[{"index":0,"delta":{"function_call":{"arguments":"了"}},"finish_reason":null}]}

rawLine 

rawLine data: {"id":"chatcmpl-8Rs86FbrQ1h5pbmoLT6OOAxAiGWGt","object":"chat.completion.chunk","created":1701653622,"model":"gpt-3.5-turbo-1106","system_fingerprint":"fp_eeff13170a","choices":[{"index":0,"delta":{"function_call":{"arguments":"一个"}},"finish_reason":null}]}

rawLine 

rawLine data: {"id":"chatcmpl-8Rs86FbrQ1h5pbmoLT6OOAxAiGWGt","object":"chat.completion.chunk","created":1701653622,"model":"gpt-3.5-turbo-1106","system_fingerprint":"fp_eeff13170a","choices":[{"index":0,"delta":{"function_call":{"arguments":"无"}},"finish_reason":null}]}

rawLine 

rawLine data: {"id":"chatcmpl-8Rs86FbrQ1h5pbmoLT6OOAxAiGWGt","object":"chat.completion.chunk","created":1701653622,"model":"gpt-3.5-turbo-1106","system_fingerprint":"fp_eeff13170a","choices":[{"index":0,"delta":{"function_call":{"arguments":"法"}},"finish_reason":null}]}

rawLine 

rawLine data: {"id":"chatcmpl-8Rs86FbrQ1h5pbmoLT6OOAxAiGWGt","object":"chat.completion.chunk","created":1701653622,"model":"gpt-3.5-turbo-1106","system_fingerprint":"fp_eeff13170a","choices":[{"index":0,"delta":{"function_call":{"arguments":"解"}},"finish_reason":null}]}

rawLine 

rawLine data: {"id":"chatcmpl-8Rs86FbrQ1h5pbmoLT6OOAxAiGWGt","object":"chat.completion.chunk","created":1701653622,"model":"gpt-3.5-turbo-1106","system_fingerprint":"fp_eeff13170a","choices":[{"index":0,"delta":{"function_call":{"arguments":"决"}},"finish_reason":null}]}

rawLine 

rawLine data: {"id":"chatcmpl-8Rs86FbrQ1h5pbmoLT6OOAxAiGWGt","object":"chat.completion.chunk","created":1701653622,"model":"gpt-3.5-turbo-1106","system_fingerprint":"fp_eeff13170a","choices":[{"index":0,"delta":{"function_call":{"arguments":"的"}},"finish_reason":null}]}

rawLine 

rawLine data: {"id":"chatcmpl-8Rs86FbrQ1h5pbmoLT6OOAxAiGWGt","object":"chat.completion.chunk","created":1701653622,"model":"gpt-3.5-turbo-1106","system_fingerprint":"fp_eeff13170a","choices":[{"index":0,"delta":{"function_call":{"arguments":"问题"}},"finish_reason":null}]}

rawLine 

rawLine data: {"id":"chatcmpl-8Rs86FbrQ1h5pbmoLT6OOAxAiGWGt","object":"chat.completion.chunk","created":1701653622,"model":"gpt-3.5-turbo-1106","system_fingerprint":"fp_eeff13170a","choices":[{"index":0,"delta":{"function_call":{"arguments":","}},"finish_reason":null}]}

rawLine 

rawLine data: {"id":"chatcmpl-8Rs86FbrQ1h5pbmoLT6OOAxAiGWGt","object":"chat.completion.chunk","created":1701653622,"model":"gpt-3.5-turbo-1106","system_fingerprint":"fp_eeff13170a","choices":[{"index":0,"delta":{"function_call":{"arguments":"需要"}},"finish_reason":null}]}

rawLine 

rawLine data: {"id":"chatcmpl-8Rs86FbrQ1h5pbmoLT6OOAxAiGWGt","object":"chat.completion.chunk","created":1701653622,"model":"gpt-3.5-turbo-1106","system_fingerprint":"fp_eeff13170a","choices":[{"index":0,"delta":{"function_call":{"arguments":"人"}},"finish_reason":null}]}

rawLine 

rawLine data: {"id":"chatcmpl-8Rs86FbrQ1h5pbmoLT6OOAxAiGWGt","object":"chat.completion.chunk","created":1701653622,"model":"gpt-3.5-turbo-1106","system_fingerprint":"fp_eeff13170a","choices":[{"index":0,"delta":{"function_call":{"arguments":"å·¥"}},"finish_reason":null}]}

rawLine 

rawLine data: {"id":"chatcmpl-8Rs86FbrQ1h5pbmoLT6OOAxAiGWGt","object":"chat.completion.chunk","created":1701653622,"model":"gpt-3.5-turbo-1106","system_fingerprint":"fp_eeff13170a","choices":[{"index":0,"delta":{"function_call":{"arguments":"帮"}},"finish_reason":null}]}

rawLine 

rawLine data: {"id":"chatcmpl-8Rs86FbrQ1h5pbmoLT6OOAxAiGWGt","object":"chat.completion.chunk","created":1701653622,"model":"gpt-3.5-turbo-1106","system_fingerprint":"fp_eeff13170a","choices":[{"index":0,"delta":{"function_call":{"arguments":"助"}},"finish_reason":null}]}

rawLine 

rawLine data: {"id":"chatcmpl-8Rs86FbrQ1h5pbmoLT6OOAxAiGWGt","object":"chat.completion.chunk","created":1701653622,"model":"gpt-3.5-turbo-1106","system_fingerprint":"fp_eeff13170a","choices":[{"index":0,"delta":{"function_call":{"arguments":"。"}},"finish_reason":null}]}

rawLine 

rawLine data: {"id":"chatcmpl-8Rs86FbrQ1h5pbmoLT6OOAxAiGWGt","object":"chat.completion.chunk","created":1701653622,"model":"gpt-3.5-turbo-1106","system_fingerprint":"fp_eeff13170a","choices":[{"index":0,"delta":{"function_call":{"arguments":"\"}"}},"finish_reason":null}]}

rawLine 

rawLine data: {"id":"chatcmpl-8Rs86FbrQ1h5pbmoLT6OOAxAiGWGt","object":"chat.completion.chunk","created":1701653622,"model":"gpt-3.5-turbo-1106","system_fingerprint":"fp_eeff13170a","choices":[{"index":0,"delta":{},"finish_reason":"function_call"}]}

rawLine 

rawLine data: [DONE]

Screenshots/Logs image

image image

Environment (please complete the following information):

  • go-openai version: 1.17.9
  • Go version: 1.18
  • OS: macOS 14.1 (23B74)

harry0703 avatar Dec 04 '23 03:12 harry0703