PrefectHQ / marvin

✨ Build AI interfaces that spark joy
https://askmarvin.ai
Apache License 2.0
5.34k stars 348 forks source link

Support `tool_choice` parameter for runs #941

Closed andehr closed 5 months ago

andehr commented 5 months ago

Closes https://github.com/PrefectHQ/marvin/issues/927

Allows you to specify the tool_choice parameter for Runs (see Open Ai docs). This parameter allows you to force the assistant to use a particular tool.

Example usage, forcing the use of the vector store file search:

from marvin.beta import Assistant, Thread
from marvin.tools.assistants import FileSearch

# new thread
thread = Thread()

# Load some assistant with a vector store attached
ai = Assistant.load(assistant_id="<assistant ID>", tools=[FileSearch],
        tool_resources={
           "file_search": {
               "vector_store_ids": ["<vector store ID>"]
           }
        })

# Run the thread, forcing the use of FileSearch
thread.run(assistant=ai, tool_choice=FileSearch)