serve: tool_choice required with a single tool names it (#790)
This commit is contained in:
1 parent
82579827e9
commit
8e368af984
2 files changed
+11
No files matched your search
@@ -496,6 +496,8 @@ def forced_call(tool_choice, tools: list[dict] | None) -> str | None:
|
||||
names = {t.get("name") for t in tools or [] if isinstance(t, dict)}
|
||||
if kind in ("auto", "none"):
|
||||
return None
|
||||
if kind == "required" and len(names) == 1: # one tool to call: name it, the model cannot invent another
|
||||
kind, name = "named", next(iter(names))
|
||||
if kind == "required" and names:
|
||||
return CALL_START + "\n<function="
|
||||
if kind == "named" and name in names:
|
||||
|
||||
@@ -92,3 +92,12 @@ class EmptyTurnsSwitch(unittest.TestCase):
|
||||
self.assertEqual(template.render(msgs), clean)
|
||||
with mock.patch.dict(os.environ, {"STRATA_KEEP_EMPTY_TURNS": "1"}):
|
||||
self.assertNotEqual(template.render(msgs), clean)
|
||||
|
||||
|
||||
class ForcedCallOpening(unittest.TestCase):
|
||||
def test_required_with_one_tool_names_it(self):
|
||||
from serve.frontend import forced_call
|
||||
one, two = [{"name": "a"}], [{"name": "a"}, {"name": "b"}]
|
||||
self.assertTrue(forced_call("required", one).endswith("<function=a>\n"))
|
||||
self.assertTrue(forced_call("required", two).endswith("<function="))
|
||||
self.assertIsNone(forced_call("auto", one))
|
||||
Reference in new issue
Block a user