llmINPUTBUFFERPROCESSOROUTPUT
LLM
llm 处理器(processor)将文本列的每一行发送到 OpenAI 兼容的 chat completions API,并把补全结果追加为 Utf8 列。可用它在流内完成摘要、翻译、改写、分类或结构化抽取。任何支持 OpenAI /chat/completions 协议的端点均可使用:OpenAI、Azure OpenAI(通过 headers)、vLLM 或 Ollama 网关。
它天然适合与 SQL(先构造提示词列)以及 embedding 处理器(对模型产出做向量化)搭配使用。
配置
| Field | Type | Required | Default | 描述 |
|---|---|---|---|---|
| type | string | yes | — | llm |
| api_base | string | yes | — | API 基础 URL;请求路径为 {api_base}/chat/completions。 |
| model | string | yes | — | 聊天模型名称(如 gpt-4o-mini)。 |
| field | string | 条件 | — | 待发送的输入 UTF-8 列。各行必须非 null。除非 prompt_template 通过 {{column_name}} 引用了至少一列,否则必填。 |
| target_field | string | no | response | 追加的补全结果列名称。 |
| system_prompt | string | no | — | 前置到每个请求的系统消息。 |
| prompt_template | string | no | — | 用户消息模板,支持 {{value}}(解析为 field)与 {{column_name}} 占位符,可引用批次中的任意列。非字符串列会格式化为文本;NULL 渲染为空字符串。省略时行文本即用户消息。 |
| temperature | number | no | — | 采样温度;未设置时不随请求发送。 |
| max_tokens | integer | no | — | 补全 token 上限;未设置时不随请求发送。 |
| concurrency | integer | no | 4 | 最大并发请求数;结果始终按行序回填。 |
| api_key | string | no | — | 以 Authorization: Bearer 形式发送。支持 Secret 引用。 |
| timeout_ms | integer | no | 30000 | HTTP 请求超时。 |
| retry_count | integer | no | 3 | 暂态失败(429/5xx/传输错误)的重试次数。0 表示不重试。 |
| headers | map | no | — | 额外的 HTTP 头(如 Azure 的 api-key)。 |
| stream | boolean | no | false | 请求 SSE 流式传输,并将增量(delta)组装为该行的最终补全文本。适用于会对长补全的非流式请求超时的提供商或网关。处理器仍为每行输出一段完整文本。 |
| tools | array | no | — | 原样透传的 OpenAI tools 定义,用于函数调用。 |
| tool_calls_column | string | no | — | 设置后追加该列,以 JSON 文本填充响应中的工具调用(没有时为空字符串)。流式工具调用增量按索引合并。 |
| response_format | object | no | — | 原样透传的 OpenAI response_format 规格,用于结构化输出。 |
备注
每一行对应一个请求(聊天协议没有批量形式)。未配置 on_error(或配置 fail)时,某行的确定性失败(4xx、解析错误,重试耗尽后亦然)会短路整个批次——飞行中的请求会被丢弃而非等待完成——整个批次(Batch)作为整体流向 error_output。配置 on_error: dlq/drop/error_column后,处理器实现行错误协议:每一行都会被尝试,失败行携带原因(__arkflow_row_error)而不是让整批失败——内核按策略改道或标注。配置级失败(field 列缺失或非 UTF-8)在任何策略下都让整批失败。请合理设置 concurrency 与上游批次大小,以保持在速率限制之内。发往回环(loopback)端点的请求始终绕过系统代理。
暂态 HTTP 失败(429、5xx、连接错误)会按封顶指数退避重试(retry_count,默认 3);4xx 拒绝与解析/校验失败立即失败,不重试。
示例
- type: "llm"
api_base: "https://api.openai.com/v1"
model: "gpt-4o-mini"
api_key: "${env:OPENAI_API_KEY:-}"
field: "text"
system_prompt: "Translate the text to French. Reply with the translation only."
prompt_template: "{{value}}"
concurrency: 4
完整管道示例
logging:
level: info
streams:
- id: support-tagger
input:
type: memory
pipeline:
thread_num: 4
processors:
- type: json_to_arrow
- type: llm
api_base: "https://api.openai.com/v1"
model: "gpt-4o-mini"
api_key: "${env:OPENAI_API_KEY:-}"
field: "text"
system_prompt: "Classify the support ticket with a single word: billing, bug, or feature."
target_field: "category"
temperature: 0
output:
type: stdout