Skip to content

feat: add tool_choice parameter to chat() (closes #663)#671

Open
shivanireddyk wants to merge 1 commit into
ollama:mainfrom
shivanireddyk:feat/tool-choice
Open

feat: add tool_choice parameter to chat() (closes #663)#671
shivanireddyk wants to merge 1 commit into
ollama:mainfrom
shivanireddyk:feat/tool-choice

Conversation

@shivanireddyk
Copy link
Copy Markdown

Closes #663

Adds tool_choice support to chat() (sync and async), mirroring the OpenAI API and the server's existing partial support.

Changes

  • New ToolChoiceFunction class and ToolChoice type alias in _types.py
  • Both exported from top-level ollama package
  • tool_choice field added to ChatRequest
  • All 6 chat() overloads updated (3 sync + 3 async) with typed parameter

Usage

from ollama import ToolChoiceFunction

# Forcing a specific tool
ollama.chat(
  model='llama3.2',
  tools=[get_weather],
  tool_choice=ToolChoiceFunction(
    function=ToolChoiceFunction.Function(name='get_weather')
  ),
  messages=[{'role': 'user', 'content': 'What is the weather in Paris?'}],
)

# It requires the model to call *some* tool
ollama.chat(model='llama3.2', tools=[...], tool_choice='required', messages=[...])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add tool_choice parameter to chat() (mirror server-side ollama#11171)

1 participant