@@ -12,6 +12,7 @@ const (
12
12
ChatMessageRoleUser = "user"
13
13
ChatMessageRoleAssistant = "assistant"
14
14
ChatMessageRoleFunction = "function"
15
+ ChatMessageRoleTool = "tool"
15
16
)
16
17
17
18
const chatCompletionsSuffix = "/chat/completions"
@@ -61,6 +62,12 @@ type ChatCompletionMessage struct {
61
62
Name string `json:"name,omitempty"`
62
63
63
64
FunctionCall * FunctionCall `json:"function_call,omitempty"`
65
+ ToolCalls []ToolCall `json:"tool_calls,omitempty"`
66
+ }
67
+
68
+ type ToolCall struct {
69
+ ID string `json:"id"`
70
+ Function FunctionCall `json:"function"`
64
71
}
65
72
66
73
type FunctionCall struct {
@@ -97,10 +104,35 @@ type ChatCompletionRequest struct {
97
104
// LogitBias is must be a token id string (specified by their token ID in the tokenizer), not a word string.
98
105
// incorrect: `"logit_bias":{"You": 6}`, correct: `"logit_bias":{"1639": 6}`
99
106
// refs: https://platform.openai.com/docs/api-reference/chat/create#chat/create-logit_bias
100
- LogitBias map [string ]int `json:"logit_bias,omitempty"`
101
- User string `json:"user,omitempty"`
102
- Functions []FunctionDefinition `json:"functions,omitempty"`
103
- FunctionCall any `json:"function_call,omitempty"`
107
+ LogitBias map [string ]int `json:"logit_bias,omitempty"`
108
+ User string `json:"user,omitempty"`
109
+ // Deprecated: use Tools instead.
110
+ Functions []FunctionDefinition `json:"functions,omitempty"`
111
+ // Deprecated: use ToolChoice instead.
112
+ FunctionCall any `json:"function_call,omitempty"`
113
+ Tools []Tool `json:"tools,omitempty"`
114
+ // This can be either a string or an ToolChoice object.
115
+ ToolChoiche any `json:"tool_choice,omitempty"`
116
+ }
117
+
118
+ type ToolType string
119
+
120
+ const (
121
+ ToolTypeFunction ToolType = "function"
122
+ )
123
+
124
+ type Tool struct {
125
+ Type ToolType `json:"type"`
126
+ Function FunctionDefinition `json:"function,omitempty"`
127
+ }
128
+
129
+ type ToolChoiche struct {
130
+ Type ToolType `json:"type"`
131
+ Function ToolFunction `json:"function,omitempty"`
132
+ }
133
+
134
+ type ToolFunction struct {
135
+ Name string `json:"name"`
104
136
}
105
137
106
138
type FunctionDefinition struct {
@@ -123,6 +155,7 @@ const (
123
155
FinishReasonStop FinishReason = "stop"
124
156
FinishReasonLength FinishReason = "length"
125
157
FinishReasonFunctionCall FinishReason = "function_call"
158
+ FinishReasonToolCalls FinishReason = "tool_calls"
126
159
FinishReasonContentFilter FinishReason = "content_filter"
127
160
FinishReasonNull FinishReason = "null"
128
161
)
0 commit comments