GPT Function Node
Overview
The GPT Function Node allows you to define a function that can be called by OpenAI's GPT in its responses. This is part of GPT's "function-calling" capability. The function is defined using JSON Schema.
The output of the GPT Function Node can be passed into the "Function" port of the Chat Node. To enable this, you must check the "Enable Function Calling" setting in the Chat Node.
If you want to pass multiple functions into a Chat Node, all of the functions should be passed into an Array Node, and the Array Node goes into the "Function" port of the Chat Node.
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}}
.
- Inputs
- Outputs
- Editor Settings
Title | Data Type | Description | Default Value | Notes |
---|---|---|---|---|
Input N | string | Variable number of inputs for interpolated values such as {{value}} inside the schema definition of the node. | (empty string) |
Outputs
Title | Data Type | Description | Notes |
---|---|---|---|
Function | gpt-function | The function that was defined. This output can be connected to the "Function" port of a Chat Node. |
Editor Settings
Setting | Description | Default Value | Use Input Toggle | Input Data Type |
---|---|---|---|---|
Name | The name of the function. This is the name that GPT will use to call the function in its responses. | newFunction | Yes | string |
Description | A description of the function. This is used for documentation purposes and does not affect the function's behavior. | (empty) | Yes | string |
Schema | The JSON Schema that defines the function's parameters. | (empty) | Yes | object |
Example 1: Define a function that takes a single string parameter
Create a GPT Function Node.
Set the
Name
togreet
.Set the
Description
toA function that greets a user
.Set the
Schema
to the following:{
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "The name of the user"
}
},
"required": ["name"]
}Create a Chat Node and enable the "Function" input port by checking the "Enable Function Calling" setting.
Connect the
Function
output of the GPT Function Node to theFunction
input of the Chat Node.Set the
Prompt
of the Chat Node to the following, using a Text Node or Prompt Node:Please call the `greet` function with the name "John Doe".
Run the graph. The Chat Node should output a call to the
greet
function with the parametername
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 a Chat Node?
A: You can connect multiple functions to a Chat Node by passing all of the functions into an Array Node, and then connecting the Array Node to the Chat Node.