kirara_ai/web/api/block/README.md
区块 API 提供了查询工作流构建块类型的功能。每个区块类型定义了其输入、输出和配置项。
注意:文档由 Claude 生成,可能存在错误,请以实际代码为准。
GET/backend-api/api/block/types
获取所有可用的区块类型列表。
响应示例:
{
"types": [
{
"type_name": "MessageBlock",
"name": "消息区块",
"description": "处理消息的基础区块",
"inputs": [
{
"name": "content",
"description": "消息内容",
"type": "string",
"required": true
}
],
"outputs": [
{
"name": "message",
"description": "处理后的消息",
"type": "IMMessage"
}
],
"configs": [
{
"name": "format",
"description": "消息格式",
"type": "string",
"required": false,
"default": "text"
}
]
}
]
}
GET/backend-api/api/block/types/{type_name}
获取指定区块类型的详细信息。
响应示例:
{
"type": {
"type_name": "LLMBlock",
"name": "大语言模型区块",
"description": "调用 LLM 进行对话的区块",
"inputs": [
{
"name": "prompt",
"description": "提示词",
"type": "string",
"required": true
}
],
"outputs": [
{
"name": "response",
"description": "LLM 的响应",
"type": "string"
}
],
"configs": [
{
"name": "model",
"description": "使用的模型",
"type": "string",
"required": true,
"default": "gpt-4"
},
{
"name": "temperature",
"description": "温度参数",
"type": "float",
"required": false,
"default": 0.7
}
]
}
}
POST/backend-api/api/block/types
注册新的区块类型。
请求体:
{
"type": "image_process",
"name": "图像处理",
"description": "处理图像数据",
"category": "media",
"config_schema": {
"type": "object",
"properties": {
"operation": {
"type": "string",
"enum": ["resize", "crop", "rotate"]
},
"params": {
"type": "object"
}
}
},
"input_schema": {
"type": "object",
"properties": {
"image": {
"type": "string",
"format": "binary"
}
}
},
"output_schema": {
"type": "object",
"properties": {
"image": {
"type": "string",
"format": "binary"
}
}
}
}
PUT/backend-api/api/block/types/{type}
更新现有区块类型。
DELETE/backend-api/api/block/types/{type}
删除指定区块类型。
GET/backend-api/api/block/instances/{workflow_id}
获取指定工作流中的所有区块实例。
响应示例:
{
"instances": [
{
"block_id": "input_1",
"type": "input",
"workflow_id": "chat:normal",
"config": {
"format": "text"
},
"state": {
"status": "ready",
"last_run": "2024-03-10T12:00:00Z",
"error": null
}
}
]
}
GET/backend-api/api/block/instances/{workflow_id}/{block_id}
获取指定区块实例的详细信息。
PUT/backend-api/api/block/instances/{workflow_id}/{block_id}
更新区块实例的配置。
name: 输入名称description: 输入描述type: 数据类型required: 是否必需default: 默认值(可选)name: 输出名称description: 输出描述type: 数据类型name: 配置项名称description: 配置项描述type: 数据类型required: 是否必需default: 默认值(可选)type_name: 区块类型名称name: 显示名称description: 描述inputs: 输入定义列表outputs: 输出定义列表configs: 配置项定义列表block_id: 区块实例 IDtype: 区块类型workflow_id: 所属工作流 IDconfig: 区块配置state: 区块状态metadata: 元数据(可选)status: 状态(ready/running/error)last_run: 最后运行时间error: 错误信息(如果有)metrics: 性能指标(可选)所有 API 端点在发生错误时都会返回适当的 HTTP 状态码和错误信息:
{
"error": "错误描述信息"
}
常见状态码:
import requests
response = requests.get(
'http://localhost:8080/api/block/types',
headers={'Authorization': f'Bearer {token}'}
)
import requests
response = requests.get(
'http://localhost:8080/api/block/types/LLMBlock',
headers={'Authorization': f'Bearer {token}'}
)