← Back to list

Using OpenAI Assistants Function Calling with ease

PlugBear simplifies function calling in OpenAI Assistant, eliminating the need to independently write and execute code.

Liam HwangLiam Hwang

Function calling in OpenAI Assistant, similar to actions in GPTs, enhances its capabilities. However, you must write and execute the code for function calls and output submissions independently, typically requiring deployment in a separate location. PlugBear simplifies this process, eliminating the need for you to write a single line of code.

OpenAI Assistants Function Calling

When using the OpenAI Assistant's API, you can define functions. The model can then generate a JSON-structured object containing the required arguments to call these functions. This leads to a more dependable link between the AI's abilities and external tools or APIs.

Unlike actions in GPTs, coordinating function execution is necessary. Calling a function with OpenAI assistants involves three parts.

  • First, define the function and add it to your Assistant.
  • When an assistant is initiated with a run, it enters a requires_action state after processing.
  • Finally, you can call submit_tool_outputs to pass the output of your function back to the Assistant.

OpenAPI is a well-known API documentation specification. It represents API specs in a structured way, making it ideal for function calling.

Let's consider an example. The OpenAPI specification below represents a virtual, in-house API that displays the top revenue customers for a certain product.

openapi: 3.0.0
info:
  version: 1.0.0
  title: Customers Insight API
servers:
  - url: https://salesdata.example.com/api

paths:
  /customers/top_revenue/{product}:
    get:
      summary: List Top Revenue Customers for a Product
      description: Retrieves a list of customers, sorted by their revenue from a specific product in descending order.
      parameters:
        - name: product
          in: path
          required: true
          description: The unique identifier or name of the product to retrieve top revenue customers for.
          schema:
            type: string
      responses:
        '200':
          description: Successfully fetched a list of customers by top revenue for the specified product.
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/CustomerByRevenue'
components:
  schemas:
    CustomerByRevenue:
      type: object
      properties:
        name:
          type: string
          description: The name of the customer.
        revenue:
          type: number
          description: The customer's revenue.

To use this API with OpenAI Assistants, you need to convert it into a function and register it with your Assistant.

{
  "name": "customers_top_revenue_by_product",
  "description": "Retrieves a list of customers, sorted by their revenue from a specific product in descending order.",
  "parameters": {
    "type": "object",
    "properties": {
      "path_params": {
        "type": "object",
        "properties": {
          "product": {
            "type": "string"
          }
        },
        "required": [
          "product"
        ],
      }
    },
    "required": [
      "path_params"
    ]
  }
}

The function definition marks the product parameter as required. If you instruct your Assistant to provide customer revenue for a specific product, it will intelligently determine the appropriate value for the product parameter.

If a user enters 'Show me top customers and their revenue of our ecommerce', the assistant will call the customers_top_revenue_by_product function with the argument {"path_params": {"product": "ecommerce"}}.

Since the tool call request is structured data, you can parse it, call the corresponding API based on the OpenAPI specification, and then return the result to the Assistant.

Function Calling using PlugBear

Now, let's look at how PlugBear can streamline this process for you. PlugBear's OpenAI Assistants integration supports function calling in a managed manner. You don't need to write code, run, or deploy it somewhere to invoke it, as long as it's defined as a REST API.

If you have an OpenAPI specification definition, you can directly paste it into PlugBear. This will convert it into a callable function for your OpenAI Assistant. If instructions are provided on when the assistant should execute a specific action, it will autonomously call the API and return the result to the Assistant.

PlugBear Function Calling

And that's it. You can now link your OpenAI Assistants to your preferred communication tool and enjoy it.

Chat Example

This example is created for demonstration purposes. Exercise caution when applying it to connect to an actual system. If you're automating actions such as canceling an order or sending messages to your customers based on user input, ensure that you include an additional confirmation step for your instructions.

In Closing

In conclusion, using function calling with OpenAI Assistants can streamline your daily workflow. By connecting your Assistant to internal APIs, you can craft a versatile tool that can efficiently manage tedious tasks.

If you aim to enhance your daily workflow with OpenAI function calling without altering your current work methods, consider connecting OpenAI Assistants using PlugBear to Slack or Microsoft Teams. This approach allows you to optimize your workflow without having to write code or deploy any functions.

For more details, book a demo or check out our doc site.

Get Started

Streamline your workflow, increase efficiency, and enhance your OpenAI Assistant's capabilities with function calling. Click below to explore options and start enhancing your workflow.

or get started now!