Skip to content

Commit e703226

Browse files
committed
Allow to customize no action behavior
Signed-off-by: mudler <[email protected]>
1 parent b3f43ab commit e703226

File tree

2 files changed

+33
-20
lines changed

2 files changed

+33
-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

+25-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{
@@ -416,16 +399,40 @@ func chatEndpoint(cm *ConfigMerger, o *Option) func(c *fiber.Ctx) error {
416399
}
417400
log.Debug().Msgf("Configuration read: %+v", config)
418401

402+
// Allow the user to set custom actions via config file
403+
// to be "embedded" in each model
404+
noActionName := "answer"
405+
noActionDescription := "use this action to answer without performing any action"
406+
407+
if config.FunctionsConfig.NoActionFunctionName != "" {
408+
noActionName = config.FunctionsConfig.NoActionFunctionName
409+
}
410+
if config.FunctionsConfig.NoActionDescriptionName != "" {
411+
noActionDescription = config.FunctionsConfig.NoActionDescriptionName
412+
}
413+
419414
// process functions if we have any defined or if we have a function call string
420415
if len(input.Functions) > 0 &&
421416
((config.functionCallString != "none" || config.functionCallString == "") || len(config.functionCallNameString) > 0) {
422417
log.Debug().Msgf("Response needs to process functions")
423418

424419
processFunctions = true
425420

421+
noActionGrammar := grammar.Function{
422+
Name: noActionName,
423+
Description: noActionDescription,
424+
Parameters: map[string]interface{}{
425+
"properties": map[string]interface{}{
426+
"message": map[string]interface{}{
427+
"type": "string",
428+
"description": "The message to reply the user with",
429+
}},
430+
},
431+
}
432+
426433
// Append the no action function
427434
funcs = append(funcs, input.Functions...)
428-
if !config.DisableDefaultAnswer {
435+
if !config.FunctionsConfig.DisableNoAction {
429436
funcs = append(funcs, noActionGrammar)
430437
}
431438

0 commit comments

Comments
 (0)