文档

服务质检

更新时间:

本文主要介绍服务质检的AI能力和实现方式。服务质检是指对服务过程中的对话进行质量检测,支持自定义多个质检维度,辅助客户提升服务水平。

请求参数

参数名

类型

是否必填

说明

ServiceInspectionEnabled

boolean

服务质检功能开关,默认为false。

ServiceInspection

object

服务质检参数对象。

ServiceInspection.SceneIntroduction

string

服务质检的对话场景描述。

ServiceInspection.InspectionIntroduction

string

服务质检的检测目标和侧重点描述。

ServiceInspection.InspectionContents

list[]

服务质检的质检维度列表,包含质检维度名称和定义,即需要大模型以什么样的标准判断该维度是否命中。

ServiceInspection.InspectionContents[i].Title

string

服务质检的质检维度名称。

ServiceInspection.InspectionContents[i].Content

string

服务质检的质检维度定义。

ServiceInspection.SpeakerMap

map<string,string>

服务质检的角色映射表,key为"1"、"2"...对应SpeakerId,value为说话人对应的角色,只有在多通道音频下才有意义。

示例设置

{
    "Input":{
        ...
    },
    "Parameters": {
        "ServiceInspectionEnabled": true,
        "ServiceInspection": {
            "SceneIntroduction": "汽车门店线下销售场景",
            "InspectionIntroduction": "请检测对话中汽车销售人员表现是否接待热情、态度良好",
            "InspectionContents": [
                {
                    "Title": "到店迎接-欢迎语",
                    "Content": "销售在开场白的时候主动向客户打招呼进行欢迎"
                },
                {
                    "Title": "离店送别-客户留资",
                    "Content": "销售邀请客户留下微信、电话号码、名片等联系方式"
                },
                {
                    "Title": "到店迎接-饮品提供",
                    "Content": "销售在接待客户的时候主动询问是否需要饮料(如咖啡、橙汁、水、茶等)、点心、零食、水果等"
                }
            ]
        }
    }
}

代码示例

#!/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'] = '输入您在听悟管控台创建的Appkey'

    # 基本请求参数
    input = dict()
    input['SourceLanguage'] = 'cn'
    input['TaskKey'] = 'task' + datetime.datetime.now().strftime('%Y%m%d%H%M%S')
    input['FileUrl'] = '输入待测试的音频url链接'
    root['Input'] = input

    # AI相关参数,按需设置即可
    parameters = dict()
    # 服务质检
    parameters['ServiceInspectionEnabled'] = True
    service_inspection = {
        "SceneIntroduction": "汽车门店线下销售场景",
        "InspectionIntroduction": "请检测对话中汽车销售人员表现是否接待热情、态度良好",
        "InspectionContents": [
            {
                "Title": "到店迎接-欢迎语",
                "Content": "销售在开场白的时候主动向客户打招呼进行欢迎"
            },
            {
                "Title": "离店送别-客户留资",
                "Content": "销售邀请客户留下微信、电话号码、名片等联系方式"
            },
            {
                "Title": "到店迎接-饮品提供",
                "Content": "销售在接待客户的时候主动询问是否需要饮料(如咖啡、橙汁、水、茶等)、点心、零食、水果等"
            }
        ]
    }
    parameters['ServiceInspection'] = service_inspection
    root['Parameters'] = parameters
    return root


body = init_parameters()
print(body)

# TODO  请通过环境变量设置您的 AccessKeyId 和 AccessKeySecret
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", "输入您在听悟管控台创建的Appkey");

        JSONObject input = new JSONObject();
        input.fluentPut("FileUrl", "输入待测试的音频url链接")
                .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", "长安深蓝汽车门店线下销售场景")
                .fluentPut("InspectionIntroduction", "请检测对话中汽车销售人员表现是否接待热情、态度良好")
                .fluentPut("InspectionContents", new JSONArray()
                        .fluentAdd(new JSONObject().fluentPut("Title", "到店迎接-欢迎语").fluentPut("Content", "销售在开场白的时候主动向客户打招呼进行欢迎"))
                        .fluentAdd(new JSONObject().fluentPut("Title", "离店送别-客户留资").fluentPut("Content", "销售邀请客户留下微信、电话号码、名片等联系方式"))
                        .fluentAdd(new JSONObject().fluentPut("Title", "到店迎接-饮品提供").fluentPut("Content", "销售在接待客户的时候主动询问是否需要饮料(如咖啡、橙汁、水、茶等)、点心、零食、水果等。"))
                );
        parameters.put("ServiceInspection", serviceInspection);
        root.put("Parameters", parameters);
        System.out.println(root.toJSONString());
        request.setHttpContent(root.toJSONString().getBytes(), "utf-8", FormatType.JSON);

        // TODO 请通过环境变量设置您的AccessKeyId、AccessKeySecret
        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) {
        // 创建API请求并设置参数
        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;
    }
}

示例输出

{
    "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=LTAI4G4uXHLPwQHj********&Signature=*********huzKcM4tzimubU%3D", 
            "ServiceInspection": "http://speech-swap-hangzhou.oss-cn-hangzhou.aliyuncs.com/tingwu/output/1503864348104017/05c45066fc6d496dae9b583426fdaae8/05c45066fc6d496dae9b583426fdaae8_ServiceInspection_20231028230459.json?Expires=1698593389&OSSAccessKeyId=LTAI4G4uXHLPwQHj********&Signature=*********V8O%2BG4paM0VMv0AIyK4%3D"
        }, 
        "TaskId": "05c45066fc6df96dg09bf8z4*********", 
        "TaskStatus": "COMPLETED"
    }, 
    "RequestId": "7AE5CB5C-7287-16D1-BA93-G43********"
}

其中ServiceInspection字段对应的即为口语书面化结果的http url下载链接。

协议解析

上述输出中的服务质检结果url中的内容为JSON格式的报文,示例如下所示。

{
    "TaskId": "4ee872e72fd0490694f1cd615b6b6314",
    "ServiceInspection": [
        {
            "Title": "到店迎接-欢迎语",
            "Matched": true,
            "Remarks": "销售人员通过询问开启对话,表现出一定的迎接意图。",
            "MatchedSentenceIds": [

            ]
        },
        {
            "Title": "离店送别-客户留资",
            "Matched": true,
            "Remarks": "销售人员提出加微信的方式以便后续联系。",
            "MatchedSentenceIds": [

            ]
        },
        {
            "Title": "到店迎接-饮品提供",
            "Matched": false,
            "Remarks": "对话中未提及提供饮品的信息。",
            "MatchedSentenceIds": [

            ]
        }
    ]
}

具体字段定义如下。

参数名

类型

说明

TaskId

string

创建任务时生成的TaskId。

ServiceInspection

list[]

服务质检结果的集合,含有0个、1个或多个服务质检结果信息。

ServiceInspection[i].Title

string

服务质检结果的名称,和入参的ServiceInspection.InspectionContents[i].Title对应。

ServiceInspection[i].Matched

boolean

本条服务质检项是否命中。

ServiceInspection[i].Remarks

string

大模型对本条质检项的分析。

ServiceInspection[i].MatchedSentenceIds

list[]

命中该质检项的原始对话,在原文中的句子id。