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

feat(chat): support function call api #369

Merged
merged 2 commits into from
Jun 15, 2023

Conversation

Ccheers
Copy link
Contributor

@Ccheers Ccheers commented Jun 15, 2023

No description provided.

@codecov
Copy link

codecov bot commented Jun 15, 2023

Codecov Report

Merging #369 (bd60463) into master (646989c) will not change coverage.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master     #369   +/-   ##
=======================================
  Coverage   95.22%   95.22%           
=======================================
  Files          17       17           
  Lines         670      670           
=======================================
  Hits          638      638           
  Misses         22       22           
  Partials       10       10           
Impacted Files Coverage Δ
completion.go 100.00% <ø> (ø)
chat.go 100.00% <100.00%> (ø)
chat_stream.go 89.28% <100.00%> (ø)

chat.go Outdated Show resolved Hide resolved
chat.go Outdated Show resolved Hide resolved
chat.go Show resolved Hide resolved
@vvatanabe
Copy link
Collaborator

Looks Good 👍

Copy link
Owner

@sashabaranov sashabaranov left a 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! 🙌🏻

@sashabaranov sashabaranov merged commit 2bd65aa into sashabaranov:master Jun 15, 2023
@@ -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"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

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"`
Copy link
Contributor

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"`
Copy link
Contributor

@j178 j178 Jun 15, 2023

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"`
Copy link
Contributor

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"`
Copy link
Contributor

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"`
Copy link

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.

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.

6 participants