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
@ -13,9 +13,10 @@ type Config struct {
|
|||||||
SystemPrompt *string `yaml:"systemPrompt" default:"You are a helpful assistant."`
|
SystemPrompt *string `yaml:"systemPrompt" default:"You are a helpful assistant."`
|
||||||
} `yaml:"modelDefaults"`
|
} `yaml:"modelDefaults"`
|
||||||
OpenAI *struct {
|
OpenAI *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 {
|
Model: model,
|
||||||
// TODO: support some way to limit which tools are available per-request
|
Messages: chatCompletionMessages,
|
||||||
tools = append(tools, t.Tool)
|
MaxTokens: maxTokens,
|
||||||
|
N: 1, // limit responses to 1 "choice". we use choices[0] to reference it
|
||||||
}
|
}
|
||||||
|
|
||||||
return openai.ChatCompletionRequest{
|
var tools []openai.Tool
|
||||||
Model: model,
|
for _, t := range config.OpenAI.EnabledTools {
|
||||||
Messages: chatCompletionMessages,
|
tool, ok := AvailableTools[t]
|
||||||
MaxTokens: maxTokens,
|
if ok {
|
||||||
N: 1, // limit responses to 1 "choice". we use choices[0] to reference it
|
tools = append(tools, tool.Tool)
|
||||||
Tools: tools,
|
}
|
||||||
ToolChoice: "auto", // TODO: allow limiting/forcing which function is called?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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