Skip to content

Commit 978d755

Browse files
committed
escape clause for tool calling
1 parent 3e4a334 commit 978d755

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

koboldcpp.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2477,8 +2477,9 @@ def determine_tool_json_to_use(genparams, curr_ctx, assistant_message_start, is_
24772477
for name in toolnames:
24782478
pollgrammar += ("" if pollgrammar=="" else " | ")
24792479
pollgrammar += "\"" + name + "\""
2480+
pollgrammar += " | \"no_tool\""
24802481
pollgrammar = r'root ::= ' + pollgrammar
2481-
decide_tool_prompt = "Which of the listed tools should be used next? Pick exactly one. (Reply directly with the selected tool's name):"
2482+
decide_tool_prompt = "Which of the listed tools should be used next? Pick exactly one. If no tool is suitable, reply no_tool. (Reply directly with the selected tool's name):"
24822483
temp_poll = {
24832484
"prompt": f"{curr_ctx}\n\nTool List:\n{tools_string}\n\n{decide_tool_prompt}{assistant_message_start}",
24842485
"max_length":16,
@@ -2491,12 +2492,15 @@ def determine_tool_json_to_use(genparams, curr_ctx, assistant_message_start, is_
24912492
temp_poll_result = generate(genparams=temp_poll)
24922493
if temp_poll_result:
24932494
raw = temp_poll_result['text'].lower()
2494-
for name in toolnames:
2495-
if name.lower() in raw:
2496-
used_tool_json = extract_tool_info_from_tool_array(name, tools_array)
2497-
if not args.quiet:
2498-
print(f"\nAttempting to use tool: {name}")
2499-
break
2495+
if "no_tool" in raw:
2496+
print(f"\nNo suitable tool found.")
2497+
else:
2498+
for name in toolnames:
2499+
if name.lower() in raw:
2500+
used_tool_json = extract_tool_info_from_tool_array(name, tools_array)
2501+
if not args.quiet:
2502+
print(f"\nAttempting to use tool: {name}")
2503+
break
25002504

25012505
return used_tool_json
25022506

0 commit comments

Comments
 (0)