Azure OpenAI API with own data

J Rippon 81 Reputation points
2023-11-21T12:27:39.2+00:00

I'm trying to leverage Azure OpenAI API as part of a Slack Bott integration.

I can get responses without my own data, but when I add in the data and cognitive search, I receive a "message":" The extensions chat completions operation must have at least one extension."}}

Code snippets below

$openAiUrl = "$($openai.api_base)/openai/deployments/$($openai.name)/extensions/chat/completions?api-version=$($openai.api_version)"
$systemMessage  = "You are an AI assistant called"


$openai = @{
    api_key     = ""
    api_base    = "https://xxx-aiservices.openai.azure.com"
    api_version = "2023-06-01-preview"
    name        = ""
}


$openAiHeaders = [ordered]@{
    'api-key'        = $openai.api_key
    "Content-Type"   = "application/json"
}


$dataSources = @{
    "type" = "AzureCognitiveSearch"
        "parameters" = @{
            "endpoint"  = $search_endpoint
            "key"       = $search_key
            "indexName" = $search_index_name
        }
}

$search_key        = ""
$search_endpoint   = "https://xxxx.search.windows.net"
$search_index_name = ""


$openAibody = [ordered]@{
    "prompt"      = "$systemMessage $messageTextString"
    "dataSources" = "$dataSources"
    "max_tokens"  = 500
    "temperature" = 0.7
    "top_p"       = 0.95
  } | ConvertTo-Json

$openAiMessage = Invoke-RestMethod `
    -Uri $openAiUrl `
    -Method Post `
   	-Headers $openAiHeaders `
    -Body $openAibody
Azure AI Search
Azure AI Search
An Azure search service with built-in artificial intelligence capabilities that enrich information to help identify and explore relevant content at scale.
1,339 questions
Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
4,080 questions
{count} votes

3 answers

Sort by: Most helpful
  1. J Rippon 81 Reputation points
    2023-12-08T11:18:04.6266667+00:00

    For anyone interested my message body was wrong when referencing the datasource, and the below fixed it.

    $openAibody = [ordered]@{
        "messages"    = @(
            @{
            	"role"    = "user"
            	"content" = $messageTextString
            }
            @{
            	"role"    = "system"
            	"content" = $systemMessage
            }
        )
        "max_tokens"  = 500
        "temperature" = 0.7
        "top_p"       = 0.95
        "dataSources" = @(
            @{
            "type"        = "AzureCognitiveSearch"
            "parameters" = @{
                "endpoint"  = $search_endpoint
                "key"       = $search_key
                "indexName" = $search_index_name
                "inScope"   = "false"
            }
            }
        )
    }| ConvertTo-Json -Depth 10
    
    1 person found this answer helpful.

  2. brtrach-MSFT 17,731 Reputation points Microsoft Employee Moderator
    2023-11-22T23:54:51.89+00:00

    @J Rippon This error message indicates that you need to add at least one extension to your chat completions operation. An extension is a custom skill that you can add to your skillset to enhance the capabilities of your chatbot.

    To add an extension, you need to create a custom skill and add it to your skillset. You can create a custom skill using Azure Cognitive Search or Azure Functions. Once you have created your custom skill, you can add it to your skillset and use it in your chat completions operation.

    Here is an example of how to create a custom skill using Azure Cognitive Search:

    1. Create a new skillset or open an existing one.
    2. Click on the "Add Cognitive Services" button and select "Azure Cognitive Search".
    3. Enter the endpoint and key for your Azure Cognitive Search service.
    4. Click on the "Add Skill" button and select "Custom Skill".
    5. Enter a name for your custom skill and select "Azure Cognitive Search" as the source.
    6. Enter the code for your custom skill. This code will be executed by Azure Cognitive Search when the skill is called.
    7. Save your custom skill and add it to your skillset.

    Once you have added your custom skill to your skillset, you can use it in your chat completions operation by specifying the name of the skill in the "extensions" parameter of your request.

    0 comments No comments

  3. brtrach-MSFT 17,731 Reputation points Microsoft Employee Moderator
    2023-12-12T05:35:11.42+00:00

    @J Rippon I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others (Opens in new window or tab)", I'll repost your solution in case you'd like to "Accept (Opens in new window or tab)" the answer.

    Issue: You were able to successfully get data when using a general dataset but after introducing your own data, you received the error, 'The extensions chat completions operation must have at least one extension.'"

    Solution: "For anyone interested my message body was wrong when referencing the data source, and the below fixed it."

    $openAibody = [ordered]@{
        "messages"    = @(
            @{
            	"role"    = "user"
            	"content" = $messageTextString
            }
            @{
            	"role"    = "system"
            	"content" = $systemMessage
            }
        )
        "max_tokens"  = 500
        "temperature" = 0.7
        "top_p"       = 0.95
        "dataSources" = @(
            @{
            "type"        = "AzureCognitiveSearch"
            "parameters" = @{
                "endpoint"  = $search_endpoint
                "key"       = $search_key
                "indexName" = $search_index_name
                "inScope"   = "false"
            }
            }
        )
    }| ConvertTo-Json -Depth 10
    
    
    

    We are always here to assist you. Please reach out if you require further assistance in the future. We would appreciate your consideration in accepting this post as the solution so this can be marked as resolved, which lets our management and community know you found a solution. Thank you for your understanding.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.