snowflake.snowpark.functions.ai_complete¶
- snowflake.snowpark.functions.ai_complete(model: str, prompt: ColumnOrLiteralStr, model_parameters: Optional[dict] = None, response_format: Optional[dict] = None, show_details: Optional[bool] = None, _emit_ast: bool = True) Column[source]¶
- snowflake.snowpark.functions.ai_complete(model: str, prompt: str, file: Column, model_parameters: Optional[dict] = None, response_format: Optional[dict] = None, show_details: Optional[bool] = None, _emit_ast: bool = True) Column
Generates a response (completion) for a text prompt using a supported language model.
This function supports three main usage patterns: 1. String prompt only: AI_COMPLETE(model, prompt, …) 2. Prompt with file: AI_COMPLETE(model, prompt, file, …) 3. Prompt object: AI_COMPLETE(model, prompt_object, …)
- Parameters:
model – A string specifying the model to be used. Different input types have different supported models. See details in AI_COMPLETE.
prompt – A string prompt, or a Column object from
prompt().file – The FILE type column representing an image. When provided, prompt should be a string.
model_parameters –
Optional object containing model hyperparameters:
temperature: A value from 0 to 1 controlling randomness (default:
0)top_p: A value from 0 to 1 controlling diversity (default:
0)max_tokens: Maximum number of output tokens (default:
4096, max:8192)guardrails: Enable Cortex Guard filtering (default:
FALSE)
response_format – Optional JSON schema that the response should follow for structured outputs.
show_details – Optional boolean flag to return detailed inference information (default:
FALSE).
- Returns:
response_formatandshow_detailsare only supported for single string. Whenshow_detailsisFALSEandresponse_formatis not specified: Returns a string containing the response. Whenshow_detailsisFALSEandresponse_formatis specified: Returns an object following the provided format. Whenshow_detailsisTRUE: Returns a JSON object with detailed inference information including choices, created timestamp, model name, and token usage statistics. See details in AI_COMPLETE Returns.
Examples: