通过上传离线任务数据进行通义晓蜜CCAI-对话分析

本文向您介绍一个通过上传离线任务数据进行通义晓蜜CCAI-对话分析的最佳实践。

  • 关于Java SDK的更多说明,请参见开始使用

  • 关于各API的详细出入参说明,请参见API目录

前提条件

如果您还未创建AccessKeyIDAccessKeySecret,请参考AccessKey、AppIDAgentKey获取方式

获取Workspace IDApp ID

Workspace ID

image

  1. 鼠标悬浮到右上角头像处,点击主账号管理,进入业务空间管理页面。

  2. 在业务空间管理列表中获取的Workspace ID为入参中workspaceId。

App ID

image

  1. 在左侧导航栏选择应用广场,点击通义晓蜜CCAI-对话分析AIO查看详情

  2. 点击上方我的应用,展示应用卡片列表。

  3. 每个卡片上的应用ID即为需要获取的App ID。

安装SDK

同步Java

<dependency>

<groupId>com.aliyun</groupId>

<artifactId>contactcenterai20240603</artifactId>

<version>3.2.0</version>

</dependency>

异步Java

<dependency>

<groupId>com.aliyun</groupId>

<artifactId>alibabacloud-contactcenterai20240603</artifactId>

<version>3.0.4</version>

</dependency>

代码示例

说明

请用已获取的Workspace ID替换示例中的YOUR_WORKSPACEID,AccessKeyID替换示例中的YOUR_ACCESS_KEY_ID,AccessKeySecret替换示例中的YOUR_ACCESS_KEY_SECRET,App ID替换示例中的YOUR_APPID,代码才能正常运行。为防止密钥泄露,建议将AccessKeyIDAccessKeySecret设置为环境变量。

创建语音任务

import com.alibaba.fastjson.JSONObject;
import com.aliyun.contactcenterai20240603.Client;
import com.aliyun.contactcenterai20240603.models.*;
import com.aliyun.teaopenapi.models.Config;
import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class CcaiPaasTest {

  public static void main(String[] args) throws Exception{
        String accessKeyId = "YOUR_ACCESS_KEY_ID";
        String accessKeySecret = "YOUR_ACCESS_KEY_SECRET";
        String workspaceId = "YOUR_WORKSPACEID";
        String appId = "YOUR_APPID";

        Config config = new Config();
        config.setAccessKeyId(accessKeyId).setAccessKeySecret(accessKeySecret).setEndpoint("contactcenterai.cn-shanghai.aliyuncs.com")
                .setRegionId("cn-shanghai").setProtocol("HTTPS");

        Client client = new Client(config);

        CreateTaskRequest request=new CreateTaskRequest();

    
        request.setTaskType("audio");
        request.setResultTypes(Arrays.asList("summary"));
        request.setModelCode("tyxmPlus");

        CreateTaskRequest.CreateTaskRequestTranscription transcription=new CreateTaskRequest.CreateTaskRequestTranscription();
        transcription.setFileName("***.mkv");
        transcription.setVoiceFileUrl("https://***.oss-cn-beijing.aliyuncs.com/****/***.mkv");
        request.setTranscription(transcription);

        CreateTaskResponse response=client.createTask(workspaceId,appId,request);
        System.out.println(JSONObject.toJSONString(response.getBody()));
    }
     
}

创建文本任务

import com.alibaba.fastjson.JSONObject;
import com.aliyun.contactcenterai20240603.Client;
import com.aliyun.contactcenterai20240603.models.*;
import com.aliyun.teaopenapi.models.Config;
import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class CcaiPaasTest {
     public static void main(String[] args) throws Exception{
        String accessKeyId = "YOUR_ACCESS_KEY_ID";
        String accessKeySecret = "YOUR_ACCESS_KEY_SECRET";
        String workspaceId = "YOUR_WORKSPAC
        String appId = "YOUR_APPID";

        Config config = new Config();
        config.setAccessKeyId(accessKeyId).setAccessKeySecret(accessKeySecret).setEndpoint("contactcenterai.cn-shanghai.aliyuncs.com")
                .setRegionId("cn-shanghai").setProtocol("HTTPS");

        Client client = new Client(config);

        CreateTaskRequest request=new CreateTaskRequest();

        CreateTaskRequest.CreateTaskRequestDialogue dialogue = new CreateTaskRequest.CreateTaskRequestDialogue();

        List<CreateTaskRequest.CreateTaskRequestDialogueSentences> sentences = new ArrayList<>();
        CreateTaskRequest.CreateTaskRequestDialogueSentences sentences1 = new CreateTaskRequest.CreateTaskRequestDialogueSentences();
        sentences1.setRole("agent");
        sentences1.setText("请问有什么事,你什么性别,胖不胖");
        sentences.add(sentences1);

        CreateTaskRequest.CreateTaskRequestDialogueSentences  sentences2 = new  CreateTaskRequest.CreateTaskRequestDialogueSentences ();
        sentences2.setRole("user");
        sentences2.setText("我要买保险,我是男的,很瘦");
        sentences.add(sentences2);
        dialogue.setSentences(sentences);
        dialogue.setSessionId("sessionId-

        request.setDialogue(dialogue);
        
        request.setTaskType("text");
        request.setResultTypes(Arrays.asList("summary"));
        request.setModelCode("tyxmPlus");

        CreateTaskResponse response=client.createTask(workspaceId,appId,request);
        System.out.println(JSONObject.toJSONString(response.getBody()));
    }

 
}

获取任务结果

import com.alibaba.fastjson.JSONObject;
import com.aliyun.contactcenterai20240603.Client;
import com.aliyun.contactcenterai20240603.models.*;
import com.aliyun.teaopenapi.models.Config;
import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class CcaiPaasTest {   
    
    public static void main(String[] args) throws Exception{
        String accessKeyId = "YOUR_ACCESS_KEY_ID";
        String accessKeySecret = "YOUR_ACCESS_KEY_SECRET";
     
        Config config = new Config();
        config.setAccessKeyId(accessKeyId).setAccessKeySecret(accessKeySecret).setEndpoint("contactcenterai.cn-shanghai.aliyuncs.com")
                .setRegionId("cn-shanghai").setProtocol("HTTPS");

        Client client = new Client(config);

        String taskId = "*****-****-****-*****-****";
        GetTaskResultRequest request = new GetTaskResultRequest();
        request.setTaskId(taskId);
        GetTaskResultResponse response = client.getTaskResult(request);
        System.out.println(JSONObject.toJSONString(response));
    }
}

相关文档

关于任务类型,请参CreateTask - 通过上传离线任务数据进行通义晓蜜CCAI-对话分析见中resultTypes字段的描述。