Use no-code applications as tools
You can use deployed no-code applications as tools in chat completions with Palmyra-X-004.
This approach allows you to:
- Use no-code applications alongside other tools
- Chain multiple no-code applications together
- Combine application outputs with other API calls or business logic
If you don’t have a deployed no-code application, build a text generation or research assistant application in AI Studio and deploy it to get an application ID.
You need an API key to access the Writer API. Get an API key by following the steps in the API quickstart.
We recommend setting the API key as an environment variable in a .env
file with the name WRITER_API_KEY
.
Tool structure
To use a no-code application as a tool, define the tool in a tools
array when making the request to the chat endpoint.
The tools
array contains an object with the following parameters:
Parameter | Type | Description |
---|---|---|
type | string | The type of tool, which is function for a no-code application |
function | object | An object containing the tool’s description and application ID |
function.name | string | The name of the tool |
function.description | string | A description of what the tool will be used for |
function.parameters | object | An object containing the tool’s input parameters |
function.parameters.type | string | The string object |
function.parameters.properties | object | An object containing the tool’s parameters in the form of a JSON schema. See below for more details. |
function.parameters.required | array | An array of the tool’s required parameters |
function.parameters.properties
The function.parameters.properties
object contains the tool’s parameter definitions as a JSON schema. The object’s keys should be the names of the parameters, and the values should be objects containing the parameter’s type and description.
When the model decides you should use the tool to answer the user’s question, it will return the parameters that you should use when calling the function you’ve defined.
Below is an example of a tool definition for a no-code application that generates product descriptions.
To help the model understand when to use the tool, follow these best practices for the function.description
parameter:
- Indicate that the tool is a function that invokes a no-code application
- Specify the application’s purpose and capabilities
- Describe when the tool should be used
An example description for a tool that invokes a text-generation application:
“A function that invokes a text-generation application, specialized in generating product descriptions. Any user request asking for product descriptions should use this tool.”
Response format
When the model decides to use a custom tool, the response from the tool call is returned in the tool_calls
object. The tool_calls
object contains the following fields:
Parameter | Type | Description |
---|---|---|
tool_calls[0].id | string | The ID of the tool call |
tool_calls[0].function | object | An object containing the function to call |
tool_calls[0].function.type | string | The type of tool, which is function for a no-code application |
tool_calls[0].function.name | string | The name of the function to call |
tool_calls[0].function.arguments | string | A JSON-formatted string containing the arguments to pass to the function |
Here is an example of a chat completion response that includes a tool call. In this example, the model decides to use the generate_product_description
tool to answer the user’s question, and provides the arguments to pass to the function.
Usage example
The following example demonstrates how to use a no-code text generation application as a tool in a chat completion. The example uses a hypothetical product description application, but you can use any no-code application in this way.
Create a function that calls your deployed application
First, create a function that calls your deployed application. You will use this function if the LLM you’re chatting with decides to use the tool.
The function below takes a product_name
parameter, invokes a no-code text generation application with the application’s required input fields, and returns the generated product description.
If you are unfamiliar with how to invoke a no-code application with the SDK, see the no-code application guide.
Define your application as a tool
Next, define your application as a tool so the LLM knows when to use it. See the tool structure section for more details on the tool object.
Use your application as a tool in a chat completion
Add the tools array to the chat endpoint call along with your array of messages. Setting tool_choice
to auto
allows the model to choose when to use the no-code application tool, based on the user’s question and the description of the tool.
When the model decides to use the tool you’ve defined, it will indicate that in the tool_calls
object of the response.
This example uses a non-streaming response. For a streaming implementation, and to learn more about processing custom tool call responses, see the tool calling guide.
Here is the full code example:
Next steps
Now that you’ve defined a custom tool, learn about prebuilt tools and how to use them in your applications:
Was this page helpful?