Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Did you hear? There's a new SQL AI Developer certification (DP-800). Start preparing now and be one of the first to get certified. Register now

0

SQL AI Functions - Select LLM Model

Built-in T-SQL AI functions leveraging GPT-4 for enrichment. The user would like to set the LLM for AI Functions.

Status: Completed

Please check this learn document - sp_invoke_external_rest_endpoint (Transact-SQL) - SQL Server | Microsoft Learn

Also, Here's a sample code

 DECLARE @url nvarchar(4000) = '<URL for Chat GPT model that you have deployed>';
    DECLARE @payload nvarchar(max) = N'{
        "messages": [
            {
                "role": "system",
                "content": "You are a sales assistant who helps customers find the right products for their question and activities."
            },
            {
                "role": "user",
                "content": "The products available are the following: ' + <Data to ground your ask> + '"
            },
            {
                "role": "user",
                "content": " ' + <add the prompt> + '"
            }
        ]
    }';

    DECLARE @ret int, @response nvarchar(max);

    exec @ret = sp_invoke_external_rest_endpoint
        @url = @url,
        @method = 'POST',
        @payload = @payload,
        @Credential = [<Add your Credential>],    
        @timeout = 230,
        @response = @response output;

    select json_value(@response, '$.result.choices[0].message.content');
Comments
sukkaur
Microsoft Employee
Status changed to: Completed

Please check this learn document - sp_invoke_external_rest_endpoint (Transact-SQL) - SQL Server | Microsoft Learn

Also, Here's a sample code

 DECLARE @url nvarchar(4000) = '<URL for Chat GPT model that you have deployed>';
    DECLARE @payload nvarchar(max) = N'{
        "messages": [
            {
                "role": "system",
                "content": "You are a sales assistant who helps customers find the right products for their question and activities."
            },
            {
                "role": "user",
                "content": "The products available are the following: ' + <Data to ground your ask> + '"
            },
            {
                "role": "user",
                "content": " ' + <add the prompt> + '"
            }
        ]
    }';

    DECLARE @ret int, @response nvarchar(max);

    exec @ret = sp_invoke_external_rest_endpoint
        @url = @url,
        @method = 'POST',
        @payload = @payload,
        @Credential = [<Add your Credential>],    
        @timeout = 230,
        @response = @response output;

    select json_value(@response, '$.result.choices[0].message.content');