Custom json payload in Custom Web API skill - call Azure CLU via API

Danijel Ilievski 0 Reputation points
2023-02-09T21:57:49.28+00:00

I wrote valid skillset (Custom Web Api skill), but problem rise when I want to define different structure for Json payload. Because e.g. Azure CLU (Conversational language understanding) API request to have additional keys/names in Json payload: e.q. "kind", "analysisInput", etc.

Solution:
Define proper skillset json defintion and inside define to call custom azure function. Inside this e.g. python function defines your custom json payload and then call inside or outside API.

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
{count} votes

1 answer

Sort by: Most helpful
  1. brtrach-MSFT 17,731 Reputation points Microsoft Employee Moderator
    2023-02-16T05:02:54.15+00:00

    Yes, you can define a custom JSON payload structure for your Web API skill in Azure Cognitive Search. You can write a custom function in Python or any other language that generates the desired JSON payload structure and then call the API with that payload. You can also pass any additional parameters or headers that the API requires.

    For example, if you want to call the Azure CLU API, you can write a Python function that generates the JSON payload with the required keys/names such as "kind", "analysisInput", etc. and then call the API with that payload.

    Here's a sample Python function that generates the JSON payload for the Azure CLU API:

    import requests
    
    def generate_payload(text, language):
        payload = {
            "kind": "text",
            "analysisInput": {
                "text": text,
                "languageCode": language
            }
        }
        return payload
    
    def call_api(payload):
        headers = {
            "Content-Type": "application/json",
            "Ocp-Apim-Subscription-Key": "your_subscription_key"
        }
        response = requests.post("https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/your_app_id", headers=headers, json=payload)
        return response.json()
    

    You can then call this function from your Web API skill in Azure Cognitive Search and pass the generated JSON payload to the API.

    Please let us know if you have any further questions or concerns.

    0 comments No comments

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.