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:
Matt Low 2023-11-29 05:27:58 +00:00
parent e29dbaf2a3
commit d32e9421fe
2 changed files with 22 additions and 14 deletions

View File

@ -13,9 +13,10 @@ type Config struct {
SystemPrompt *string `yaml:"systemPrompt" default:"You are a helpful assistant."`
} `yaml:"modelDefaults"`
OpenAI *struct {
APIKey *string `yaml:"apiKey" default:"your_key_here"`
DefaultModel *string `yaml:"defaultModel" default:"gpt-4"`
DefaultMaxLength *int `yaml:"defaultMaxLength" default:"256"`
APIKey *string `yaml:"apiKey" default:"your_key_here"`
DefaultModel *string `yaml:"defaultModel" default:"gpt-4"`
DefaultMaxLength *int `yaml:"defaultMaxLength" default:"256"`
EnabledTools []string `yaml:"enabledTools"`
} `yaml:"openai"`
Chroma *struct {
Style *string `yaml:"style" default:"onedark"`

View File

@ -34,20 +34,27 @@ func CreateChatCompletionRequest(model string, messages []Message, maxTokens int
chatCompletionMessages = append(chatCompletionMessages, message)
}
var tools []openai.Tool
for _, t := range AvailableTools {
// TODO: support some way to limit which tools are available per-request
tools = append(tools, t.Tool)
request := openai.ChatCompletionRequest{
Model: model,
Messages: chatCompletionMessages,
MaxTokens: maxTokens,
N: 1, // limit responses to 1 "choice". we use choices[0] to reference it
}
return openai.ChatCompletionRequest{
Model: model,
Messages: chatCompletionMessages,
MaxTokens: maxTokens,
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