Skip to content

Commit 5715e81

Browse files
committed
Allow to customize no action behavior
1 parent b3f43ab commit 5715e81

File tree

2 files changed

+34
-20
lines changed

2 files changed

+34
-20
lines changed

api/config.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,25 @@ type Config struct {
4242
MainGPU string `yaml:"main_gpu"`
4343
ImageGenerationAssets string `yaml:"asset_dir"`
4444

45-
DisableDefaultAnswer bool `yaml:"disable_default_answer"`
46-
4745
PromptCachePath string `yaml:"prompt_cache_path"`
4846
PromptCacheAll bool `yaml:"prompt_cache_all"`
4947
PromptCacheRO bool `yaml:"prompt_cache_ro"`
5048

5149
Grammar string `yaml:"grammar"`
5250

51+
FunctionsConfig Functions `yaml:"function"`
52+
5353
PromptStrings, InputStrings []string
5454
InputToken [][]int
5555
functionCallString, functionCallNameString string
5656
}
5757

58+
type Functions struct {
59+
DisableNoAction bool `yaml:"disable_no_action"`
60+
NoActionFunctionName string `yaml:"no_action_function_name"`
61+
NoActionDescriptionName string `yaml:"no_action_description_name"`
62+
}
63+
5864
type TemplateConfig struct {
5965
Completion string `yaml:"completion"`
6066
Functions string `yaml:"function"`

api/openai.go

+26-18
Original file line numberDiff line numberDiff line change
@@ -363,23 +363,6 @@ func embeddingsEndpoint(cm *ConfigMerger, o *Option) func(c *fiber.Ctx) error {
363363
}
364364

365365
func chatEndpoint(cm *ConfigMerger, o *Option) func(c *fiber.Ctx) error {
366-
// TODO: replace this with config settings
367-
// Allow the user to set custom actions via config file
368-
// to be "embedded" in each model
369-
const noActionName = "answer"
370-
const noActionDescription = "use this action to answer without performing any action"
371-
372-
noActionGrammar := grammar.Function{
373-
Name: noActionName,
374-
Description: noActionDescription,
375-
Parameters: map[string]interface{}{
376-
"properties": map[string]interface{}{
377-
"message": map[string]interface{}{
378-
"type": "string",
379-
"description": "The message to reply the user with",
380-
}},
381-
},
382-
}
383366

384367
process := func(s string, req *OpenAIRequest, config *Config, loader *model.ModelLoader, responses chan OpenAIResponse) {
385368
initialMessage := OpenAIResponse{
@@ -423,9 +406,34 @@ func chatEndpoint(cm *ConfigMerger, o *Option) func(c *fiber.Ctx) error {
423406

424407
processFunctions = true
425408

409+
// TODO: replace this with config settings
410+
// Allow the user to set custom actions via config file
411+
// to be "embedded" in each model
412+
noActionName := "answer"
413+
noActionDescription := "use this action to answer without performing any action"
414+
415+
if config.FunctionsConfig.NoActionFunctionName != "" {
416+
noActionName = config.FunctionsConfig.NoActionFunctionName
417+
}
418+
if config.FunctionsConfig.NoActionDescriptionName != "" {
419+
noActionDescription = config.FunctionsConfig.NoActionDescriptionName
420+
}
421+
422+
noActionGrammar := grammar.Function{
423+
Name: noActionName,
424+
Description: noActionDescription,
425+
Parameters: map[string]interface{}{
426+
"properties": map[string]interface{}{
427+
"message": map[string]interface{}{
428+
"type": "string",
429+
"description": "The message to reply the user with",
430+
}},
431+
},
432+
}
433+
426434
// Append the no action function
427435
funcs = append(funcs, input.Functions...)
428-
if !config.DisableDefaultAnswer {
436+
if !config.FunctionsConfig.DisableNoAction {
429437
funcs = append(funcs, noActionGrammar)
430438
}
431439

0 commit comments

Comments
 (0)