Skip to content

feat(chat): support function call api#369

Merged
sashabaranov merged 2 commits intosashabaranov:masterfrom
Ccheers:master
Jun 15, 2023
Merged

feat(chat): support function call api#369
sashabaranov merged 2 commits intosashabaranov:masterfrom
Ccheers:master

Conversation

@Ccheers
Copy link
Copy Markdown
Contributor

@Ccheers Ccheers commented Jun 15, 2023

No description provided.

@codecov
Copy link
Copy Markdown

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%> (ø)

Comment thread chat.go Outdated
Comment thread chat.go Outdated
Comment thread chat.go
@vvatanabe
Copy link
Copy Markdown
Collaborator

Looks Good 👍

Copy link
Copy Markdown
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
Comment thread chat.go
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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
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.

Comment thread chat.go
// - 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
Copy Markdown
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.

Comment thread chat.go
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
Copy Markdown
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?

Comment thread chat.go
Name string `json:"name"`
Description string `json:"description,omitempty"`
// it's required in function call
Parameters *FunctionParams `json:"parameters"`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why pointer?

Comment thread chat.go
@@ -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
Copy Markdown
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.

Comment thread chat.go
// 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
Copy Markdown

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