SELECT ai_complete(
'endpoint:qwen3-max-preview',
CONCAT('用20字总结以下文本:', content)
) AS summary
FROM articles;
图像模式:使用具名元组语法,同时传入文本提示和图像 URL:
SELECT ai_complete(
'endpoint:doubao-seed-2-0-pro-260215',
('图片中有什么?' AS prompt,
GET_PRESIGNED_URL(USER VOLUME, 'images/product.jpg', 36000) AS image)
);
图像模式中
image
image
字段不可为 NULL,否则报错
invalid type of image field: void
invalid type of image field: void
。
options(可选)
使用
json '{}'
json '{}'
字面量语法传入,控制执行行为和模型参数:
参数键
类型
说明
model.params.temperature
model.params.temperature
FLOAT
输出随机性,范围 [0, 2],越低越确定
model.params.max_tokens
model.params.max_tokens
INT
最大输出 token 数
model.params.top_p
model.params.top_p
FLOAT
核采样概率,范围 (0, 1]
model.params.enable_thinking
model.params.enable_thinking
BOOL
是否开启 thinking 模式,批量处理建议设为
false
false
response.timeout
response.timeout
STRING
单次请求超时时间(秒),如
"60"
"60"
task.concurrency
task.concurrency
STRING
批量处理并发度,如
"5"
"5"
-- 关闭 thinking 模式
SELECT ai_complete(
'endpoint:qwen3-max-preview',
'什么是人工智能?用一句话回答',
json '{"model.params":{"enable_thinking":false}}'
) AS result;
-- 多参数组合
SELECT ai_complete(
'endpoint:qwen3-max-preview',
question,
json '{"model.params":{"enable_thinking":false},"task.concurrency":"5"}'
) AS answer
FROM questions;
返回值
返回 STRING 类型,为模型生成的响应文本。
prompt 为
NULL
NULL
或空字符串时,返回
NULL
NULL
endpoint 不存在时,报错
CZLH-67000: No available endpoints found
CZLH-67000: No available endpoints found
model 格式错误(无
endpoint:
endpoint:
或
connection:
connection:
前缀)时,报错
CZLH-65000: Invalid model coordinates
CZLH-65000: Invalid model coordinates
使用示例
基础文本补全
SELECT ai_complete('endpoint:qwen3-max-preview', '中国的首都在哪里?') AS result;
批量处理表中数据
SELECT
id,
ai_complete(
'endpoint:qwen3-max-preview',
question,
json '{"model.params":{"enable_thinking":false},"task.concurrency":"5"}'
) AS answer
FROM questions;
CONCAT 动态拼接 prompt
SELECT
product_id,
ai_complete(
'endpoint:qwen3-max-preview',
CONCAT('请为以下商品写一段30字以内的卖点描述:', product_name)
) AS selling_point
FROM products;
图像描述
SELECT ai_complete(
'endpoint:doubao-seed-2-0-pro-260215',
('图片中有什么?' AS prompt,
GET_PRESIGNED_URL(USER VOLUME, 'images/product.jpg', 36000) AS image)
) AS result;
图像 + 具体问题
SELECT ai_complete(
'endpoint:doubao-seed-2-0-pro-260215',
('这个商品的价格是多少?请用一句话回答。' AS prompt,
GET_PRESIGNED_URL(USER VOLUME, 'images/product.jpg', 36000) AS image)
) AS result;
批量图像处理
SELECT
relative_path,
ai_complete(
'endpoint:doubao-seed-2-0-pro-260215',
('用一句话描述图片中的商品。' AS prompt,
GET_PRESIGNED_URL(USER VOLUME, relative_path, 36000) AS image),
json '{"model.params":{"enable_thinking":false},"task.concurrency":"3"}'
) AS description
FROM (SHOW USER VOLUME DIRECTORY SUBDIRECTORY 'images/products')
LIMIT 10;