Call the Tongyi Xiaomi CCAI-Conversation Analysis AIO application via native Prompt

Updated at:

Prerequisites

  • This document introduces the installation, usage, and key notes for the Java SDK of the Tongyi Xiaomi CCAI-Conversation Analysis AIO application.

    For more information about the Java SDK, see Get started.

  • If you have not created an AccessKey ID and AccessKey Secret, see Get AccessKey and AgentKey.

  • If you use a RAM user to call the API, see Use and authorize RAM users for CCAI-Conversation Analysis.

  • For detailed input and output parameters of each API, see the API directory in the left navigation.

API input parameter locations

workspaceId

image
  1. Go to the Business Space Management page.
  2. In the business space management list, the Workspace ID is the workspaceId input parameter.

appId

image
  1. Go to the App Plaza - App Practices page, select Tongyi Xiaomi CCAI-Conversation Analysis AIO, and click View Now.
  2. Click My Apps at the top to display the app card list.
  3. The app ID on each card is the appId in the API parameters.

Install the SDK

Sync Java

<dependency>

<groupId>com.aliyun</groupId>

<artifactId>contactcenterai20240603</artifactId>

<version>3.6.4</version>

</dependency>

Async Java

<dependency>

<groupId>com.aliyun</groupId>

<artifactId>contactcenterai20240603</artifactId>

<version>3.6.4</version>

</dependency>

Python

pip install alibabacloud_contactcenterai20240603

Asynchronous streaming call

NoteReplace YOUR_WORKSPACEID in the example with your workspaceId, YOUR_ACCESS_KEY_ID with your AccessKey ID, YOUR_ACCESS_KEY_SECRET with your AccessKey Secret, and YOUR_APPID with your appId so that the code can run properly.

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.aliyun.auth.credentials.Credential;
import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
import com.aliyun.core.http.HttpMethod;
import com.aliyun.sdk.gateway.pop.Configuration;
import com.aliyun.sdk.gateway.pop.auth.SignatureAlgorithm;
import com.aliyun.sdk.gateway.pop.auth.SignatureVersion;
import com.aliyun.sdk.service.contactcenterai20240603.AsyncClient;
import com.aliyun.sdk.service.contactcenterai20240603.models.*;
import darabonba.core.RequestConfiguration;
import darabonba.core.ResponseIterable;
import darabonba.core.ResponseIterator;
import darabonba.core.client.ClientOverrideConfiguration;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class CcaiPaasTest {

    private static String accessKeyId="YOUR_ACCESS_KEY_ID";
    private static String accessKeySecret="YOUR_ACCESS_KEY_SECRET";
    private static String workspaceId="YOUR_WORKSPACEID";
    private static String appId="YOUR_APPID";

    private static StaticCredentialProvider provider = StaticCredentialProvider.create(
            Credential.builder()
                    .accessKeyId(accessKeyId)
                    .accessKeySecret(accessKeySecret)
                    .build()
    );

    private static AsyncClient client = AsyncClient.builder()
            .region("cn-shanghai")
            .credentialsProvider(provider)
            .serviceConfiguration(Configuration.create()
                    .setSignatureVersion(SignatureVersion.V3)
                    .setSignatureAlgorithmV3(SignatureAlgorithm.ACS3_HMAC_SHA256)
            ).overrideConfiguration(
                    ClientOverrideConfiguration.create()
                            .setProtocol("HTTPS")
                            .setEndpointOverride("contactcenterai.cn-shanghai.aliyuncs.com")
            ).build();

    public static void main(String[] args) throws Exception{
        //Prompt
        List<RunCompletionMessageRequest.Messages> messageList = new ArrayList<>();
        messageList.add(RunCompletionMessageRequest.Messages.builder().role("system").content("You are a helpful assistant.").build());
        messageList.add(RunCompletionMessageRequest.Messages.builder().role("user").content("Please read the following dialogue and execute the instruction task as required.\\n```\\n\\nAgent: your own words```\\nThe task instruction is as follows:\\n```\\nYou are an intelligent office assistant that can generate a brief summary of the dialogue analysis content.\\n```\\nPlease follow the instruction above and complete the task accurately.").build());

        RunCompletionMessageRequest completionParam = RunCompletionMessageRequest.builder()
                .workspaceId(workspaceId).appId(appId).messages(messageList).requestConfiguration(RequestConfiguration.create()
                        .setHttpMethod(HttpMethod.POST)).stream(true).build();
        System.out.println(JSON.toJSONString(completionParam));

        ResponseIterable<RunCompletionMessageResponseBody> x = client.runCompletionMessageWithResponseIterable(completionParam);
        ResponseIterator<RunCompletionMessageResponseBody> iterator = x.iterator();
        String lastTxt="";
        while (iterator.hasNext()) {
            RunCompletionMessageResponseBody event = iterator.next();
            //System.out.println(event.getText());
            //System.out.println(event.getFinishReason());
            //System.out.println(event.getRequestId());
            lastTxt=event.getText();
        }

        System.out.println("ALL***********************");
        System.out.println(lastTxt);
        System.out.println("Headers of the successful request:");
        System.out.println(x.getStatusCode());
        System.out.println(x.getHeaders());
    }
}

Asynchronous non-streaming call

NoteReplace YOUR_WORKSPACEID in the example with your workspaceId, YOUR_ACCESS_KEY_ID with your AccessKey ID, YOUR_ACCESS_KEY_SECRET with your AccessKey Secret, and YOUR_APPID with your appId so that the code can run properly.

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.aliyun.auth.credentials.Credential;
import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
import com.aliyun.core.http.HttpMethod;
import com.aliyun.sdk.gateway.pop.Configuration;
import com.aliyun.sdk.gateway.pop.auth.SignatureAlgorithm;
import com.aliyun.sdk.gateway.pop.auth.SignatureVersion;
import com.aliyun.sdk.service.contactcenterai20240603.AsyncClient;
import com.aliyun.sdk.service.contactcenterai20240603.models.*;
import darabonba.core.RequestConfiguration;
import darabonba.core.ResponseIterable;
import darabonba.core.ResponseIterator;
import darabonba.core.client.ClientOverrideConfiguration;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class CcaiPaasTest {

    private static String accessKeyId="YOUR_ACCESS_KEY_ID";
    private static String accessKeySecret="YOUR_ACCESS_KEY_SECRET";
    private static String workspaceId="YOUR_WORKSPACEID";
    private static String appId="YOUR_APPID";

    private static StaticCredentialProvider provider = StaticCredentialProvider.create(
            Credential.builder()
                    .accessKeyId(accessKeyId)
                    .accessKeySecret(accessKeySecret)
                    .build()
    );

    private static AsyncClient client = AsyncClient.builder()
            .region("cn-shanghai")
            .credentialsProvider(provider)
            .serviceConfiguration(Configuration.create()
                    .setSignatureVersion(SignatureVersion.V3)
                    .setSignatureAlgorithmV3(SignatureAlgorithm.ACS3_HMAC_SHA256)
            ).overrideConfiguration(
                    ClientOverrideConfiguration.create()
                            .setProtocol("HTTPS")
                            .setEndpointOverride("contactcenterai.cn-shanghai.aliyuncs.com")
            ).build();

    public static void main(String[] args) throws Exception{
         //Prompt
        List<RunCompletionMessageRequest.Messages> messageList = new ArrayList<>();
        messageList.add(RunCompletionMessageRequest.Messages.builder().role("system").content("You are a helpful assistant.").build());
        messageList.add(RunCompletionMessageRequest.Messages.builder().role("user").content("Please read the following dialogue and execute the instruction task as required.\\n```\\n\\nAgent: your own words```\\nThe task instruction is as follows:\\n```\\nYou are an intelligent office assistant that can generate a brief summary of the dialogue analysis content.\\n```\\nPlease follow the instruction above and complete the task accurately.").build());

        RunCompletionMessageRequest completionParam = RunCompletionMessageRequest.builder()
                .workspaceId(workspaceId).appId(appId).messages(messageList).requestConfiguration(RequestConfiguration.create()
                        .setHttpMethod(HttpMethod.POST)).stream(false).build();
        System.out.println(JSON.toJSONString(completionParam));

        CompletableFuture<RunCompletionMessageResponse> generateCompletionResponseCompletableFuture = client.runCompletionMessage(completionParam);
        RunCompletionMessageResponse generateCompletionResponse = generateCompletionResponseCompletableFuture.get(10, TimeUnit.SECONDS);
        System.out.println(JSON.toJSONString(generateCompletionResponse.getBody().getText()));
        System.out.println(JSON.toJSONString(generateCompletionResponse.getBody().getFinishReason()));
        System.out.println(JSON.toJSONString(generateCompletionResponse.getBody().getRequestId()));
    }
}
import asyncio

from alibabacloud_contactcenterai20240603.client import Client

from alibabacloud_tea_openapi.models import Config
from alibabacloud_contactcenterai20240603.models import (RunCompletionRequestDialogueSentences,
                                                         RunCompletionRequestDialogue,
                                                         RunCompletionRequestFields,
                                                         RunCompletionRequest)
from alibabacloud_contactcenterai20240603.models import RunCompletionMessageRequest
from alibabacloud_contactcenterai20240603.models import RunCompletionMessageRequestMessages

ak = "YOUR_ACCESS_KEY_ID"
sk = "YOUR_ACCESS_KEY_SECRET"
workSpace = "YOUR_WORKSPACEID"
appId = "YOUR_APPID"

async def run_async_sse():
    config = Config()
    config.access_key_id = ak
    config.access_key_secret = sk
    config.endpoint = "contactcenterai.cn-shanghai.aliyuncs.com"
    config.region_id = "cn-shanghai"

    client = Client(config)

    # Prompt
    role = "system"
    content = "You are a helpful assistant."
    requestMessage1 = RunCompletionMessageRequestMessages(content, role)
    role = "user"
    content = "Please read the following dialogue and execute the instruction task as required.\n```\n\nAgent: your own words\nCustomer: you want the phone number yourself\nCustomer: 31\nAgent: he is 1 cm\nCustomer: after the new year, I see\nCustomer: opened it later to look\nCustomer: hmm, if it weren't for the previous one\nCustomer: this isn't, look, you look\nAgent: after the new year I changed it to extend by execution time; with the old time extension you couldn't extend at all\nAgent: you follow along here to the back\nAgent: isn't it that after so many days you become a member here\nCustomer: then aren't you settled after more than that many days\nAgent: hmm\nCustomer: hmm\nAgent: we have one\nCustomer: it's this one of yours\nAgent: he said you also follow this here\nCustomer: how much of it is vaguely different\nCustomer: after these 3 days\nAgent: the currently executing one\nAgent: these, actually yours is too\nCustomer: then this color of yours\nAgent: according to the expectation he gave, is it settled for how many days\nCustomer: according to the interest he gave, is it extended for how many days, no\nAgent: what's the problem then\nAgent: when you're at 3 days, inside\nCustomer: if you were the original one\nCustomer: you basically just need to look\nAgent: if you were the original, you, you basically don't need\nAgent: 5 days\nCustomer: right\nCustomer: ah, regarding\nCustomer: 15 new\nCustomer: recorded above\n\n```\nThe task instruction is as follows:\n```\nYou are an intelligent office assistant that can generate a brief summary of the dialogue analysis content.\n```\nPlease follow the instruction above and complete the task accurately."
    requestMessage2 = RunCompletionMessageRequestMessages(content, role)

    listRequestMessage = [requestMessage1, requestMessage2]

    request = RunCompletionMessageRequest()
    request.messages = listRequestMessage
    request.model_code = "tyxmTurbo"
    request.stream = False

    # Send request
    response = await client.run_completion_message_async(workSpace, appId, request)
    body = response.body
    print(body)

if __name__ == '__main__':
    asyncio.run(run_async_sse())

Synchronous non-streaming call

NoteReplace YOUR_WORKSPACEID in the example with your workspaceId, YOUR_ACCESS_KEY_ID with your AccessKey ID, YOUR_ACCESS_KEY_SECRET with your AccessKey Secret, and YOUR_APPID with your appId so that the code can run properly.

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.aliyun.contactcenterai20240603.Client;
import com.aliyun.contactcenterai20240603.models.*;
import com.aliyun.teaopenapi.models.Config;
import java.util.*;

public class CcaiPaasTest {

    private static String accessKeyId="YOUR_ACCESS_KEY_ID";
    private static String accessKeySecret="YOUR_ACCESS_KEY_SECRET";
    private static String workspaceId="YOUR_WORKSPACEID";
    private static String appId="YOUR_APPID";

    public static void main(String[] args) throws Exception{
        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);

        //Prompt
        RunCompletionMessageRequest request = new RunCompletionMessageRequest();
        List<RunCompletionMessageRequest.RunCompletionMessageRequestMessages> messageList = new ArrayList<>();
        RunCompletionMessageRequest.RunCompletionMessageRequestMessages message1 = new RunCompletionMessageRequest.RunCompletionMessageRequestMessages();
        message1.setRole("system").setContent("You are a helpful assistant.");
        RunCompletionMessageRequest.RunCompletionMessageRequestMessages message2 = new RunCompletionMessageRequest.RunCompletionMessageRequestMessages();
        message2.setRole("user").setContent("Please read the following dialogue and execute the instruction task as required.\\n```\\n\\nAgent: your own words\\nCustomer: you want the phone number yourself\\nCustomer: 31\\nAgent: he is 1 cm\\nCustomer: after the new year, I see\\nCustomer: opened it later to look\\nCustomer: hmm, if it weren't for the previous one\\nCustomer: this isn't, look, you look\\nAgent: after the new year I changed it to extend by execution time; with the old time extension you couldn't extend at all\\nAgent: you follow along here to the back\\nAgent: isn't it that after so many days you become a member here\\nCustomer: then aren't you settled after more than that many days\\nAgent: hmm\\nCustomer: hmm\\nAgent: we have one\\nCustomer: it's this one of yours\\nAgent: he said you also follow this here\\nCustomer: how much of it is vaguely different\\nCustomer: after these 3 days\\nAgent: the currently executing one\\nAgent: these, actually yours is too\\nCustomer: then this color of yours\\nAgent: according to the expectation he gave, is it settled for how many days\\nCustomer: according to the interest he gave, is it extended for how many days, no\\nAgent: what's the problem then\\nAgent: when you're at 3 days, inside\\nCustomer: if you were the original one\\nCustomer: you basically just need to look\\nAgent: if you were the original, you, you basically don't need\\nAgent: 5 days\\nCustomer: right\\nCustomer: ah, regarding\\nCustomer: 15 new\\nCustomer: recorded above\\n\\n```\\nThe task instruction is as follows:\\n```\\nYou are an intelligent office assistant that can generate a brief summary of the dialogue analysis content.\\n```\\nPlease follow the instruction above and complete the task accurately.");
        messageList.add(message1);
        messageList.add(message2);

        request.setMessages(messageList);
        request.setStream(false);
        request.setModelCode("tyxmTurbo");

        RunCompletionMessageResponse responseBody = client.runCompletionMessage(workspaceId, appId, request);
        RunCompletionMessageResponseBody body = responseBody.getBody();
        System.out.println(JSON.toJSONString(body));
    }
}
from alibabacloud_contactcenterai20240603.client import Client

import alibabacloud_contactcenterai20240603
import alibabacloud_tea_openapi
from alibabacloud_tea_openapi.models import Config
from alibabacloud_contactcenterai20240603.models import RunCompletionMessageRequest
from alibabacloud_contactcenterai20240603.models import RunCompletionMessageRequest
from alibabacloud_contactcenterai20240603.models import RunCompletionMessageRequestMessages

ak = "YOUR_ACCESS_KEY_ID"
sk = "YOUR_ACCESS_KEY_SECRET"
workSpace = "YOUR_WORKSPACEID"
appId = "YOUR_APPID"

if __name__ == '__main__':
    config = Config()
    config.access_key_id = ak
    config.access_key_secret = sk
    config.endpoint = "contactcenterai.cn-shanghai.aliyuncs.com"
    config.region_id = "cn-shanghai"

    client = Client(config)

    # Prompt
    role = "system"
    content = "You are a helpful assistant."
    requestMessage1 = RunCompletionMessageRequestMessages(content, role)
    role = "user"
    content = "Please read the following dialogue and execute the instruction task as required.\n```\n\nAgent: your own words\nCustomer: you want the phone number yourself\nCustomer: 31\nAgent: he is 1 cm\nCustomer: after the new year, I see\nCustomer: opened it later to look\nCustomer: hmm, if it weren't for the previous one\nCustomer: this isn't, look, you look\nAgent: after the new year I changed it to extend by execution time; with the old time extension you couldn't extend at all\nAgent: you follow along here to the back\nAgent: isn't it that after so many days you become a member here\nCustomer: then aren't you settled after more than that many days\nAgent: hmm\nCustomer: hmm\nAgent: we have one\nCustomer: it's this one of yours\nAgent: he said you also follow this here\nCustomer: how much of it is vaguely different\nCustomer: after these 3 days\nAgent: the currently executing one\nAgent: these, actually yours is too\nCustomer: then this color of yours\nAgent: according to the expectation he gave, is it settled for how many days\nCustomer: according to the interest he gave, is it extended for how many days, no\nAgent: what's the problem then\nAgent: when you're at 3 days, inside\nCustomer: if you were the original one\nCustomer: you basically just need to look\nAgent: if you were the original, you, you basically don't need\nAgent: 5 days\nCustomer: right\nCustomer: ah, regarding\nCustomer: 15 new\nCustomer: recorded above\n\n```\nThe task instruction is as follows:\n```\nYou are an intelligent office assistant that can generate a brief summary of the dialogue analysis content.\n```\nPlease follow the instruction above and complete the task accurately."
    requestMessage2 = RunCompletionMessageRequestMessages(content, role)

    listRequestMessage = [requestMessage1, requestMessage2]

    request = RunCompletionMessageRequest()
    request.messages = listRequestMessage
    request.model_code = "tyxmTurbo"
    request.stream = False

    # Send request
    response = client.run_completion_message(workSpace, appId, request)
    body = response.body
    print(body)