HowardTaylor's avatar
HowardTaylor
Microsoft Employee
3 months ago
Status:
Completed

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.

1 Comment

  • sukkaur's avatar
    sukkaur
    Microsoft Employee
    Status changed:
    New
    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');

Recent ideas