[GH-ISSUE #8421] tool_choice argument is being ignored #51921

Closed
opened 2026-04-28 21:14:35 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @pminervini on GitHub (Jan 14, 2025).
Original GitHub issue: https://github.com/ollama/ollama/issues/8421

What is the issue?

Consider the following snippet:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from openai import OpenAI

client_kwargs = {
    'base_url': "http://localhost:11434/v1"
}

client = OpenAI(**client_kwargs)

# Messages from the log
messages = [{
    'role': 'system', 
    'content': 'You are a Kaggle grandmaster attending a competition.'
}]

# Tools specification from the log
tools = [{
    'type': 'function',
    'function': {
        'name': 'submit_review',
        'description': 'Submit a review evaluating the output of the training script.',
        'parameters': {
            'type': 'object',
            'properties': {
                'is_bug': {
                    'type': 'boolean',
                    'description': 'true if the output log shows that the execution failed or has some bug, otherwise false.'
                },
                'summary': {
                    'type': 'string',
                    'description': 'if there is a bug, propose a fix. Otherwise, write a short summary (2-3 sentences) describing the empirical findings.'
                },
                'metric': {
                    'type': 'number',
                    'description': 'If the code ran successfully, report the value of the validation metric. Otherwise, leave it null.'
                },
                'lower_is_better': {
                    'type': 'boolean',
                    'description': 'true if the metric should be minimized (i.e. a lower metric value is better, such as with MSE), false if the metric should be maximized (i.e. a higher metric value is better, such as with accuracy).'
                }
            },
            'required': ['is_bug', 'summary', 'metric', 'lower_is_better']
        }
    }
}]

# Make the API call with exact kwargs from the log
response = client.chat.completions.create(
    model='llama3.3' if 'base_url' in client_kwargs else 'gpt-4o',
    temperature=0.5,
    messages=messages,
    tools=tools,
    tool_choice={
        'type': 'function',
        'function': {'name': 'submit_review'}
    }
)

print(response)

tool_calls = response.choices[0].message.tool_calls

# Print the function call details
print(f"Tool calls: {tool_calls}")

Output:

ChatCompletion(id='chatcmpl-651', choices=[Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(content='', refusal=None, role='assistant', audio=None, function_call=None, tool_calls=None))], created=1736861285, model='llama3.3', object='chat.completion', service_tier=None, system_fingerprint='fp_ollama', usage=CompletionUsage(completion_tokens=1, prompt_tokens=59, total_tokens=60, completion_tokens_details=None, prompt_tokens_details=None))
Tool calls: None

Otoh, when using gpt-4o, I get the following:

ChatCompletion(id='chatcmpl-ApbGxne0uBHdxD8h44XhqCMX7Er3h', choices=[Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(content=None, refusal=None, role='assistant', audio=None, function_call=None, tool_calls=[ChatCompletionMessageToolCall(id='call_DWjp36UQSwc6r8UYDZB4kIct', function=Function(arguments='{"is_bug":false,"summary":"The training script executed successfully, achieving a validation metric of 0.85. This indicates a strong performance, suggesting that the model is well-tuned for the task at hand.","metric":0.85,"lower_is_better":false}', name='submit_review'), type='function')]))], created=1736861367, model='gpt-4o-2024-08-06', object='chat.completion', service_tier='default', system_fingerprint='fp_4691090a87', usage=CompletionUsage(completion_tokens=58, prompt_tokens=194, total_tokens=252, completion_tokens_details=CompletionTokensDetails(accepted_prediction_tokens=0, audio_tokens=0, reasoning_tokens=0, rejected_prediction_tokens=0), prompt_tokens_details=PromptTokensDetails(audio_tokens=0, cached_tokens=0)))
Tool calls: [ChatCompletionMessageToolCall(id='call_DWjp36UQSwc6r8UYDZB4kIct', function=Function(arguments='{"is_bug":false,"summary":"The training script executed successfully, achieving a validation metric of 0.85. This indicates a strong performance, suggesting that the model is well-tuned for the task at hand.","metric":0.85,"lower_is_better":false}', name='submit_review'), type='function')]

OS

macOS

GPU

Apple

CPU

Apple

Ollama version

0.5.5

Originally created by @pminervini on GitHub (Jan 14, 2025). Original GitHub issue: https://github.com/ollama/ollama/issues/8421 ### What is the issue? Consider the following snippet: ```python #!/usr/bin/env python3 # -*- coding: utf-8 -*- from openai import OpenAI client_kwargs = { 'base_url': "http://localhost:11434/v1" } client = OpenAI(**client_kwargs) # Messages from the log messages = [{ 'role': 'system', 'content': 'You are a Kaggle grandmaster attending a competition.' }] # Tools specification from the log tools = [{ 'type': 'function', 'function': { 'name': 'submit_review', 'description': 'Submit a review evaluating the output of the training script.', 'parameters': { 'type': 'object', 'properties': { 'is_bug': { 'type': 'boolean', 'description': 'true if the output log shows that the execution failed or has some bug, otherwise false.' }, 'summary': { 'type': 'string', 'description': 'if there is a bug, propose a fix. Otherwise, write a short summary (2-3 sentences) describing the empirical findings.' }, 'metric': { 'type': 'number', 'description': 'If the code ran successfully, report the value of the validation metric. Otherwise, leave it null.' }, 'lower_is_better': { 'type': 'boolean', 'description': 'true if the metric should be minimized (i.e. a lower metric value is better, such as with MSE), false if the metric should be maximized (i.e. a higher metric value is better, such as with accuracy).' } }, 'required': ['is_bug', 'summary', 'metric', 'lower_is_better'] } } }] # Make the API call with exact kwargs from the log response = client.chat.completions.create( model='llama3.3' if 'base_url' in client_kwargs else 'gpt-4o', temperature=0.5, messages=messages, tools=tools, tool_choice={ 'type': 'function', 'function': {'name': 'submit_review'} } ) print(response) tool_calls = response.choices[0].message.tool_calls # Print the function call details print(f"Tool calls: {tool_calls}") ``` Output: ```bash ChatCompletion(id='chatcmpl-651', choices=[Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(content='', refusal=None, role='assistant', audio=None, function_call=None, tool_calls=None))], created=1736861285, model='llama3.3', object='chat.completion', service_tier=None, system_fingerprint='fp_ollama', usage=CompletionUsage(completion_tokens=1, prompt_tokens=59, total_tokens=60, completion_tokens_details=None, prompt_tokens_details=None)) Tool calls: None ``` Otoh, when using `gpt-4o`, I get the following: ```bash ChatCompletion(id='chatcmpl-ApbGxne0uBHdxD8h44XhqCMX7Er3h', choices=[Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(content=None, refusal=None, role='assistant', audio=None, function_call=None, tool_calls=[ChatCompletionMessageToolCall(id='call_DWjp36UQSwc6r8UYDZB4kIct', function=Function(arguments='{"is_bug":false,"summary":"The training script executed successfully, achieving a validation metric of 0.85. This indicates a strong performance, suggesting that the model is well-tuned for the task at hand.","metric":0.85,"lower_is_better":false}', name='submit_review'), type='function')]))], created=1736861367, model='gpt-4o-2024-08-06', object='chat.completion', service_tier='default', system_fingerprint='fp_4691090a87', usage=CompletionUsage(completion_tokens=58, prompt_tokens=194, total_tokens=252, completion_tokens_details=CompletionTokensDetails(accepted_prediction_tokens=0, audio_tokens=0, reasoning_tokens=0, rejected_prediction_tokens=0), prompt_tokens_details=PromptTokensDetails(audio_tokens=0, cached_tokens=0))) Tool calls: [ChatCompletionMessageToolCall(id='call_DWjp36UQSwc6r8UYDZB4kIct', function=Function(arguments='{"is_bug":false,"summary":"The training script executed successfully, achieving a validation metric of 0.85. This indicates a strong performance, suggesting that the model is well-tuned for the task at hand.","metric":0.85,"lower_is_better":false}', name='submit_review'), type='function')] ``` ### OS macOS ### GPU Apple ### CPU Apple ### Ollama version 0.5.5
GiteaMirror added the bug label 2026-04-28 21:14:35 -05:00
Author
Owner
<!-- gh-comment-id:2591370676 --> @rick-github commented on GitHub (Jan 15, 2025): https://github.com/ollama/ollama/blob/main/docs/openai.md#supported-request-fields:~:text=tools-,tool_choice,-logit_bias
Author
Owner

@pminervini commented on GitHub (Jan 15, 2025):

Oof, thank you! Closing (& looking into how to add this feature)

<!-- gh-comment-id:2591876892 --> @pminervini commented on GitHub (Jan 15, 2025): Oof, thank you! Closing (& looking into how to add this feature)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#51921