ai_generate_text
function
Applies to: Databricks SQL
Preview
This feature is in Public Preview.
Returns text generated by a selected large language model (LLM) given the prompt.
Requirements
This function is only available on Databricks SQL Pro and Serverless.
This feature is in public preview. To enroll in the public preview, please populate and submit the AI Functions Public Preview enrollment form.
Arguments
prompt
: A string expression, the text prompt that passed to selected LLM.modelName
: A STRING literal, only'openai/gpt-3.5-turbo'
and'azure_openai/gpt-35-turbo'
are supported.paramN
andvalueN
: key-value pairs to authenticate and configure the selected LLM. The keys must be string literals and are case-sensitive. The types of the values depend on the following keys:Model
'openai/gpt-3.5-turbo'
uses the chat completion API from Open AI. It supports the following parameters:'apiKey'
: Required. The OpenAI API key to access the model endpoint. You must use the secret function to specify its value.'temperature'
: The sampling temperature to use. Its value is a numeric literal between0
and2
. The default value is1.0
.stop
: Stop strings. Its value is aSTRING
literal or anARRAY<STRING>
of up to 4 string literals. The default value is null.
Model
'azure_openai/gpt-35-turbo'
uses the chat completion API from the Azure OpenAI Service. It accepts all parameters from the above'openai/gpt-3.5-turbo'
model and any additional parameters to construct the endpoint URL. Databricks only supports API Key authentication.'resourceName'
: Required. Its value is a string literal to specify the resource name.'deploymentName'
: Required. Its value is a string literal to specify the deployment name.'apiVersion'
: Required. Its value is a string literal to specify the API version to use.
Examples
> SELECT ai_generate_text('Hello', 'openai/gpt-3.5-turbo',
'apiKey', secret('ml', 'key'),
'temperature', 0.1);
Hello! How can I assist you today?
> SELECT ai_generate_text('Hello',
'azure_openai/gpt-35-turbo',
'apiKey', secret('ml', 'key'),
'resouceName', 'resource',
'deploymentName', 'deploy',
'apiVersion', '2023-03-15-preview',
'temperature', 0.1);
Hello! How can I assist you today?
> SELECT ai_generate_text('Hello',
'openai/gpt-3.5-turbo',
'apiKey', 'sg-xxxxxxxxxxxxxxxxxxxxxx',
'temperature', 0.1);
Error: DATATYPE_MISMATCH.INVALID_SECRET
The value expression of API_TOKEN can only be a `secret(<scope>, <key>)` function; however, got StringLiteral sg-xxxxxxxxxxxxxxxxxxxxxx.