Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass a list of functions/tools to client like in the API #229

Closed
jmorzeck opened this issue Jul 24, 2024 · 2 comments
Closed

Pass a list of functions/tools to client like in the API #229

jmorzeck opened this issue Jul 24, 2024 · 2 comments

Comments

@jmorzeck
Copy link

Hi there, with more and more models supporting function calling now, I am missing a way to pass a list of functions (tools) to the client. This what works perfectly calling the API:

model = "llama3.1:70b"

tools = [
    {
        "type": "function",
        "function": {
            "name": "retrieve_payment_status",
            "description": "Get payment status of a transaction",
            "parameters": {
                "type": "object",
                "properties": {
                    "transaction_id": {
                        "type": "string",
                        "description": "The transaction id."
                    }
                },
                "required": ["transaction_id"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "retrieve_payment_date",
            "description": "Get payment date of a transaction",
            "parameters": {
                "type": "object",
                "properties": {
                    "transaction_id": {
                        "type": "string",
                        "description": "The transaction id."
                    }
                },
                "required": ["transaction_id"]
            }
        }
    }
]

messages = [
    {
        "content": "What is the status and payment date of my transaction T1001?",
        "role": "user"
    }
]

data = {
    "messages": messages,
    "tools": tools,
    "model": model,
    "temperature": 0.3
}

response = requests.post('http://localhost:11434/v1/chat/completions',
                         headers={"Content-Type": "application/json"},
                         json=data)

With this, I get a response with the different tool choices and their parameters.

However, I am missing the feature to pass the list of tools to the client. I was thinking of something like this:

ollama_client = Client(host='http://localhost:11434')
response = ollama_client.chat(model=model, messages=messages, tools=tools)

Is there a way to do this without passing the tools into the system prompt? Apologies if I didn't find it elsewhere.

@jmorzeck jmorzeck changed the title Pass functions/tools like in the API Pass a list of functions/tools to client like in the API Jul 24, 2024
@anthonywu
Copy link

anthonywu commented Jul 31, 2024

I think this was implemented in chat(...): #213 https://github.com/ollama/ollama-python/pull/213/files#diff-0f246a9c084dd2ef9d4a58c02fb818ac4a114c34877e558cac88ab351daae9eeR183

help(ollama.Client.chat) in latest client main branch:P

 |  chat(self, ..., tools: Optional[Sequence[ollama._types.Tool]] = None, ...

@ParthSareen
Copy link
Contributor

Closing this out with the recent tool passing updates https://ollama.com/blog/functions-as-tools

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

No branches or pull requests

3 participants