Function Calling
Note: This feature requires SDK version >= 3.2.0
Function calling allows users to connect our latest models to external tools, streamlining agentic use cases, and allowing users to integrate our models much more deeply into their workflows. Some examples of tools that users could pass to our model are:
- Calculator: Connect our models to a calculator to eliminate all hallucinations, especially if working with complex computations.
- Internal Databases Connect our models to your internal tools/databases to allow customers to ask questions about inventory and product availability.
- REST APIs: Connect our models to any REST API, allowing our models to access to the particular real-time information that you need to drive your application-specific use case.
Models That Support Function Calling
Currently, only Reka Flash supports function calling. We are working hard to quickly enable support for our other classes of models.
Step By Step Example of How to Leverage Function Calling
In this section, we will go through step by step how to use Reka’s function calling capabilities with a concrete example. For this example, we will define two functions: get_product_availability
, and get_similar_products
. Both take in a product id, and get_similar_products
additionally takes in the maximum number of results to return, allowing customers to ask questions about various products.
Step 1: Define The Tools
First, we must create a specification for each function. We pass these specs to the model to connect them to the tools.
Step 2: Pass the Tools Along With a User Query to the Model
Now that we have defined the tools our model has access to, we can query the model by passing in these tools along with a user query. Assume we have the following user query:
We can then query the model using the usual client.chat.create
:
This will print a response like:
Tool Choice
The tool_choice
parameter controls how the model uses the tools you pass. There are three available options:
- auto lets the model decide whether or not to invoke a tool. This is the recommended way to do function calling with our models
- none disables tool calling. In this case, even if you pass tools to the model, the model will not invoke any tools
- tool forces the model to invoke one or more of the tools it has been passed
Model Response Type
Note that if tool_choice
is set to auto
, the model will decide whether or not to invoke a function. If the model chooses to invoke a function, the invocations can be extracted according to the code snippet above. In this case, response.responses[0].message.content
will be None
. In the case that the model refrains from making a function call, the converse will be true: tool_calls
will be None
and content
will contain the model’s natural language response.
Step 3: Execute the Function
In the case the model decides to invoke a tool, the next step is to execute the function to obtain the output from the function invocation.
Step 4: Pass the Result Back to the Model
Finally, we can pass the result back to the model in order to receive a natural language response based on the result of the function execution.
This will print a response like