Feat Support tools and tools choice new fileds (#526)
* feat: support tools and tools choice new fileds * fix: use value not pointers
This commit is contained in:
33
chat.go
33
chat.go
@@ -12,6 +12,7 @@ const (
|
|||||||
ChatMessageRoleUser = "user"
|
ChatMessageRoleUser = "user"
|
||||||
ChatMessageRoleAssistant = "assistant"
|
ChatMessageRoleAssistant = "assistant"
|
||||||
ChatMessageRoleFunction = "function"
|
ChatMessageRoleFunction = "function"
|
||||||
|
ChatMessageRoleTool = "tool"
|
||||||
)
|
)
|
||||||
|
|
||||||
const chatCompletionsSuffix = "/chat/completions"
|
const chatCompletionsSuffix = "/chat/completions"
|
||||||
@@ -61,6 +62,12 @@ type ChatCompletionMessage struct {
|
|||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
|
|
||||||
FunctionCall *FunctionCall `json:"function_call,omitempty"`
|
FunctionCall *FunctionCall `json:"function_call,omitempty"`
|
||||||
|
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ToolCall struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
Function FunctionCall `json:"function"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type FunctionCall struct {
|
type FunctionCall struct {
|
||||||
@@ -99,8 +106,33 @@ type ChatCompletionRequest struct {
|
|||||||
// refs: https://platform.openai.com/docs/api-reference/chat/create#chat/create-logit_bias
|
// refs: https://platform.openai.com/docs/api-reference/chat/create#chat/create-logit_bias
|
||||||
LogitBias map[string]int `json:"logit_bias,omitempty"`
|
LogitBias map[string]int `json:"logit_bias,omitempty"`
|
||||||
User string `json:"user,omitempty"`
|
User string `json:"user,omitempty"`
|
||||||
|
// Deprecated: use Tools instead.
|
||||||
Functions []FunctionDefinition `json:"functions,omitempty"`
|
Functions []FunctionDefinition `json:"functions,omitempty"`
|
||||||
|
// Deprecated: use ToolChoice instead.
|
||||||
FunctionCall any `json:"function_call,omitempty"`
|
FunctionCall any `json:"function_call,omitempty"`
|
||||||
|
Tools []Tool `json:"tools,omitempty"`
|
||||||
|
// This can be either a string or an ToolChoice object.
|
||||||
|
ToolChoiche any `json:"tool_choice,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ToolType string
|
||||||
|
|
||||||
|
const (
|
||||||
|
ToolTypeFunction ToolType = "function"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Tool struct {
|
||||||
|
Type ToolType `json:"type"`
|
||||||
|
Function FunctionDefinition `json:"function,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ToolChoiche struct {
|
||||||
|
Type ToolType `json:"type"`
|
||||||
|
Function ToolFunction `json:"function,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ToolFunction struct {
|
||||||
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type FunctionDefinition struct {
|
type FunctionDefinition struct {
|
||||||
@@ -123,6 +155,7 @@ const (
|
|||||||
FinishReasonStop FinishReason = "stop"
|
FinishReasonStop FinishReason = "stop"
|
||||||
FinishReasonLength FinishReason = "length"
|
FinishReasonLength FinishReason = "length"
|
||||||
FinishReasonFunctionCall FinishReason = "function_call"
|
FinishReasonFunctionCall FinishReason = "function_call"
|
||||||
|
FinishReasonToolCalls FinishReason = "tool_calls"
|
||||||
FinishReasonContentFilter FinishReason = "content_filter"
|
FinishReasonContentFilter FinishReason = "content_filter"
|
||||||
FinishReasonNull FinishReason = "null"
|
FinishReasonNull FinishReason = "null"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ type ChatCompletionStreamChoiceDelta struct {
|
|||||||
Content string `json:"content,omitempty"`
|
Content string `json:"content,omitempty"`
|
||||||
Role string `json:"role,omitempty"`
|
Role string `json:"role,omitempty"`
|
||||||
FunctionCall *FunctionCall `json:"function_call,omitempty"`
|
FunctionCall *FunctionCall `json:"function_call,omitempty"`
|
||||||
|
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ChatCompletionStreamChoice struct {
|
type ChatCompletionStreamChoice struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user