Skip to content

Commit

Permalink
fix: normalize LLM-hallucinated tool names (#656)
Browse files Browse the repository at this point in the history
Signed-off-by: Grant Linville <[email protected]>
  • Loading branch information
g-linville authored Jul 23, 2024
1 parent e3a43cb commit d54d11b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pkg/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/tests/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ func TestMissingTool(t *testing.T) {

r.RespondWith(tester.Result{
Func: types.CompletionFunctionCall{
Name: "not bob",
Name: "not.bob",
},
})

Expand Down
2 changes: 1 addition & 1 deletion pkg/tests/testdata/TestMissingTool/call1-resp.golden
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"toolCall": {
"id": "call_1",
"function": {
"name": "not bob"
"name": "not.bob"
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/tests/testdata/TestMissingTool/call2.golden
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"toolCall": {
"id": "call_1",
"function": {
"name": "not bob"
"name": "not.bob"
}
}
}
Expand All @@ -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": {}
Expand Down

0 comments on commit d54d11b

Please sign in to comment.