From e8f02c083f03b04ffc58eb8ba1f093c9227be0a5 Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Mon, 1 Apr 2024 19:39:54 +0200 Subject: [PATCH] fix(functions): respect when selected from string (#1940) * fix(functions): respect when selected from string * fix(toolschoice): decode both string and objects --- core/config/backend_config.go | 7 ++++++- core/http/endpoints/openai/request.go | 9 ++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/core/config/backend_config.go b/core/config/backend_config.go index 32e10a17436..db9c66654dd 100644 --- a/core/config/backend_config.go +++ b/core/config/backend_config.go @@ -185,7 +185,12 @@ func (c *BackendConfig) ShouldCallSpecificFunction() bool { } func (c *BackendConfig) FunctionToCall() string { - return c.functionCallNameString + if c.functionCallNameString != "" && + c.functionCallNameString != "none" && c.functionCallNameString != "auto" { + return c.functionCallNameString + } + + return c.functionCallString } func (cfg *BackendConfig) SetDefaults(opts ...ConfigLoaderOption) { diff --git a/core/http/endpoints/openai/request.go b/core/http/endpoints/openai/request.go index 1f845c6f1cc..c99812045ad 100644 --- a/core/http/endpoints/openai/request.go +++ b/core/http/endpoints/openai/request.go @@ -146,7 +146,14 @@ func updateRequestConfig(config *config.BackendConfig, input *schema.OpenAIReque if input.ToolsChoice != nil { var toolChoice grammar.Tool - json.Unmarshal([]byte(input.ToolsChoice.(string)), &toolChoice) + + switch content := input.ToolsChoice.(type) { + case string: + _ = json.Unmarshal([]byte(content), &toolChoice) + case map[string]interface{}: + dat, _ := json.Marshal(content) + _ = json.Unmarshal(dat, &toolChoice) + } input.FunctionCall = map[string]interface{}{ "name": toolChoice.Function.Name, }