keep recovery tool choices provider compatible

This commit is contained in:
pewdiepie-archdaemon
2026-09-18 01:40:57 +00:00
parent 01fc714d45
commit 4deb8ebe5a
2 changed files with 42 additions and 1 deletions
+19 -1
View File
@@ -184,7 +184,8 @@ def search_tool_choice_request(request):
def provider_compatible_tool_choice_request(request, model):
"""Keep tools but avoid forced choice unsupported by thinking providers."""
if canonical(model) == 'deepseek-flash' and 'tool_choice' in request:
model_name = canonical(str(model or '')).casefold()
if model_name.startswith('deepseek') and 'tool_choice' in request:
compatible = dict(request)
choice = compatible.get('tool_choice')
selected_name = (
@@ -200,6 +201,23 @@ def provider_compatible_tool_choice_request(request, model):
compatible['tools'] = selected
compatible.pop('tool_choice', None)
return compatible
if (
request.get('tool_choice') == 'required'
and len(request.get('tools') or []) == 1
and ('qwen' in model_name or model_name.startswith('odysseus-'))
):
# Raw-policy capture accepts a named tool constraint (and records that
# turn as excluded from policy loss), but deliberately rejects the
# distribution-wide ``required`` mode. Search recovery narrows the
# schema to one tool before reaching this boundary, so preserving that
# exact name has the same runtime intent without a transport failure.
compatible = dict(request)
name = request['tools'][0]['function']['name']
compatible['tool_choice'] = {
'type': 'function',
'function': {'name': name},
}
return compatible
return request