Skip to main content
This recipe generates function calls for user requests. It also shows how to give each row of a dataset its own generation parameters, so that each request can see a different set of tools. The full code is in the function calling example on GitHub.
1

Import the libraries

2

Define the function call generator

Set return_completions_object = True so that parse gets the full API response. The model may return a tool call or a plain message, so parse handles both.
3

Define the tools

This list defines two tools. The first gets the weather for a location, and the second gets the local time.
4

Create the generator with default parameters

By default, every request can use both tools.
5

Set generation parameters for each row

Add a generation_params column to the dataset. For each row, Curator starts from the default generation parameters and replaces the keys that the row sets.
Here the first row can use only the weather tool, and the second row can use only the time tool.
Store generation_params as a JSON string. If you store a dictionary, the datasets library splits its keys into separate columns. See issue 325 for details.
6

Run the generator

Curator sends each row with its own tools, and the model returns a function call for each request.
You can use row-level parameters whenever different rows need different settings, e.g., to give each type of request only the tools it needs. In parse, always handle both tool calls and plain messages.