数据类型
在内部,通过Rivet传递的数据被标记为多种数据类型。当将Rivet与您自己的应用程序集成时,您需要了解这些数据类型是什么以及如何处理它们。
DataValue
DataValue是一个可以通过Rivet传递的值。它是所有可以通过Rivet传递的数据类型的联合体。它被表示为一个具有type
属性和value
属性的对象。type
键在下表中列出,除非类型上存在额外的类型装饰器。
装饰器
一个类型可以应用以下修饰符来改变其特性。修饰符可以组合在类型名称上,例如一个类型可以是fn
。有效的修饰符包括:
装饰器 | 描述 |
---|---|
[] | The type is an array of the type before the brackets. |
fn<type> | The type is a function that returns the type inside the angle brackets. |
类型
类型 | 描述 | TypeScript类型 | 备注 |
---|---|---|---|
any | A special type of data that can store anything. | unknown | Often, the value contained will be attempted to be either inferred based on the JavaScript type of the value, or it will be attempted to be coerced into a desired data type. Avoid using any in most cases, especially when you already know the type of a value. |
boolean | A boolean true or false. | boolean | Equivalent to the JavaScript boolean type. |
string | A string value. | string | Equivalent to the JavaScript string type. |
number | A number value. | number | Equivalent to the JavaScript number type. |
date | A date value. | string | ISO-8601 date string. |
time | A time value. | string | ISO-8601 time string. |
datetime | A datetime value. | string | ISO-8601 datetime string. |
chat-message | A representation of a chat message to sent to an LLM, with attached metadata such as who is sending it. | { type: string; message: string; name?: string; function_call?: string } | |
object | An object value. | Record<string, unknown> | Roughly equivalent to the JavaScript object type. Often used interchangably with any , and may be an array sometimes. |
control-flow-excluded | A value that is excluded from control flow. | undefined | |
gpt-function | A definition of a function that GPT can evaluate. | (See Rivet source) | Only used by the Chat node when "Enable function use" is turned on. |
vector | A vector of numbers. | number[] | Used when generating and using embeddings. |
image | An image value. | { mediaType: string; data: UInt8Array; } | |
audio | An audio value. | { mediaType: string; eata: UInt8Array; } | |
binary | A binary value. | UInt8Array |