-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
feat(chat): support function call api #369
Conversation
Codecov Report
@@ Coverage Diff @@
## master #369 +/- ##
=======================================
Coverage 95.22% 95.22%
=======================================
Files 17 17
Lines 670 670
=======================================
Hits 638 638
Misses 22 22
Partials 10 10
|
Looks Good 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Folks, thank you for all your work poured into this! 🙌🏻
@@ -43,12 +54,70 @@ type ChatCompletionRequest struct { | |||
FrequencyPenalty float32 `json:"frequency_penalty,omitempty"` | |||
LogitBias map[string]int `json:"logit_bias,omitempty"` | |||
User string `json:"user,omitempty"` | |||
Functions []*FunctionDefine `json:"functions,omitempty"` | |||
FunctionCall string `json:"function_call,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function_call
can be a string or an object: https://platform.openai.com/docs/api-reference/chat/create#chat/create-function_call
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to this -- this is crucial functionality because you can use it to force the model to use a particular function, but only as an object.
@@ -27,6 +30,14 @@ type ChatCompletionMessage struct { | |||
// - https://github.com/openai/openai-python/blob/main/chatml.md | |||
// - https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb | |||
Name string `json:"name,omitempty"` | |||
|
|||
FunctionCall *FunctionCall `json:"function_call,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FunctionCall
should be added to ChatCompletionStreamChoiceDelta
too.
@@ -43,12 +54,70 @@ type ChatCompletionRequest struct { | |||
FrequencyPenalty float32 `json:"frequency_penalty,omitempty"` | |||
LogitBias map[string]int `json:"logit_bias,omitempty"` | |||
User string `json:"user,omitempty"` | |||
Functions []*FunctionDefine `json:"functions,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason to make Functions
a slice of pointer? It makes constructing request much harder. Why not []FunctionDefine
?
Name string `json:"name"` | ||
Description string `json:"description,omitempty"` | ||
// it's required in function call | ||
Parameters *FunctionParams `json:"parameters"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why pointer?
@@ -27,6 +30,14 @@ type ChatCompletionMessage struct { | |||
// - https://github.com/openai/openai-python/blob/main/chatml.md | |||
// - https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb | |||
Name string `json:"name,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name
is documented now, this document should be updated.
// Enum is a enum of JSON Schema. It used if Type is JSONSchemaTypeString. | ||
Enum []string `json:"enum,omitempty"` | ||
// Properties is a properties of JSON Schema. It used if Type is JSONSchemaTypeObject. | ||
Properties map[string]*JSONSchemaDefine `json:"properties,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to those pointed out by @j178 , this is also an unnecessary use of pointers.
No description provided.