go-openai
go-openai copied to clipboard
function_call arguments are garbled characters
Describe the bug
- 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"
}
}
]
}
- 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
Environment (please complete the following information):
- go-openai version: 1.17.9
- Go version: 1.18
- OS: macOS 14.1 (23B74)