This guide explains how to use no-code applications as tools with the Chat completion endpoint.

You can use deployed no-code applications as tools in your tool calling implementation. This allows you to combine the power of no-code applications with other tools and APIs.

This approach allows you to:

  • Use no-code applications alongside other tools
  • Chain multiple applications together
  • Combine application outputs with other API calls or business logic

Tool calling is only available with Palmyra-X-004.

Implementation steps

1

Build and deploy your application

First, build a text generation or research assistant application in AI Studio and deploy it to get an application ID. Make note of the application ID and input field names as you’ll need these for the API calls.

2

Define your function

Create a function that calls your deployed application:

def generate_product_description(product_name):
    response = client.applications.generate_content(
        application_id="your-application-id",
        inputs=[
            {
                "id": "Product name",
                "value": [product_name]
            }
        ]
    )
    return response.suggestion
3

Define the tool schema

Next, define your application as a tool in your tools array:

tools = [
    {
        "type": "function",
        "function": {
            "name": "generate_product_description",
            "description": "Generate a product description using a no-code application",
            "parameters": {
                "type": "object",
                "properties": {
                    "product_name": {
                        "type": "string",
                        "description": "The name of the product"
                    }
                },
                "required": ["product_name"]
            }
        }
    }
]
4

Use the tool with chat completion

Finally, use your application as a tool in a chat completion. This example uses non-streaming responses for simplicity. For streaming implementation, follow the patterns in the tool calling guide.

messages = [{"role": "user", "content": "Generate a description for the Terra running shoe"}]

response = client.chat.chat(
    model="palmyra-x-004",
    messages=messages,
    tools=tools,
    tool_choice="auto",
    stream=False
)

response_message = response.choices[0].message
tool_calls = response_message.tool_calls
if tool_calls:
    tool_call = tool_calls[0]
    tool_call_id = tool_call.id
    function_name = tool_call.function.name
    function_args = json.loads(tool_call.function.arguments)

    if function_name == "generate_product_description":
        function_response = generate_product_description(function_args["product_name"])
        
        messages.append({
            "role": "tool",
            "tool_call_id": tool_call_id,
            "name": function_name,
            "content": function_response
        })

final_response = client.chat.chat(
    model="palmyra-x-004",
    messages=messages,
    stream=False
)

print(final_response.choices[0].message.content)
# Here's a product description for the Terra running shoe: ...

For more details on tool calling, see the tool calling guide.