GPT功能节点

概述
GPT函数节点允许您定义一个函数,该函数可以被OpenAI的GPT在其响应中调用。这是GPT"函数调用"功能的一部分。该函数使用JSON Schema进行定义。
GPT功能节点的输出可以传递到Chat Node的"Function"端口。要实现这一点,您必须在Chat节点中勾选"Enable Function Calling"设置。
如果想将多个函数传递到聊天节点中,所有函数都应传入一个数组节点,然后将该数组节点连接到聊天节点的"Function"端口。
函数使用JSON Schema定义,这是一种允许您注释和验证JSON文档的词汇表。有关JSON Schema的更多信息,请参阅官方网站。
您可以在GPT函数模式中使用插值,就像在文本和提示节点中使用它们一样。将您的插值用双大括号包裹起来,例如{{value}}。
- 输入
- 输出
- 编辑器设置
| 标题 | 数据类型 | 描述 | 默认值 | 备注 |
|---|---|---|---|---|
| Input N | string | Variable number of inputs for interpolated values such as {{value}} inside the schema definition of the node. | (empty string) |
输出
| 标题 | 数据类型 | 描述 | 备注 |
|---|---|---|---|
| Function | gpt-function | The function that was defined. This output can be connected to the "Function" port of a Chat Node. |
编辑器设置
| 设置 | 描述 | 默认值 | 使用输入切换 | 输入数据类型 |
|---|---|---|---|---|
| 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 |
示例1:定义一个接收单个字符串参数的函数
创建一个GPT函数节点。
将
Name设置为greet。将
Description设置为A function that greets a user。将
Schema设置为以下内容:{
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "用户名"
}
},
"required": ["name"]
}创建一个Chat Node并通过勾选"Enable Function Calling"设置来启用"Function"输入端口。
将GPT功能节点的
Function输出连接到聊天节点的Function输入。将聊天节点的
Prompt设置为以下内容,使用文本节点或提示节点:请使用名称"John Doe"调用`greet`函数。运行图表。Chat节点应该会输出一个对
greet函数的调用,其中参数name被设置为"John Doe"。

错误处理
如果Schema不是有效的JSON字符串,或者它不代表有效的JSON Schema,GPT Function Node将会报错。
常见问题
问:我可以定义一个接受多个参数的函数吗?
A: 是的,你可以通过向Schema添加更多属性来定义一个接受多个参数的函数。每个属性代表函数的一个参数。
问:我可以定义一个接受数组或对象作为参数的函数吗?
A: 是的,您可以通过将Schema中属性的type设置为array或object来定义一个接受数组或对象作为参数的函数。
问:我可以定义一个不需要任何参数的函数吗?
A: 是的,你可以通过将Schema设置为空对象({})来定义一个不需要任何参数的函数。
问:我可以使用GPT函数节点来定义一个返回值的函数吗?
A: 不,GPT函数节点仅定义函数的名称和参数。函数的行为由图的其余部分决定。
问:如何将多个功能连接到聊天节点?
A: 您可以通过将所有函数传递到Array Node中,然后将Array Node连接到Chat Node,从而将多个函数连接到一个Chat Node。