Skip to content

Using the Deployed Model

  1. Clone the Duet Samples Git repository here. It contains a C# project that shows you how to query the runtime endpoints generated from the Duet system after you publish your model. You can clone to your terminal in two ways:

    • SSH: git clone git@gitlab.com:intelus-ai/intelus-samples.git
    • HTTPS: git clone https://gitlab.com/intelus-ai/intelus-samples.git
  2. Open the repository in an IDE (e.g. VSCode) and update the app.config file with your endpoint URL and your API key that you copy from Duet publish page. Sample code here:

        //The deployment endpoint url generated from intelus.ai system
        key="END_POINT_URL" value="--OVERRIDE THIS WITH ENVIRONMENT-SPECIFIC VALUE--"
        //The secret key to be used in api key authentication endpoint
        key="INTELUS_SECRET_KEY" value="--OVERRIDE THIS WITH ENVIRONMENT-SPECIFIC VALUE--"
    

  3. Copy the desired endpoint URL, and replace the value of the END_POINT_URL.

  4. Copy the API key, and replace the value of the INTELUS_SECRET_KEY key.

  5. Check the Program.cs file. Replace the sampleQuery string as needed.

        public static async Task MainAsync()
        {
            string sampleQuery = "I have an issue with my credit card payment";
    
            // Call endpoint with your query
            var response = await QueryEndpointApiKeyAsync(sampleQuery);
            Console.WriteLine(response);
        }
    

    The query is sent via HTTP. Duet uses the GET and POST requests. GET requests come with a limit of 2KB, so if your request is bigger, we strongly recommend that you use the POST method, which has a 300KB limit. Documents that exceed this limit in size will not be processed through Duet.

    public static async Task<string> QueryEndpointApiKeyAsync(string query)
    {
        string url = $"{ConfigurationManager.AppSettings["END_POINT_URL"]}/apikey";
        string secretKey = ConfigurationManager.AppSettings["INTELUS_SECRET_KEY"];
    
        var httpClient = new HttpClient
        {
            BaseAddress = new Uri(url)
        };
    
        httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        httpClient.DefaultRequestHeaders.Add("X-API-Key", secretKey);
    
        var response = await httpClient.GetAsync($"?query={query}");
        if (response.IsSuccessStatusCode)
        {
            return await response.Content.ReadAsStringAsync();
        }
        else
        {
            return $"Execution failed with error: {response.ToString()}";
        }
    }
    
    public static async Task<string> QueryEndpointPostAsync(string query)
    {
        var httpClient = new HttpClient();
    
        string url = $"{ConfigurationManager.AppSettings["END_POINT_URL"]}/apikey";
        string secretKey = ConfigurationManager.AppSettings["INTELUS_SECRET_KEY"];
        QueryRequest queryReq = new QueryRequest(query);
    
        StringContent content = new StringContent(
            JsonSerializer.Serialize(queryReq),
            Encoding.UTF8,
            "application/json"
        );
    
        httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        httpClient.DefaultRequestHeaders.Add("X-API-Key", secretKey);
    
        var response = await httpClient.PostAsync(url, content);
        if (response.IsSuccessStatusCode)
        {
            return await response.Content.ReadAsStringAsync();
        }
        else
        {
            return $"Execution failed with error: {response.ToString()}";
        }
    }
    
  6. After you run the query, check the console for the response in JSON format. The confidence for each category is given in the score attribute, where a score of 1 is 100% confidence in the prediction. Duet provides the prediction of the "topleafcategory" field with its confidence score. This represents the top category the model indicates for the input document. Duet also gives a sorted list of predictions by confidence score for the predictions of all categories in the model schema.

{
  "query": "I'm having payment issue",
  "classifiers": [
    {
      "projectId": "33901560-25f0-4aec-994f-82a3e0282350",
      "projectName": "CSDemo77",
      "topScoreSubcategory": {
        "id": "7",
        "name": "payment issue",
        "score": 1
      },
      "categories": [
        {
          "id": "3",
          "name": "payment",
          "score": 1,
          "subcategories": [
            {
              "id": "7",
              "name": "payment issue",
              "score": 1
            },
            {
              "id": "9",
              "name": "payment method",
              "score": 0
            },
            {
              "id": "8",
              "name": "Other_payment",
              "score": 0
            }
          ]
        },
        {
          "id": "5",
          "name": "feedback",
          "score": 0,
          "subcategories": [
            {
              "id": "10",
              "name": "review",
              "score": 0
            },
            {
              "id": "12",
              "name": "complaint",
              "score": 0
            },
            {
              "id": "11",
              "name": "Other_feedback",
              "score": 0
            }
          ]
        },
        {
          "id": "6",
          "name": "order",
          "score": 0,
          "subcategories": [
            {
              "id": "13",
              "name": "change order",
              "score": 0
            },
            {
              "id": "15",
              "name": "track order",
              "score": 0
            },
            {
              "id": "14",
              "name": "Other_order",
              "score": 0
            }
          ]
        },
        {
          "id": "4",
          "name": "Other_CSDemo77",
          "score": 0
        }
      ]
    }
  ],
  "tag": "V1-CSDemo",
  "timestamp": "2021-11-16 17:05:11.958",
  "creationTimestampUnix": 1636564217
}

Here is an example of an unsuccessful query.

{
  "detail": "Invalid endpointId or API secret key",
  "status": 401,
  "title": "One or more errors occurred.",
  "type": "https://datatracker.ietf.org/doc/html/rfc7231#section-6.5",
  "traceId": "611c09bdab78f843b74f411f17ccf28f",
  "errorSubcode": 11,
  "requestTimestamp": "2021-11-17T18:36:37.7206281Z"
}

Here are the response codes from the model endpoint HTTP request. Responses include some error message if the request has errors, along with the HTTP protocol status and an errorSubcode specific to Duet. Here are some scenarios in which you may receive errorSubcodes:

HTTP Response Code errorSubcode Error Name When it occurs
200 no errorSubcode Success if the query is successful
400 1 ServiceClientInvalidArgument if the "query" argument is not specified or is an empty document
400 100002 RuntimeEndpointDeactivated for when the request has the correct combination of endpointId and authorization information, but the request fails because the endpoint has been deactivated
401 11 IncorrectApiSecretKeyAndResourceIdCombination for when the value in the intelus-secret-key request header does not match the endpoint ID, model ID, or user ID in the same request
401 12 ApiSecretKeyHeaderMissingOrEmpty for when the intelus-secret-key request header is required but is missing or empty
401 100001 IncorrectUserAccessTokenAndEndpointIdCombination if the endpoint has been deactivated
413 no errorSubcode if the request is too long and exceeds the limit of the GET and POST limits
429 no errorSubcode Response will be blocked by AWS API Gateway before it reaches our backend if you exceed the amount of queries on your free account
500 various errorSubcodes if there is an internal error on the Duet system in which case your next path forward is to report the problem to us so that we can fix it

Check integrations to see other platforms to which you can deploy models.

Back to top