Categories:

String & binary functions (AI Functions)

AI_COMPLETE(单张图像)

Note

AI_COMPLETE is the updated version of . For the latest functionality, use AI_COMPLETE.

使用支持的语言模型,根据文本提示生成响应(补全)。该函数的此变体为 AI_COMPLETE 增强了文档理解能力。提示可以引用包含文档的文件中找到的信息或图像。该函数支持单个文档输入。

语法

The function has three required arguments and one optional argument. The function can be used with either positional or named argument syntax.

将 AI_COMPLETE 与单个图像输入结合使用:

AI_COMPLETE(
    <model>, <predicate>, <file> [, <model_parameters> ] )

实参

model

指定要使用模型的字符串。指定以下模型之一:

  • claude-3-7-sonnet
  • claude-4-opus
  • claude-4-sonnet
  • claude-haiku-4-5
  • claude-opus-4-5
  • claude-opus-4-6
  • claude-opus-4-7
  • claude-sonnet-4-5
  • claude-sonnet-4-6
  • gemini-3.1-pro
  • llama4-maverick
  • llama4-scout
  • openai-gpt-4.1
  • openai-gpt-5
  • openai-gpt-5-chat
  • openai-gpt-5-mini
  • openai-gpt-5-nano
  • openai-gpt-5.1
  • openai-gpt-5.2
  • openai-gpt-5.4
  • pixtral-large

Supported models might have different costs.

predicate

字符串提示符。

file

代表图像的 FILE 类型对象。

model_parameters

An object containing zero or more of the following options that affect the model’s hyperparameters. See LLM Settings (https://www.promptingguide.ai/introduction/settings).

  • temperature: A value from 0 to 1 (inclusive) that controls the randomness of the output of the language model. A higher temperature (for example, 0.7) results in more diverse and random output, while a lower temperature (such as 0.2) makes the output more deterministic and focused.

默认值:0

  • top_p: A value from 0 to 1 (inclusive) that controls the randomness and diversity of the language model, generally used as an alternative to temperature. The difference is that top_p restricts the set of possible tokens that the model outputs, while temperature influences which tokens are chosen at each step.

默认值:0

  • max_tokens: Sets the maximum number of output tokens in the response. Small values can result in truncated responses.

默认值:4096。最大允许值:8192

  • guardrails: Filters potentially unsafe and harmful responses from a language model using Cortex Guard. Either TRUE or FALSE. The default value is FALSE.

返回

返回来自语言模型的字符串响应。

示例

The following examples demonstrate the basic capabilities of the AI_COMPLETE function with images.

视觉问答

通货膨胀率图表用于回答有关数据的问题。

Graph of inflation rates in 2023 with estimates for 2024

Comparison between inflation rates in 2023 and in 2024 (Statista (https://www.statista.com/))

SELECT AI_COMPLETE('claude-sonnet-4-6',
    'Which country will observe the largest inflation change in 2024 compared to 2023?',
    TO_FILE('@myimages', 'highest-inflation.png'));

响应:

Looking at the data, Venezuela will experience the largest change in inflation rates between 2023 and 2024.
The inflation rate in Venezuela is projected to decrease significantly from 337.46% in 2023 to 99.98% in 2024,
representing a reduction of approximately 237.48 percentage points. This is the most dramatic change among
all countries shown in the chart, even though Zimbabwe has higher absolute inflation rates.

从图像中提取实体

此示例从图像中提取实体(对象)并以 JSON 格式返回结果。

Photograph of kitchen after remodeling
SELECT AI_COMPLETE('claude-sonnet-4-6',
    'Extract the kitchen appliances identified in this image. Respond in JSON only with the identified appliances.',
    TO_FILE('@myimages', 'kitchen.png'));

响应:

{
    "appliances": [ "microwave","electric stove","oven","refrigerator" ]
}

关于处理图像的使用说明

  • 仅支持文本和图像。不支持视频和音频文件。

  • 支持的图像格式:

    • .jpg
    • .jpeg
    • .png
    • .gif
    • .webp
    • pixtral and llama4 models also support .bmp.
  • The maximum image size is 10 MB for most models, and 3.75 MB for claude models. claude models do not support images with resolutions above 8000x8000.

  • 包含图像的暂存区必须启用服务器端加密。不支持客户端加密暂存区。

  • 该函数不支持自定义网络策略。

  • 暂存区名称不区分大小写;路径区分大小写。