Skip to content

Commit e8f02c0

Browse files
authored
fix(functions): respect when selected from string (#1940)
* fix(functions): respect when selected from string * fix(toolschoice): decode both string and objects
1 parent ebb1fce commit e8f02c0

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

core/config/backend_config.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,12 @@ func (c *BackendConfig) ShouldCallSpecificFunction() bool {
185185
}
186186

187187
func (c *BackendConfig) FunctionToCall() string {
188-
return c.functionCallNameString
188+
if c.functionCallNameString != "" &&
189+
c.functionCallNameString != "none" && c.functionCallNameString != "auto" {
190+
return c.functionCallNameString
191+
}
192+
193+
return c.functionCallString
189194
}
190195

191196
func (cfg *BackendConfig) SetDefaults(opts ...ConfigLoaderOption) {

core/http/endpoints/openai/request.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,14 @@ func updateRequestConfig(config *config.BackendConfig, input *schema.OpenAIReque
146146

147147
if input.ToolsChoice != nil {
148148
var toolChoice grammar.Tool
149-
json.Unmarshal([]byte(input.ToolsChoice.(string)), &toolChoice)
149+
150+
switch content := input.ToolsChoice.(type) {
151+
case string:
152+
_ = json.Unmarshal([]byte(content), &toolChoice)
153+
case map[string]interface{}:
154+
dat, _ := json.Marshal(content)
155+
_ = json.Unmarshal(dat, &toolChoice)
156+
}
150157
input.FunctionCall = map[string]interface{}{
151158
"name": toolChoice.Function.Name,
152159
}

0 commit comments

Comments
 (0)