Skip to main content

GPT Function Node

GPT Function Node Screenshot

Overview

The GPT Function Node defines a JSON-schema-backed tool/function that an LLM can call in its response.

The output of the GPT Function Node can be passed into the Tools port of the LLM Chat Node. To enable this, turn on tool use in the LLM Chat node's Tools section.

If you want to pass multiple functions into an LLM Chat node, collect the functions with an Array Node, then connect that array to the LLM Chat node's Tools port.

A function is defined using JSON Schema, which is a vocabulary that allows you to annotate and validate JSON documents. For more information on JSON Schema, see the official website.

You may use interpolation values in the GPT Function schema the same way you can use them in the Text and Prompt nodes. Wrap your interpolation values in double curly braces, e.g. {{value}}.

TitleData TypeDescriptionDefault ValueNotes
Input NstringVariable number of inputs for interpolated values such as {{value}} inside the schema definition of the node.(empty string)

Example 1: Define a function that takes a single string parameter

  1. Create a GPT Function Node.

  2. Set the Name to greet.

  3. Set the Description to A function that greets a user.

  4. Set the Schema to the following:

    {
    "type": "object",
    "properties": {
    "name": {
    "type": "string",
    "description": "The name of the user"
    }
    },
    "required": ["name"]
    }
  5. Create an LLM Chat Node and enable tool use in its Tools section.

  6. Connect the Function output of the GPT Function Node to the Tools input of the LLM Chat Node.

  7. Set the Prompt of the LLM Chat Node to the following, using a Text Node or Prompt Node:

    Please call the `greet` function with the name "John Doe".
  8. Run the graph. The LLM Chat node should output a tool/function call to greet with the parameter name set to "John Doe".

Error Handling

The GPT Function Node will error if the Schema is not a valid JSON string or if it does not represent a valid JSON Schema.

FAQ

Q: Can I define a function that takes multiple parameters?

A: Yes, you can define a function that takes multiple parameters by adding more properties to the Schema. Each property represents a parameter of the function.

Q: Can I define a function that takes an array or an object as a parameter?

A: Yes, you can define a function that takes an array or an object as a parameter by setting the type of the property in the Schema to array or object.

Q: Can I define a function that does not take any parameters?

A: Yes, you can define a function that does not take any parameters by setting the Schema to an empty object ({}).

Q: Can I use the GPT Function Node to define a function that returns a value?

A: No, the GPT Function Node only defines the function's name and parameters. The function's behavior is determined by the rest of the graph.

Q: How can I connect multiple functions to an LLM Chat Node?

A: You can connect multiple functions to an LLM Chat Node by passing all of the functions into an Array Node, and then connecting the Array Node to the LLM Chat Node's Tools input.

See Also