Service inspection

更新时间:
复制 MD 格式

This topic describes the AI capabilities and implementation of service inspection. Service inspection evaluates the quality of conversations that occur during service interactions. You can define custom inspection dimensions to help improve service quality.

Request parameters

Parameter Name

Type

Required

Description

ServiceInspectionEnabled

boolean

No

The switch for the service inspection feature. The default value is false.

ServiceInspection

object

No

The parameter object for service inspection.

ServiceInspection.SceneIntroduction

string

Yes

A description of the conversation scenario for service inspection.

ServiceInspection.InspectionIntroduction

string

Yes

A description of the inspection goals and focus areas for service inspection.

ServiceInspection.InspectionContents

list[]

Yes

A list of inspection dimensions. It includes the dimension name and definition, which specifies the criteria the Large Language Model (LLM) uses to determine if the dimension is hit. The number of dimensions cannot exceed 100.

ServiceInspection.InspectionContents[i].Title

string

Yes

The name of the service inspection dimension.

ServiceInspection.InspectionContents[i].Content

string

Yes

The definition of the service inspection dimension.

For descriptions of other request parameters, see the document for your scenario:

Example settings

The service inspection feature requires a clear conversation scenario, such as online education telephone sales, offline car dealership sales, or real estate agency home sales. You also need to clearly state the inspection requirements for staff, such as good service attitude, a complete service process, and effective resolution of customer issues.

Use the Title field to describe the name of the inspection item and the Content field to describe the specific inspection point. Use clear and direct descriptions. Do not add role definitions, regular expressions, or complex list structures. These can conflict with the prompts that the service uses.

{
    "Input":{
        ...
    },
    "Parameters": {
        "ServiceInspectionEnabled": true,
        "ServiceInspection": {
            "SceneIntroduction": "Offline sales scenario at a car dealership",
            "InspectionIntroduction": "Check if the car salesperson in the conversation is welcoming and has a good attitude",
            "InspectionContents": [
                {
                    "Title": "Store arrival greeting - Welcome message",
                    "Content": "The salesperson proactively greets the customer with a welcome at the beginning of the conversation"
                },
                {
                    "Title": "Store departure farewell - Customer information collection",
                    "Content": "The salesperson asks the customer to leave their contact information, such as WeChat, phone number, or business card"
                },
                {
                    "Title": "Store arrival greeting - Beverage offer",
                    "Content": "The salesperson proactively asks the customer if they would like a beverage (such as coffee, orange juice, water, or tea), snacks, or fruit"
                }
            ]
        }
    }
}

The following are incorrect examples:

  • Scenario description: You are an agent assistant, proficient in various types of real estate property service businesses, scripts, standard processes, and customer service quality inspection analysis. You are also an expert in natural language processing and large language models, skilled in emotion analysis and recognition. Please analyze the conversation record between the service agent and the customer.

  • All Title fields use identical or unclear labels, such as "Product Explanation", "Service Standards", or "Operational Requirements".

  • The content in Title or Content is unclear. For example: Current housing situation: Script reference: Mr./Ms. XX, are you considering buying a new home or upgrading?\n(New purchase/Upgrade) Could you tell me about your family's housing needs? For example, what is your price range, do you prefer a single-story or duplex, and what is the age of your current home?\nKeywords: 1. New purchase/Upgrade\n2. Where do you live now/Where did you live before/Rented before\n3. Which neighborhoods have you looked at\nAny hit.

  • The content in Content includes conditional logic. For example: Account opening procedure: Script reference: Complete account opening procedure\n① Please show your ID card\n② Please show your household registration book\n\nKeywords: 1. ID card/Household registration book/Passport/Registration\n2. Agreement/Sign\n3. Complete account opening procedure\n(1&2)|3.

Code examples

#!/usr/bin/env python
# coding=utf-8

import os
import json
import datetime
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.request import CommonRequest
from aliyunsdkcore.auth.credentials import AccessKeyCredential


def create_common_request(domain, version, protocolType, method, uri):
    request = CommonRequest()
    request.set_accept_format('json')
    request.set_domain(domain)
    request.set_version(version)
    request.set_protocol_type(protocolType)
    request.set_method(method)
    request.set_uri_pattern(uri)
    request.add_header('Content-Type', 'application/json')
    return request


def init_parameters():
    root = dict()
    root['AppKey'] = 'Enter the AppKey you created in the Tingwu console'

    # Basic request parameters
    input = dict()
    input['SourceLanguage'] = 'cn'
    input['TaskKey'] = 'task' + datetime.datetime.now().strftime('%Y%m%d%H%M%S')
    input['FileUrl'] = 'Enter the URL of the audio file to be tested'
    root['Input'] = input

    # AI-related parameters. Set as needed.
    parameters = dict()
    # Service inspection
    parameters['ServiceInspectionEnabled'] = True
    service_inspection = {
        "SceneIntroduction": "Offline sales scenario at a car dealership",
        "InspectionIntroduction": "Check if the car salesperson in the conversation is welcoming and has a good attitude",
        "InspectionContents": [
            {
                "Title": "Store arrival greeting - Welcome message",
                "Content": "The salesperson proactively greets the customer with a welcome at the beginning of the conversation"
            },
            {
                "Title": "Store departure farewell - Customer information collection",
                "Content": "The salesperson asks the customer to leave their contact information, such as WeChat, phone number, or business card"
            },
            {
                "Title": "Store arrival greeting - Beverage offer",
                "Content": "The salesperson proactively asks the customer if they would like a beverage (such as coffee, orange juice, water, or tea), snacks, or fruit"
            }
        ]
    }
    parameters['ServiceInspection'] = service_inspection
    root['Parameters'] = parameters
    return root


body = init_parameters()
print(body)

# TODO: Set your AccessKeyId and AccessKeySecret using environment variables.
credentials = AccessKeyCredential(os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'], os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET'])
client = AcsClient(region_id='cn-beijing', credential=credentials)

request = create_common_request('tingwu.cn-beijing.aliyuncs.com', '2023-09-30', 'https', 'PUT', '/openapi/tingwu/v2/tasks')
request.add_query_param('type', 'offline')

request.set_content(json.dumps(body).encode('utf-8'))
response = client.do_action_with_exception(request)
print("response: \n" + json.dumps(json.loads(response), indent=4, ensure_ascii=False))
package com.alibaba.tingwu.client.demo.aitest;

import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.FormatType;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.http.ProtocolType;
import com.aliyuncs.profile.DefaultProfile;
import org.junit.Test;

/**
 * @author tingwu2023
 */
public class ServiceInspectionTest {

    @Test
    public void testServiceInspection() throws ClientException {
        CommonRequest request = createCommonRequest("tingwu.cn-beijing.aliyuncs.com", "2023-09-30", ProtocolType.HTTPS, MethodType.PUT, "/openapi/tingwu/v2/tasks");
        request.putQueryParameter("type", "offline");

        JSONObject root = new JSONObject();
        root.put("AppKey", "Enter the AppKey you created in the Tingwu console");

        JSONObject input = new JSONObject();
        input.fluentPut("FileUrl", "Enter the URL of the audio file to be tested")
                .fluentPut("SourceLanguage", "cn")
                .fluentPut("TaskKey", "task" + System.currentTimeMillis());
        root.put("Input", input);

        JSONObject parameters = new JSONObject();
        parameters.put("ServiceInspectionEnabled", true);
        JSONObject serviceInspection = new JSONObject();
        serviceInspection.fluentPut("SceneIntroduction", "Offline sales scenario at a Changan Deepal car dealership")
                .fluentPut("InspectionIntroduction", "Check if the car salesperson in the conversation is welcoming and has a good attitude")
                .fluentPut("InspectionContents", new JSONArray()
                        .fluentAdd(new JSONObject().fluentPut("Title", "Store arrival greeting - Welcome message").fluentPut("Content", "The salesperson proactively greets the customer with a welcome at the beginning of the conversation"))
                        .fluentAdd(new JSONObject().fluentPut("Title", "Store departure farewell - Customer information collection").fluentPut("Content", "The salesperson asks the customer to leave their contact information, such as WeChat, phone number, or business card"))
                        .fluentAdd(new JSONObject().fluentPut("Title", "Store arrival greeting - Beverage offer").fluentPut("Content", "The salesperson proactively asks the customer if they would like a beverage (such as coffee, orange juice, water, or tea), snacks, or fruit."))
                );
        parameters.put("ServiceInspection", serviceInspection);
        root.put("Parameters", parameters);
        System.out.println(root.toJSONString());
        request.setHttpContent(root.toJSONString().getBytes(), "utf-8", FormatType.JSON);

        // TODO: Set your AccessKeyId and AccessKeySecret using environment variables.
        DefaultProfile profile = DefaultProfile.getProfile("cn-beijing", System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
        IAcsClient client = new DefaultAcsClient(profile);
        CommonResponse response = client.getCommonResponse(request);
        System.out.println(response.getData());
    }

    public static CommonRequest createCommonRequest(String domain, String version, ProtocolType protocolType, MethodType method, String uri) {
        // Create an API request and set the parameters.
        CommonRequest request = new CommonRequest();
        request.setSysDomain(domain);
        request.setSysVersion(version);
        request.setSysProtocol(protocolType);
        request.setSysMethod(method);
        request.setSysUriPattern(uri);
        request.setHttpContentType(FormatType.JSON);
        return request;
    }
}

Example output

{
    "Message": "success", 
    "Code": "0", 
    "Data": {
        "Result": {
            "Transcription": "http://speech-swap-hangzhou.oss-cn-hangzhou.aliyuncs.com/tingwu/output/1503864348104017/05c45066fc6d496dae9b583426fdaae8/05c45066fc6d496dae9b583426fdaae8_Transcription_20231028230430.json?Expires=1698593389&OSSAccessKeyId=STS.****************&Signature=*********huzKcM4tzimubU%3D", 
            "ServiceInspection": "http://speech-swap-hangzhou.oss-cn-hangzhou.aliyuncs.com/tingwu/output/1503864348104017/05c45066fc6d496dae9b583426fdaae8/05c45066fc6d496dae9b583426fdaae8_ServiceInspection_20231028230459.json?Expires=1698593389&OSSAccessKeyId=STS.****************&Signature=*********V8O%2BG4paM0VMv0AIyK4%3D"
        }, 
        "TaskId": "05c45066fc6df96dg09bf8z4*********", 
        "TaskStatus": "COMPLETED"
    }, 
    "RequestId": "7AE5CB5C-7287-16D1-BA93-G43********"
}

The ServiceInspection field provides the HTTPS URL to download the service inspection results.

Protocol parsing

The service inspection result URL returns a JSON message, as shown in the following example.

{
    "TaskId": "4ee872e72fd0490694f1cd615b6b6314",
    "ServiceInspection": [
        {
            "Title": "Store arrival greeting - Welcome message",
            "Matched": true,
            "Remarks": "The salesperson started the conversation with a question, showing some intent to welcome the customer.",
            "MatchedSentenceIds": [

            ]
        },
        {
            "Title": "Store departure farewell - Customer information collection",
            "Matched": true,
            "Remarks": "The salesperson suggested adding on WeChat for future contact.",
            "MatchedSentenceIds": [

            ]
        },
        {
            "Title": "Store arrival greeting - Beverage offer",
            "Matched": false,
            "Remarks": "No information about offering a beverage was mentioned in the conversation.",
            "MatchedSentenceIds": [

            ]
        }
    ]
}

The fields are described as follows.

Parameter name

Type

Description

TaskId

string

The TaskId generated when the task was created.

ServiceInspection

list[]

A collection of service inspection results. It can contain zero, one, or more result items.

ServiceInspection[i].Title

string

The name of the service inspection result. This corresponds to the `ServiceInspection.InspectionContents[i].Title` input parameter.

ServiceInspection[i].Matched

boolean

Indicates whether this service inspection item was hit.

ServiceInspection[i].Remarks

string

The analysis of this inspection item by the LLM.

ServiceInspection[i].MatchedSentenceIds

list[]

The sentence IDs from the original conversation that hit this inspection item.