Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: function_call can be a string or an object #374

Closed
wants to merge 1 commit into from

Conversation

j178
Copy link
Contributor

@j178 j178 commented Jun 15, 2023

According to the document, function_call parameter can a string literal: "none", "auto", or an object with a key "name".

https://platform.openai.com/docs/api-reference/chat/create#chat/create-function_call

Also added FunctionCall to ChatCompletionStreamChoiceDelta.

@codecov
Copy link

codecov bot commented Jun 15, 2023

Codecov Report

Merging #374 (158fa4e) into master (0bd14f9) will increase coverage by 0.85%.
The diff coverage is 94.73%.

@@            Coverage Diff             @@
##           master     #374      +/-   ##
==========================================
+ Coverage   95.22%   96.08%   +0.85%     
==========================================
  Files          17       17              
  Lines         670      689      +19     
==========================================
+ Hits          638      662      +24     
+ Misses         22       19       -3     
+ Partials       10        8       -2     
Impacted Files Coverage Δ
chat.go 96.77% <93.33%> (-3.23%) ⬇️
chat_stream.go 100.00% <100.00%> (+10.71%) ⬆️

... and 1 file with indirect coverage changes

@vvatanabe
Copy link
Collaborator

Also added FunctionCall to ChatCompletionStreamChoiceDelta.

Oops, it's a specification that the arguments are returned in stream!

data: {"id":"chatcmpl-***","object":"chat.completion.chunk","created":1686862207,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"function_call":{"arguments":"{\n"}},"finish_reason":null}]}
data: {"id":"chatcmpl-***","object":"chat.completion.chunk","created":1686862207,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"function_call":{"arguments":" "}},"finish_reason":null}]}
data: {"id":"chatcmpl-***","object":"chat.completion.chunk","created":1686862207,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"function_call":{"arguments":" \""}},"finish_reason":null}]}
data: {"id":"chatcmpl-***","object":"chat.completion.chunk","created":1686862207,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"function_call":{"arguments":"location"}},"finish_reason":null}]}
data: {"id":"chatcmpl-***","object":"chat.completion.chunk","created":1686862207,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"function_call":{"arguments":"\":"}},"finish_reason":null}]}
data: {"id":"chatcmpl-***","object":"chat.completion.chunk","created":1686862207,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"function_call":{"arguments":" \""}},"finish_reason":null}]}
data: {"id":"chatcmpl-***","object":"chat.completion.chunk","created":1686862207,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"function_call":{"arguments":"Boston"}},"finish_reason":null}]}
data: {"id":"chatcmpl-***","object":"chat.completion.chunk","created":1686862207,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"function_call":{"arguments":"\"\n"}},"finish_reason":null}]}
data: {"id":"chatcmpl-***","object":"chat.completion.chunk","created":1686862207,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"function_call":{"arguments":"}"}},"finish_reason":null}]}
data: {"id":"chatcmpl-***","object":"chat.completion.chunk","created":1686862207,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{},"finish_reason":"function_call"}]}
data: [DONE]

}
if v, isMap := value.(map[string]string); isMap {
return v["name"] != ""
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about adding a structure as a usable type?
For example:

type Foo struct {
	Name string `json:"name"`
}

@jabalsad
Copy link

Anything I can do to help push this PR forward?

@j178
Copy link
Contributor Author

j178 commented Jun 19, 2023

Sorry, I'm not available to push this forward, so closing. Please take #388 a look instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants