kirara_ai/web/api/workflow/README.md
工作流 API 提供了管理工作流的功能。工作流由多个区块组成,用于处理消息和执行任务。每个工作流都属于一个特定的组。
GET/backend-api/api/workflow
获取所有已注册的工作流基本信息。
响应示例:
{
"workflows": [
{
"group_id": "chat",
"workflow_id": "normal",
"name": "普通聊天",
"description": "处理普通聊天消息的工作流",
"block_count": 3,
"metadata": {
"category": "chat",
"tags": ["normal", "chat"]
}
}
]
}
GET/backend-api/api/workflow/{group_id}/{workflow_id}
获取指定工作流的详细信息。
响应示例:
{
"workflow": {
"group_id": "chat",
"workflow_id": "normal",
"name": "普通聊天",
"description": "处理普通聊天消息的工作流",
"blocks": [
{
"block_id": "input_1",
"type_name": "MessageInputBlock",
"name": "消息输入",
"config": {
"format": "text"
},
"position": {
"x": 100,
"y": 100
}
},
{
"block_id": "llm_1",
"type_name": "LLMBlock",
"name": "语言模型",
"config": {
"backend": "openai",
"temperature": 0.7
},
"position": {
"x": 300,
"y": 100
}
},
{
"block_id": "output_1",
"type_name": "MessageOutputBlock",
"name": "消息输出",
"config": {
"format": "text"
},
"position": {
"x": 500,
"y": 100
}
}
],
"wires": [
{
"source_block": "input_1",
"source_output": "message",
"target_block": "llm_1",
"target_input": "prompt"
},
{
"source_block": "llm_1",
"source_output": "response",
"target_block": "output_1",
"target_input": "message"
}
],
"metadata": {
"category": "chat",
"tags": ["normal", "chat"]
}
}
}
POST/backend-api/api/workflow/{group_id}/{workflow_id}
创建新的工作流。
请求体:
{
"group_id": "chat",
"workflow_id": "creative",
"name": "创意聊天",
"description": "处理创意聊天的工作流",
"blocks": [
{
"block_id": "input_1",
"type_name": "MessageInputBlock",
"name": "消息输入",
"config": {
"format": "text"
},
"position": {
"x": 100,
"y": 100
}
},
{
"block_id": "prompt_1",
"type_name": "PromptBlock",
"name": "提示词处理",
"config": {
"template": "请发挥创意回答以下问题:{{input}}"
},
"position": {
"x": 300,
"y": 100
}
},
{
"block_id": "llm_1",
"type_name": "LLMBlock",
"name": "语言模型",
"config": {
"backend": "anthropic",
"temperature": 0.9
},
"position": {
"x": 500,
"y": 100
}
}
],
"wires": [
{
"source_block": "input_1",
"source_output": "message",
"target_block": "prompt_1",
"target_input": "input"
},
{
"source_block": "prompt_1",
"source_output": "output",
"target_block": "llm_1",
"target_input": "prompt"
}
],
"metadata": {
"category": "chat",
"tags": ["creative", "chat"]
}
}
PUT/backend-api/api/workflow/{group_id}/{workflow_id}
更新现有工作流。请求体格式与创建工作流相同。
DELETE/backend-api/api/workflow/{group_id}/{workflow_id}
删除指定工作流。成功时返回:
{
"message": "Workflow deleted successfully"
}
source_block: 源区块 IDsource_output: 源区块输出端口target_block: 目标区块 IDtarget_input: 目标区块输入端口block_id: 区块 IDtype_name: 区块类型名称name: 区块显示名称config: 区块配置position: 区块位置
x: X 坐标y: Y 坐标group_id: 工作流组 IDworkflow_id: 工作流 IDname: 工作流名称description: 工作流描述blocks: 区块列表wires: 连线列表metadata: 元数据(可选)group_id: 工作流组 IDworkflow_id: 工作流 IDname: 工作流名称description: 工作流描述block_count: 区块数量metadata: 元数据(可选)workflows: 工作流信息列表workflow: 工作流定义工作流中可以使用的区块类型包括:
message: 消息内容format: 消息格式(text/image/audio)message: 消息内容format: 消息格式(text/image/audio)prompt: 提示词response: 模型响应backend: 使用的后端temperature: 温度参数input: 输入内容output: 处理后的提示词template: 提示词模板所有 API 端点在发生错误时都会返回适当的 HTTP 状态码和错误信息:
{
"error": "错误描述信息"
}
常见状态码:
import requests
response = requests.get(
'http://localhost:8080/api/workflow',
headers={'Authorization': f'Bearer {token}'}
)
import requests
workflow_data = {
"group_id": "chat",
"workflow_id": "creative",
"name": "创意聊天",
"description": "处理创意聊天的工作流",
"blocks": [
{
"block_id": "input_1",
"type_name": "MessageInputBlock",
"name": "消息输入",
"config": {
"format": "text"
},
"position": {
"x": 100,
"y": 100
}
},
{
"block_id": "llm_1",
"type_name": "LLMBlock",
"name": "语言模型",
"config": {
"backend": "anthropic",
"temperature": 0.9
},
"position": {
"x": 300,
"y": 100
}
}
],
"wires": [
{
"source_block": "input_1",
"source_output": "message",
"target_block": "llm_1",
"target_input": "prompt"
}
],
"metadata": {
"category": "chat",
"tags": ["creative"]
}
}
response = requests.post(
'http://localhost:8080/api/workflow/chat/creative',
headers={'Authorization': f'Bearer {token}'},
json=workflow_data
)
import requests
response = requests.delete(
'http://localhost:8080/api/workflow/chat/creative',
headers={'Authorization': f'Bearer {token}'}
)