Tool calling

Langbase offers tool calling with OpenAI models to provide more flexibility and control over the conversation. You can use this feature to call tools in your code and pass the results back to the model.

How does it work?

  1. Describe the tool: You can describe a tools in your Pipe by providing the tool name, description, and arguments. You can also specify the data type of the arguments and if they are required or optional. These tools are then passed to the model.
  2. User prompt: You sent a user prompt that requires data that the tool can provide. The model will generate a JSON object with tool name and its arguments.
  3. Call the tool: You can use this JSON object to call the tool in your code.
  4. Pass the result: You can pass the result back to the model to continue the conversation.

How to use tool calling in Langbase?

You can use tool calling with the Generate API and Chat API. Here are the steps to use tool calling with both APIs:

  1. Learn how to use tool calling with the Generate API.
  2. Learn how to use tool calling with the Chat API.

Tool definition schema

Tool calling features requires you to add a tool definition schema in your Pipe. This tool definition is passed to the model. The model then generates a JSON object with the tool name and its arguments based on the user prompt.

Note

name key is required

The tool definition schema must contain name key inside function that is the name of the tool. You can also provide a description of the tool, the parameters it accepts, and their data types among other key/value pairs.

Here is an example of a valid tool definition schema:

{
    "type": "function",
    "function": {
        "name": "get_current_weather",
        "description": "Get the current weather of a given location",
        "parameters": {
            "type": "object",
            "required": [
                "location"
            ],
            "properties": {
                "unit": {
                    "enum": [
                        "celsius",
                        "fahrenheit"
                    ],
                    "type": "string"
                },
                "location": {
                    "type": "string",
                    "description": "The city and state, e.g. San Francisco, CA"
                }
            }
        }
    }
}