From d54d11b7d57762f706e8d864acaf8a68cf3260bd Mon Sep 17 00:00:00 2001 From: Grant Linville Date: Tue, 23 Jul 2024 15:08:01 -0400 Subject: [PATCH] fix: normalize LLM-hallucinated tool names (#656) Signed-off-by: Grant Linville --- pkg/engine/engine.go | 2 +- pkg/tests/runner_test.go | 2 +- pkg/tests/testdata/TestMissingTool/call1-resp.golden | 2 +- pkg/tests/testdata/TestMissingTool/call2.golden | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/engine/engine.go b/pkg/engine/engine.go index 0ea72ff6..d3daa674 100644 --- a/pkg/engine/engine.go +++ b/pkg/engine/engine.go @@ -396,7 +396,7 @@ func (e *Engine) complete(ctx context.Context, state *State) (*Return, error) { } if toolID == "" { log.Debugf("failed to find tool id for tool %s in tool_call result", content.ToolCall.Function.Name) - toolID = content.ToolCall.Function.Name + toolID = types.ToolNormalizer(content.ToolCall.Function.Name) missing = true } state.Pending[content.ToolCall.ID] = *content.ToolCall diff --git a/pkg/tests/runner_test.go b/pkg/tests/runner_test.go index a38de6a2..70d5346c 100644 --- a/pkg/tests/runner_test.go +++ b/pkg/tests/runner_test.go @@ -954,7 +954,7 @@ func TestMissingTool(t *testing.T) { r.RespondWith(tester.Result{ Func: types.CompletionFunctionCall{ - Name: "not bob", + Name: "not.bob", }, }) diff --git a/pkg/tests/testdata/TestMissingTool/call1-resp.golden b/pkg/tests/testdata/TestMissingTool/call1-resp.golden index c9799ee8..4f4e82a0 100644 --- a/pkg/tests/testdata/TestMissingTool/call1-resp.golden +++ b/pkg/tests/testdata/TestMissingTool/call1-resp.golden @@ -5,7 +5,7 @@ "toolCall": { "id": "call_1", "function": { - "name": "not bob" + "name": "not.bob" } } } diff --git a/pkg/tests/testdata/TestMissingTool/call2.golden b/pkg/tests/testdata/TestMissingTool/call2.golden index 2fe99e81..c24d83f8 100644 --- a/pkg/tests/testdata/TestMissingTool/call2.golden +++ b/pkg/tests/testdata/TestMissingTool/call2.golden @@ -35,7 +35,7 @@ "toolCall": { "id": "call_1", "function": { - "name": "not bob" + "name": "not.bob" } } } @@ -46,13 +46,13 @@ "role": "tool", "content": [ { - "text": "ERROR: can not call unknown tool named [not bob]" + "text": "ERROR: can not call unknown tool named [notBob]" } ], "toolCall": { "id": "call_1", "function": { - "name": "not bob" + "name": "not.bob" } }, "usage": {}