Chat Node
概述
Chat节点向LLM(如OpenAI的GPT或任何与OpenAI API兼容的API)发送一条或多条消息,然后返回LLM的响应。
您可以使用Chat Node来连接本地LLM,只要它们的API与OpenAI API兼容。例如,您可以将Chat Node与LM Studio一起使用。
如果您正在寻找不支持OpenAI API格式的其他语言模型,请参阅插件页面,查看实现其他语言模型节点的可用插件列表。
- 输入
- 输出
- 编辑器设置
输入项
标题 | 数据类型 | 描述 | 默认值 | 备注 |
---|---|---|---|---|
System Prompt | string or chat-message | A convenience input that allows a system prompt to be prepended to the main prompt message/messages. | (None) | If not connected, then no system prompt will be prepended. You can always include a system prompt in the main prompt input instead, if you like instead, using an Assemble Prompt node. |
Prompt | string / string[] / chat-message / chat-message[] | The main prompt to send to the language model. Can be one or more strings or chat-messages. | (Empty list) | Strings will be converted into chat messages of type user , with no name. |
Functions | gpt-function or gpt-function[] | Defines the available functions that GPT is allowed to call during its response. | (Required) | Only enabled if the Enable Function Use setting is enabled. |
输出
标题 | 数据类型 | 描述 | 备注 |
---|---|---|---|
响应 | string | 来自GPT的响应。 | 响应将以流式方式传入,但在响应完成前不会执行后续节点。 |
编辑器设置
设置 | 描述 | 默认值 | 使用输入切换 | 输入数据类型 |
---|---|---|---|---|
Model | The GPT model to use for the request. If you are not using OpenAI's GPT, and you would like to set the model parameter, you can see the Custom Model setting below. | gpt-3.5-turbo | Yes | string |
Temperature | The sampling temperature to use. Lower values are more deterministic. Higher values are more "creative". | 0.5 | Yes | number |
Top P | Alternate sampling mode using the top X% of values. 0.1 corresponds to the top 10%. | 1 | Yes | number |
Use Top P | Whether to use the Top P sampling mode. | false | Yes | boolean |
Max Tokens | The maximum number of tokens that GPT is allowed to return. When hitting the max tokens, the response will be cut off. | 1024 | Yes | number |
Stop | Comma separated list of stop tokens. If any stop token is encountered, the response will end immediately. | (None) | Yes | string[] |
Presence Penalty | Applies a penalty or bonus for tokens that have already been used. See the OpenAI documentation for more info. | 0 | Yes | number |
Frequency Penalty | Applies a penalty or bonus for tokens based on how much they have been used. See the OpenAI documentation for more info. | 0 | Yes | number |
User | Attaches a user field, for monitoring and detecting abuse. See the OpenAI documentation for more info. | (Empty) | Yes | string |
Number of Choices | Allows the Chat Node to output a list of responses simultaneously if the value is greater than 1. Each response will have a unique set of text (assuming the temperature is more than 0) | 1 | Yes | number |
Enable Function Use | Allows the use of functions in the prompt. Enables the Functions input. | false | No | N/A |
缓存 | 在Rivet中本地缓存响应。如果聊天节点再次收到完全相同的提示,它将返回缓存的响应,而不是向OpenAI发起新请求。 | false | 否 | N/A |
用于子图部分输出 | 如果启用,聊天节点将用于生成子图的部分输出。这只是视觉上的 - 聊天节点的部分输出将显示为子图的部分输出。只有在聊天节点将与其他聊天节点同时独立运行时才启用,以避免问题。 | true | No | N/A |
Endpoint | The endpoint to use for the request. For example, you can set the endpoint to http://localhost:1234/v1/chat/completions for LM Studio. You may also set a global Chat Node endpoint int the Rivet Settings page. | (empty string, uses the default endpoint configured in Settings, or OpenAI's chat completions endpoint if that is not set.) | No | string |
Custom Model | If you are not using OpenAI's GPT, you can set the model parameter here, to a custom string. This parameter overrides the model defined above. | (None) | No | string |
Headers | Allows you to set custom headers to send with the request. | (None) | Yes | object |
有关所有设置,请参阅OpenAI API文档获取更多信息。
示例1:简单响应
- 在您的图表中添加一个Chat节点。
- 添加一个文本节点,并通过打开其编辑器将您的消息放入GPT内部的文本节点中,将
{{input}}
替换为您的消息。 - 将文本节点的输出连接到Chat节点的
Prompt
输入。 - 运行您的图形。您将在节点底部看到Chat节点的输出。
示例2:连接到LM Studio
- 在您的图表中添加一个Chat节点。
- 添加一个文本节点,并通过打开其编辑器将您的消息放入GPT中,将
{{input}}
替换为您的消息。 - 将文本节点的输出连接到Chat节点的
Prompt
输入。 - 将
Endpoint
设置设为http://localhost:1234/v1/chat/completions
。 - 将您想要的模型加载到LM Studio中。
- 在LM Studio服务器选项中启用CORS。
- 运行您的图形。您将在节点底部看到Chat节点的输出。
错误处理
如果没有任何内容连接到Prompt
输入,Chat节点将会报错。
如果由于速率限制导致对OpenAI的请求失败,Chat节点将使用带有抖动的指数退避算法重试请求。此重试将持续最多5分钟。如果5分钟后请求仍然失败,Chat节点将报错。
注意不要过度拆分Chat节点,以免遇到速率限制问题。
如果OpenAI返回500级错误(由于过载或停机等原因),Chat节点将以类似方式重试。
常见问题
问:如果我将不同的数据类型连接到提示或系统提示输入会怎样?
A: 该值会被尝试转换为字符串,这将变成一个user
类型的聊天消息。例如数字5会变成用户消息"5"。
如果该值无法转换为字符串,则会被忽略不计入提示消息列表。
问:如果某个输入已切换开启但未连接会怎样?
A: 将使用在UI界面中配置的值。
问:如果系统提示已连接,但提示本身没有连接怎么办?
A: Chat Node 将会报错。提示输入是必填项。如果只想发送系统提示,可以使用Prompt节点创建系统类型的提示,并将其连接到Prompt
输入。
问:如果系统提示已连接,且提示中还包含系统提示,该怎么办?
A: 两个系统提示都会被发送。在GPT中,非对话链中第一条消息的系统提示属于未定义行为。它可能有效,也可能表现异常。系统可能会遵循其中一个或两个提示。