Add openai.enabledTools config key
By default none are, they must be explicitly enabled by the user adding the configuration.
This commit is contained in:
parent
e29dbaf2a3
commit
d32e9421fe
@ -16,6 +16,7 @@ type Config struct {
|
|||||||
APIKey *string `yaml:"apiKey" default:"your_key_here"`
|
APIKey *string `yaml:"apiKey" default:"your_key_here"`
|
||||||
DefaultModel *string `yaml:"defaultModel" default:"gpt-4"`
|
DefaultModel *string `yaml:"defaultModel" default:"gpt-4"`
|
||||||
DefaultMaxLength *int `yaml:"defaultMaxLength" default:"256"`
|
DefaultMaxLength *int `yaml:"defaultMaxLength" default:"256"`
|
||||||
|
EnabledTools []string `yaml:"enabledTools"`
|
||||||
} `yaml:"openai"`
|
} `yaml:"openai"`
|
||||||
Chroma *struct {
|
Chroma *struct {
|
||||||
Style *string `yaml:"style" default:"onedark"`
|
Style *string `yaml:"style" default:"onedark"`
|
||||||
|
@ -34,20 +34,27 @@ func CreateChatCompletionRequest(model string, messages []Message, maxTokens int
|
|||||||
chatCompletionMessages = append(chatCompletionMessages, message)
|
chatCompletionMessages = append(chatCompletionMessages, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
var tools []openai.Tool
|
request := openai.ChatCompletionRequest{
|
||||||
for _, t := range AvailableTools {
|
|
||||||
// TODO: support some way to limit which tools are available per-request
|
|
||||||
tools = append(tools, t.Tool)
|
|
||||||
}
|
|
||||||
|
|
||||||
return openai.ChatCompletionRequest{
|
|
||||||
Model: model,
|
Model: model,
|
||||||
Messages: chatCompletionMessages,
|
Messages: chatCompletionMessages,
|
||||||
MaxTokens: maxTokens,
|
MaxTokens: maxTokens,
|
||||||
N: 1, // limit responses to 1 "choice". we use choices[0] to reference it
|
N: 1, // limit responses to 1 "choice". we use choices[0] to reference it
|
||||||
Tools: tools,
|
|
||||||
ToolChoice: "auto", // TODO: allow limiting/forcing which function is called?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var tools []openai.Tool
|
||||||
|
for _, t := range config.OpenAI.EnabledTools {
|
||||||
|
tool, ok := AvailableTools[t]
|
||||||
|
if ok {
|
||||||
|
tools = append(tools, tool.Tool)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(tools) > 0 {
|
||||||
|
request.Tools = tools
|
||||||
|
request.ToolChoice = "auto"
|
||||||
|
}
|
||||||
|
|
||||||
|
return request
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateChatCompletion submits a Chat Completion API request and returns the
|
// CreateChatCompletion submits a Chat Completion API request and returns the
|
||||||
|
Loading…
Reference in New Issue
Block a user