Conversation analysis (Tongyi-Xiaomi-Analysis)

Updated at:

Tongyi-Xiaomi-Analysis specializes in information extraction from dialogues, scenario classification, and satisfaction analysis. It excels at handling complex quality inspection rules, supports custom analysis standards, and provides powerful multi-turn dialogue understanding and semantic reasoning.

Core features

  • Information extraction: Automatically extracts key information from unstructured dialogues, such as time, location, product, issue description, and customer requests.

    Typical applications: Automating work order population, updating CRM customer information, and classifying and archiving issues.

  • Scenario classification: Identifies the business scenario of a dialogue and supports custom scenario categories.

    Typical applications: Automatically routing dialogues to specialized teams, tracking inquiry volume by scenario, and optimizing service processes for specific scenarios.

  • Satisfaction analysis: Determines customer satisfaction levels based on custom rules and supports multi-dimensional evaluation.

    Typical applications: Evaluating agent performance, monitoring service quality, and improving customer experience.

  • Complex quality inspection: Supports complex quality inspection rules, including nested conditions and logical reasoning, to accurately enforce enterprise-specific standards.

    Typical applications: Performing quality inspections in highly regulated industries like finance and healthcare, checking multi-step business processes, and verifying compliance with complex scripts.

  • Multi-turn dialogue understanding: Automatically connects context across turns to accurately resolve references and dependencies, grasping the user's true intent in a multi-turn exchange.

    Typical applications: Analyzing dialogues in complex business processes, understanding intent in long conversations, and extracting context-dependent information.

  • Deep semantic understanding: Accurately identifies implied meanings, emotional tones, and subtext in a conversation.

    Typical applications: Monitoring customer sentiment, detecting potential complaints, and identifying sales opportunities.

These features can be implemented by using custom prompts. For usage details, see Feature demos.

Scope

  • Supported regions: Only China (Beijing) is supported. You must use an API Key from this region.

  • Supported languages: The conversation analysis models only support Chinese dialogue analysis and do not support other languages.

  • Supported models:
    • tongyi-xiaomi-analysis-flash: Designed for structured analysis tasks such as information extraction and scenario classification. Suitable for low-latency online analysis and cost-sensitive offline tasks.
    • tongyi-xiaomi-analysis-pro: Designed for complex logical reasoning and deep semantic understanding. Suitable for scenarios such as quality inspection with multi-condition nested rules and multi-turn dialogue analysis with strong contextual dependencies. Compared to the Flash model, it offers stronger reasoning and understanding but at a higher cost and latency.

    For more information, see Model selection.

  • The models support implicit cache. Cache-hit tokens are billed according to the implicit cache billing rules.

Model selection

Use case

Recommended model

Model advantages

Recommendations

Fast information extraction and scenario classification

tongyi-xiaomi-analysis-flash

Low latency and cost. Suitable for high-frequency, real-time calls.

Use for standardized extraction and classification tasks that do not involve complex reasoning.

Standard quality inspection

tongyi-xiaomi-analysis-flash

Accurately understands dialogue semantics and sentiment, supports custom evaluation rules, and meets most quality inspection needs.

Use for quality inspection scenarios with clear rules. For complex business logic, use the pro model.

Complex logical quality inspection

tongyi-xiaomi-analysis-pro

Stronger reasoning capabilities, supporting complex business rules such as nested conditions and contextual dependencies.

Higher cost than the flash model. Use for scenarios that require extremely high accuracy, such as finance and healthcare.

In-depth multi-turn dialogue analysis

tongyi-xiaomi-analysis-pro

Stronger dialogue understanding capabilities, accurately understanding references and implied intent.

Use for scenarios that require a global understanding, such as post-sales ticket analysis and complaint root-cause analysis.

Quick start

Usage suggestions

  • Standardize dialogue content format: Organize dialogue content in the format of [Turn] Role: Content. Using a standard format helps the model parse the dialogue structure and accurately identify speaker roles, turn order, and contextual references.

    Example:

[1] 客服:您好,欢迎致电AB电商平台,请问有什么可以帮您?
[2] 客户:你好,我上周在你们店买了一台料理机,现在运行时有点异响。
[3] 客服:很抱歉给您带来困扰,请问异响是在开机后立刻出现还是运行一段时间后出现的呢?
  • Write clear rules: Clear analysis rules are key to the model's accuracy. Vague or contradictory rules can lead to unexpected analysis results.

    Tips for writing rules:

    • Be specific and actionable: Avoid vague descriptions. For example, instead of "good service attitude," use "responded promptly and used polite language."
    • Define priorities: When there are multiple rules, define their priorities and execution order to resolve potential conflicts and ensure the model can make a clear judgment.
    • Provide positive and negative examples: Include positive and negative examples in your rules to help the model accurately understand the evaluation criteria.
  • Use special markers for key terms: When a business term has a definition that differs from its common understanding, use a special marker (such as an abbreviation) to replace the term. This prevents the model from interpreting it based on general knowledge.

  • Set API parameters: Conversation analysis tasks typically require deterministic and accurate results. Use the following parameter settings:

    • temperature: Set to 0.0 so the model returns the same result for the same input every time, ensuring analysis consistency.
    • top_k: Set to 1 so the model always selects the highest-probability token, avoiding randomness.
  • Control the output format: To ensure parsable and controllable analysis results, specify the output format in the prompt. If necessary, provide an output example.

Code examples

Prerequisites: Obtain an API Key. If you use an SDK, install the latest version of the SDK.

OpenAI-compatible

from openai import OpenAI
import os

dialogue = """
[1] 客服:您好,欢迎致电AB电商平台,请问有什么可以帮您?
[2] 客户:你好,我上周在你们店买了一台料理机,现在运行时有点异响。
[3] 客服:很抱歉给您带来困扰,请问异响是在开机后立刻出现还是运行一段时间后出现的呢?
[4] 客户:差不多开机几秒钟后就有了,而且声音很尖锐。
[5] 客服:了解了,请问您方便拍一段运行过程的视频发给我们技术人员确认吗?
[6] 客户:可以,我一会儿拍好发给你们。
[7] 客服:好的,我们收到视频后会在两小时内给您回复处理方案。
[8] 客户:那如果确定是质量问题,是可以直接换新的吧?
[9] 客服:是的,如果检测为质量问题,我们将为您免费更换新机并承担运费。
[10] 客户:好的,那我等你们的反馈,谢谢你们的耐心解答。
"""

analysis_prompt = f"""
## 客服质检满意度判定规则

### 一、目标
根据客服与客户的对话内容,准确解析客户的情绪与反馈,判定其**满意度等级**(满意 / 不满意 / 一般),并提供判定理由,用于客服质检与服务改进。

### 二、判定流程(必须自上而下匹配,遇到符合条件的规则时立即终止后续判断)

1. **无客户发言**
   - 条件:整段对话中没有客户的内容。
   - 结果:判定为 **一般**。

2. **投诉或强烈不满**
   - 条件:客户直接或间接表示要投诉(对象包括骑手、快递员、商家、客服等),或者在催促问题进度时带有明显焦急、质问、抱怨等消极情绪。
   - 示例:
     - "我要投诉你们的配送员"
     - "怎么还没处理?到底什么时候能好?"
   - 结果:判定为 **不满意**,并立即结束判定。

3. **最后一句负面情绪**
   - 条件:客户的最后一句话中出现负面情绪。
   - 结果:判定为 **不满意**。

4. **无感谢记录**
   - 条件:如果整个对话中客户没有表达"谢谢"等明确感谢语。
   - 结果:判定为 **一般**。

5. **客户主动表示满意或好评**
   - 条件:对话中客户明确表示对客服满意或给予好评。
   - 结果:忽略第4条直接判定为 **满意**。

6. **方案后感谢**
   - 条件:服务结束前,客服提供了赔付、退单、退款等解决方案后,客户明确积极地表示感谢。
   - 注意点:
     - "好的"、"行"不算感谢
     - 没有回复不算认可
   - 结果:判定为 **满意**。

7. **其他情况**
   - 条件:非上述任何情况,且无投诉或明显不满。
   - 结果:判定为 **一般**。

### 三、对话内容
```text
{dialogue}
```

### 四、输出格式
判定结果需包含两个部分:
1. **满意度标签**:满意 / 不满意 / 一般
2. **判定理由**:基于上述规则的简要说明。

格式:
```
Satisfaction Label#Reason for Judgment
```
示例:
```
Neutral#The customer did not express thanks, nor did they show any complaints or dissatisfaction during the dialogue, so the judgment is neutral.
Dissatisfied#The customer showed clear dissatisfaction and questioning when asking about the progress, matching Rule 2, so the judgment is dissatisfied.
```
"""

# 获取API Key:https://help.aliyun.com/zh/model-studio/get-api-key
# 若没有配置环境变量,请用阿里云百炼API Key将下行替换为:api_key="sk-xxx"
client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # 华北2(北京)地域的URL。调用时将 {WorkspaceId} 替换为真实的业务空间ID。
    base_url="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1",
)

completion = client.chat.completions.create(
    model="tongyi-xiaomi-analysis-flash",
    messages=[
        {
            'role': 'user',
            'content': analysis_prompt
        }
    ],
    temperature=0,
    extra_body={
        "top_k": 1
    }
)

print(completion.choices[0].message.content)
import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.core.JsonValue;
import com.openai.models.chat.completions.ChatCompletion;
import com.openai.models.chat.completions.ChatCompletionCreateParams;

public class Main {
    public static void main(String[] args) {
        try {
            OpenAIClient client = OpenAIOkHttpClient.builder()
                    // 获取API Key:https://help.aliyun.com/zh/model-studio/get-api-key
                    // 若没有配置环境变量,请用阿里云百炼API Key将下行替换为.apiKey("sk-xxx")
                    .apiKey(System.getenv("DASHSCOPE_API_KEY"))
                    // 华北2(北京)地域的URL。
                    // 将{WorkspaceId}替换为真实的业务空间ID。各地域的URL不同
                    .baseUrl("https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1")
                    .build();
            // 创建 ChatCompletion 参数
            ChatCompletionCreateParams params = ChatCompletionCreateParams.builder()
                    .model("tongyi-xiaomi-analysis-flash")
                    .addUserMessage(getUserMessage())
                    .temperature(0.0)
                    .putAdditionalBodyProperty("top_k", JsonValue.from(1))
                    .build();
            // 发送请求并获取响应
            ChatCompletion chatCompletion = client.chat().completions().create(params);
            String content = chatCompletion.choices().get(0).message().content().orElse("未返回有效内容");
            System.out.println(content);
            // 如需查看完整响应,请取消下列注释
            // System.out.println(chatCompletion);

        } catch (Exception e) {
            System.err.println("错误信息:" + e.getMessage());
        }
    }

    private static String getUserMessage() {
        String dialogue ="[1] 客服:您好,欢迎致电AB电商平台,请问有什么可以帮您?\n" +
                "                [2] 客户:你好,我上周在你们店买了一台料理机,现在运行时有点异响。\n" +
                "                [3] 客服:很抱歉给您带来困扰,请问异响是在开机后立刻出现还是运行一段时间后出现的呢?\n" +
                "                [4] 客户:差不多开机几秒钟后就有了,而且声音很尖锐。\n" +
                "                [5] 客服:了解了,请问您方便拍一段运行过程的视频发给我们技术人员确认吗?\n" +
                "                [6] 客户:可以,我一会儿拍好发给你们。\n" +
                "                [7] 客服:好的,我们收到视频后会在两小时内给您回复处理方案。\n" +
                "                [8] 客户:那如果确定是质量问题,是可以直接换新的吧?\n" +
                "                [9] 客服:是的,如果检测为质量问题,我们将为您免费更换新机并承担运费。\n" +
                "                [10] 客户:好的,那我等你们的反馈,谢谢你们的耐心解答。";

        String analysisPrompt = "## 客服质检满意度判定规则\n" +
                "\n" +
                "### 一、目标\n" +
                "根据客服与客户的对话内容,准确解析客户的情绪与反馈,判定其**满意度等级**(满意 / 不满意 / 一般),并提供判定理由,用于客服质检与服务改进。\n" +
                "\n" +
                "### 二、判定流程(必须自上而下匹配,遇到符合条件的规则时立即终止后续判断)\n" +
                "\n" +
                "1. **无客户发言**\n" +
                "   - 条件:整段对话中没有客户的内容。\n" +
                "   - 结果:判定为 **一般**。\n" +
                "\n" +
                "2. **投诉或强烈不满**\n" +
                "   - 条件:客户直接或间接表示要投诉(对象包括骑手、快递员、商家、客服等),或者在催促问题进度时带有明显焦急、质问、抱怨等消极情绪。\n" +
                "   - 示例:\n" +
                "     - \"我要投诉你们的配送员\"\n" +
                "     - \"怎么还没处理?到底什么时候能好?\"\n" +
                "   - 结果:判定为 **不满意**,并立即结束判定。\n" +
                "\n" +
                "3. **最后一句负面情绪**\n" +
                "   - 条件:客户的最后一句话中出现负面情绪。\n" +
                "   - 结果:判定为 **不满意**。\n" +
                "\n" +
                "4. **无感谢记录**\n" +
                "   - 条件:如果整个对话中客户没有表达\"谢谢\"等明确感谢语。\n" +
                "   - 结果:判定为 **一般**。\n" +
                "\n" +
                "5. **客户主动表示满意或好评**\n" +
                "   - 条件:对话中客户明确表示对客服满意或给予好评。\n" +
                "   - 结果:忽略第4条直接判定为 **满意**。\n" +
                "\n" +
                "6. **方案后感谢**\n" +
                "   - 条件:服务结束前,客服提供了赔付、退单、退款等解决方案后,客户明确积极地表示感谢。\n" +
                "   - 注意点:\n" +
                "     - \"好的\"、\"行\"不算感谢\n" +
                "     - 没有回复不算认可\n" +
                "   - 结果:判定为 **满意**。\n" +
                "\n" +
                "7. **其他情况**\n" +
                "   - 条件:非上述任何情况,且无投诉或明显不满。\n" +
                "   - 结果:判定为 **一般**。\n" +
                "\n" +
                "### 三、对话内容\n" +
                "```text\n" +
                dialogue + "\n" +
                "```\n" +
                "\n" +
                "### 四、输出格式\n" +
                "判定结果需包含两个部分:\n" +
                "1. **满意度标签**:满意 / 不满意 / 一般\n" +
                "2. **判定理由**:基于上述规则的简要说明。\n" +
                "\n" +
                "格式:\n" +
                "```\n" +
                "Satisfaction Label#Reason for Judgment\n" +
                "```\n" +
                "示例:\n" +
                "```\n" +
                "Neutral#The customer did not express thanks, nor did they show any complaints or dissatisfaction during the dialogue, so the judgment is neutral.\n" +
                "Dissatisfied#The customer showed clear dissatisfaction and questioning when asking about the progress, matching Rule 2, so the judgment is dissatisfied.\n" +
                "```";

        return analysisPrompt;
    }
}
// 需要 Node.js v18+,需在 ES Module 环境下运行
import OpenAI from "openai";
const openai = new OpenAI(
    {
        // 获取API Key:https://help.aliyun.com/zh/model-studio/get-api-key
        // 若没有配置环境变量,请用阿里云百炼API Key将下行替换为:apiKey: "sk-xxx",
        apiKey: process.env.DASHSCOPE_API_KEY,
        // 华北2(北京)地域的URL。
        // 将{WorkspaceId}替换为真实的业务空间ID。各地域的URL不同
        baseURL: "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1"
    }
);
const completion = await openai.chat.completions.create({
    model: "tongyi-xiaomi-analysis-flash",
    messages: [
        {
            role: "user",
            content: "请帮我提取下面对话中的关键信息:[1] 客服:您好,欢迎致电AB电商平台,请问有什么可以帮您?[2] 客户:你好,我上周在你们店买了一台料理机,现在运行时有点异响。"
        }
    ],
    temperature: 0,
    top_k: 1
});
console.log(completion.choices[0].message.content);
// 如需查看完整响应,请取消下列注释
// console.log(JSON.stringify(completion, null, 4));
// OpenAI Go SDK版本不低于 v2.4.0
package main

import (
	"context"
	// 如需查看完整响应,请取消下方及代码末尾的注释
	// "encoding/json"
	"fmt"
	"os"

	"github.com/openai/openai-go/v2"
	"github.com/openai/openai-go/v2/option"
)

func main() {
	// 获取API Key:https://help.aliyun.com/zh/model-studio/get-api-key
	// 若没有配置环境变量,请用阿里云百炼API Key将下行替换为:apiKey := "sk-xxx"
	apiKey := os.Getenv("DASHSCOPE_API_KEY")
	client := openai.NewClient(
		option.WithAPIKey(apiKey),
		// 华北2(北京)地域的URL。
		// 将{WorkspaceId}替换为真实的业务空间ID。各地域的URL不同
		option.WithBaseURL("https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1"),
	)

	chatCompletion, err := client.Chat.Completions.New(
		context.TODO(), openai.ChatCompletionNewParams{
			Messages: []openai.ChatCompletionMessageParamUnion{
				openai.UserMessage("请帮我提取下面对话中的关键信息:[1] 客服:您好,欢迎致电AB电商平台,请问有什么可以帮您?[2] 客户:你好,我上周在你们店买了一台料理机,现在运行时有点异响。"),
			},
			Model:       "tongyi-xiaomi-analysis-flash",
			Temperature: openai.Float(0.0),
		},
		option.WithJSONSet("top_k", 1),
	)
	if err != nil {
		fmt.Fprintf(os.Stderr, "请求失败: %v\n", err)
		os.Exit(1)
	}
	if len(chatCompletion.Choices) > 0 {
		fmt.Println(chatCompletion.Choices[0].Message.Content)
	}
	// 如需查看完整响应,请取消下列注释
	// jsonData, _ := json.MarshalIndent(chatCompletion, "", "  ")
	// fmt.Println(string(jsonData))
}
# 华北2(北京)地域的URL。
# 将{WorkspaceId}替换为真实的业务空间ID。各地域的URL不同
curl --location "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/chat/completions" \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
    "model": "tongyi-xiaomi-analysis-flash",
    "messages": [
        {
            "role": "user",
            "content": "请帮我提取下面对话中的关键信息:[1] 客服:您好,欢迎致电AB电商平台,请问有什么可以帮您?[2] 客户:你好,我上周在你们店买了一台料理机,现在运行时有点异响。"
        }
    ],
    "temperature": 0.0,
    "top_k": 1
}'

DashScope

import dashscope
import os
from dashscope import DashScopeError

# 以下为华北2(北京)地域的配置,调用时请将{WorkspaceId}替换为真实的业务空间ID,各地域的region取值不同。
client = dashscope.Client(
    # 获取API Key:https://help.aliyun.com/zh/model-studio/get-api-key
    # 若没有配置环境变量,请用阿里云百炼API Key将下行替换为:api_key="sk-xxx"
    api_key=os.getenv('DASHSCOPE_API_KEY'),
    workspace="{WorkspaceId}",
    region="cn-beijing",
)

dialogue = """
[1] 客服:您好,欢迎致电AB电商平台,请问有什么可以帮您?
[2] 客户:你好,我上周在你们店买了一台料理机,现在运行时有点异响。
[3] 客服:很抱歉给您带来困扰,请问异响是在开机后立刻出现还是运行一段时间后出现的呢?
[4] 客户:差不多开机几秒钟后就有了,而且声音很尖锐。
[5] 客服:了解了,请问您方便拍一段运行过程的视频发给我们技术人员确认吗?
[6] 客户:可以,我一会儿拍好发给你们。
[7] 客服:好的,我们收到视频后会在两小时内给您回复处理方案。
[8] 客户:那如果确定是质量问题,是可以直接换新的吧?
[9] 客服:是的,如果检测为质量问题,我们将为您免费更换新机并承担运费。
[10] 客户:好的,那我等你们的反馈,谢谢你们的耐心解答。
"""

analysis_prompt = f"""
## 客服质检满意度判定规则

### 一、目标
根据客服与客户的对话内容,准确解析客户的情绪与反馈,判定其**满意度等级**(满意 / 不满意 / 一般),并提供判定理由,用于客服质检与服务改进。

### 二、判定流程(必须自上而下匹配,遇到符合条件的规则时立即终止后续判断)

1. **无客户发言**
   - 条件:整段对话中没有客户的内容。
   - 结果:判定为 **一般**。

2. **投诉或强烈不满**
   - 条件:客户直接或间接表示要投诉(对象包括骑手、快递员、商家、客服等),或者在催促问题进度时带有明显焦急、质问、抱怨等消极情绪。
   - 示例:
     - "我要投诉你们的配送员"
     - "怎么还没处理?到底什么时候能好?"
   - 结果:判定为 **不满意**,并立即结束判定。

3. **最后一句负面情绪**
   - 条件:客户的最后一句话中出现负面情绪。
   - 结果:判定为 **不满意**。

4. **无感谢记录**
   - 条件:如果整个对话中客户没有表达"谢谢"等明确感谢语。
   - 结果:判定为 **一般**。

5. **客户主动表示满意或好评**
   - 条件:对话中客户明确表示对客服满意或给予好评。
   - 结果:忽略第4条直接判定为 **满意**。

6. **方案后感谢**
   - 条件:服务结束前,客服提供了赔付、退单、退款等解决方案后,客户明确积极地表示感谢。
   - 注意点:
     - "好的"、"行"不算感谢
     - 没有回复不算认可
   - 结果:判定为 **满意**。

7. **其他情况**
   - 条件:非上述任何情况,且无投诉或明显不满。
   - 结果:判定为 **一般**。

### 三、对话内容
```text
{dialogue}
```

### 四、输出格式
判定结果需包含两个部分:
1. **满意度标签**:满意 / 不满意 / 一般
2. **判定理由**:基于上述规则的简要说明。

格式:
```
Satisfaction Label#Reason for Judgment
```
示例:
```
Neutral#The customer did not express thanks, nor did they show any complaints or dissatisfaction during the dialogue, so the judgment is neutral.
Dissatisfied#The customer showed clear dissatisfaction and questioning when asking about the progress, matching Rule 2, so the judgment is dissatisfied.
```
"""

try:
    response = client.chat.completions.create(
        model="tongyi-xiaomi-analysis-flash",
        messages=[
            {
                'role': 'user',
                'content': analysis_prompt
            }
        ],
        temperature=0.0,
        top_k=1,
    )
    print(response.choices[0].message.content)
except DashScopeError as e:
    print(f"HTTP返回码:{e.status_code}")
    print(f"错误码:{e.code}")
    print(f"错误信息:{e.message}")
    print("请参考文档:https://help.aliyun.com/zh/model-studio/developer-reference/error-code")
import java.util.Arrays;
import java.lang.System;
import com.alibaba.dashscope.aigc.generation.Generation;
import com.alibaba.dashscope.aigc.generation.GenerationParam;
import com.alibaba.dashscope.aigc.generation.GenerationResult;
import com.alibaba.dashscope.common.Message;
import com.alibaba.dashscope.common.Role;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.protocol.Protocol;

public class Main {
    public static GenerationResult callWithMessage() throws ApiException, NoApiKeyException, InputRequiredException {
        // 华北2(北京)地域的URL。
        // 将{WorkspaceId}替换为真实的业务空间ID。各地域的URL不同
        Generation gen = new Generation(Protocol.HTTP.getValue(), "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1");

        Message userMsg = Message.builder()
                .role(Role.USER.getValue())
                .content(getContent())
                .build();

        GenerationParam param = GenerationParam.builder()
                // 获取API Key:https://help.aliyun.com/zh/model-studio/get-api-key
                // 若没有配置环境变量,请用阿里云百炼API Key将下行替换为:.apiKey("sk-xxx")
                .apiKey(System.getenv("DASHSCOPE_API_KEY"))
                .model("tongyi-xiaomi-analysis-flash")
                .messages(Arrays.asList(userMsg))
                .temperature(0.0f)
                .topK(1)
                .resultFormat(GenerationParam.ResultFormat.MESSAGE)
                .build();
        return gen.call(param);
    }

    public static void main(String[] args) {
        try {
            GenerationResult result = callWithMessage();
            System.out.println(result.getOutput().getChoices().get(0).getMessage().getContent());
            // 如需查看完整响应,请取消下列注释
            // System.out.println(JsonUtils.toJson(result));
        } catch (ApiException | NoApiKeyException | InputRequiredException e) {
            System.err.println("错误信息:"+e.getMessage());
        }
    }

    private static String getContent() {
        String dialogue ="[1] 客服:您好,欢迎致电AB电商平台,请问有什么可以帮您?\n" +
                "                [2] 客户:你好,我上周在你们店买了一台料理机,现在运行时有点异响。\n" +
                "                [3] 客服:很抱歉给您带来困扰,请问异响是在开机后立刻出现还是运行一段时间后出现的呢?\n" +
                "                [4] 客户:差不多开机几秒钟后就有了,而且声音很尖锐。\n" +
                "                [5] 客服:了解了,请问您方便拍一段运行过程的视频发给我们技术人员确认吗?\n" +
                "                [6] 客户:可以,我一会儿拍好发给你们。\n" +
                "                [7] 客服:好的,我们收到视频后会在两小时内给您回复处理方案。\n" +
                "                [8] 客户:那如果确定是质量问题,是可以直接换新的吧?\n" +
                "                [9] 客服:是的,如果检测为质量问题,我们将为您免费更换新机并承担运费。\n" +
                "                [10] 客户:好的,那我等你们的反馈,谢谢你们的耐心解答。";

        String analysisPrompt = "## 客服质检满意度判定规则\n" +
                "\n" +
                "### 一、目标\n" +
                "根据客服与客户的对话内容,准确解析客户的情绪与反馈,判定其**满意度等级**(满意 / 不满意 / 一般),并提供判定理由,用于客服质检与服务改进。\n" +
                "\n" +
                "### 二、判定流程(必须自上而下匹配,遇到符合条件的规则时立即终止后续判断)\n" +
                "\n" +
                "1. **无客户发言**\n" +
                "   - 条件:整段对话中没有客户的内容。\n" +
                "   - 结果:判定为 **一般**。\n" +
                "\n" +
                "2. **投诉或强烈不满**\n" +
                "   - 条件:客户直接或间接表示要投诉(对象包括骑手、快递员、商家、客服等),或者在催促问题进度时带有明显焦急、质问、抱怨等消极情绪。\n" +
                "   - 示例:\n" +
                "     - \"我要投诉你们的配送员\"\n" +
                "     - \"怎么还没处理?到底什么时候能好?\"\n" +
                "   - 结果:判定为 **不满意**,并立即结束判定。\n" +
                "\n" +
                "3. **最后一句负面情绪**\n" +
                "   - 条件:客户的最后一句话中出现负面情绪。\n" +
                "   - 结果:判定为 **不满意**。\n" +
                "\n" +
                "4. **无感谢记录**\n" +
                "   - 条件:如果整个对话中客户没有表达\"谢谢\"等明确感谢语。\n" +
                "   - 结果:判定为 **一般**。\n" +
                "\n" +
                "5. **客户主动表示满意或好评**\n" +
                "   - 条件:对话中客户明确表示对客服满意或给予好评。\n" +
                "   - 结果:忽略第4条直接判定为 **满意**。\n" +
                "\n" +
                "6. **方案后感谢**\n" +
                "   - 条件:服务结束前,客服提供了赔付、退单、退款等解决方案后,客户明确积极地表示感谢。\n" +
                "   - 注意点:\n" +
                "     - \"好的\"、\"行\"不算感谢\n" +
                "     - 没有回复不算认可\n" +
                "   - 结果:判定为 **满意**。\n" +
                "\n" +
                "7. **其他情况**\n" +
                "   - 条件:非上述任何情况,且无投诉或明显不满。\n" +
                "   - 结果:判定为 **一般**。\n" +
                "\n" +
                "### 三、对话内容\n" +
                "```text\n" +
                dialogue + "\n" +
                "```\n" +
                "\n" +
                "### 四、输出格式\n" +
                "判定结果需包含两个部分:\n" +
                "1. **满意度标签**:满意 / 不满意 / 一般\n" +
                "2. **判定理由**:基于上述规则的简要说明。\n" +
                "\n" +
                "格式:\n" +
                "```\n" +
                "Satisfaction Label#Reason for Judgment\n" +
                "```\n" +
                "示例:\n" +
                "```\n" +
                "Neutral#The customer did not express thanks, nor did they show any complaints or dissatisfaction during the dialogue, so the judgment is neutral.\n" +
                "Dissatisfied#The customer showed clear dissatisfaction and questioning when asking about the progress, matching Rule 2, so the judgment is dissatisfied.\n" +
                "```";

        return analysisPrompt;
    }
}
# 华北2(北京)地域的URL。
# 将{WorkspaceId}替换为真实的业务空间ID。各地域的URL不同
curl --location "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/text-generation/generation" \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header "Content-Type: application/json" \
--data '{
    "model": "tongyi-xiaomi-analysis-flash",
    "input":{
        "messages":[
            {
                "role": "user",
                "content": "请帮我提取下面对话中的关键信息:[1] 客服:您好,欢迎致电AB电商平台,请问有什么可以帮您?[2] 客户:你好,我上周在你们店买了一台料理机,现在运行时有点异响。"
            }
        ],
        "temperature": 0.0,
        "top_k": 1
    },
    "parameters": {
        "result_format": "message"
    }
}'

Feature examples

Each feature example provides runnable content. To try out a feature, replace the content in the code sample.

Dialogue information extraction

Feature description: Automatically extracts key information from unstructured dialogues, such as time, location, product, problem description, and customer requests.

Use cases:

  • Automatic ticket system population
  • CRM customer information updates
  • Problem classification and archiving

content example:

请从以下对话中提取关键信息,并按照 JSON 格式输出。

对话内容:
```
[1] Customer Service: Hello, this is Wang. How can I help you?
[2] Customer: Hello, I bought an iPhone 15 at your Nanjing Xinjiekou store last Wednesday. The order number is 123456789. The screen is now a bit yellow.
[3] Customer Service: Okay, let me check for you. Could you please provide your phone number?
[4] Customer: 138****5678
[5] Customer Service: Got it. I see your order. Regarding the yellow screen issue, under what circumstances did you notice it?
[6] Customer: I noticed it during normal use. It's especially obvious when looking at a white background.
```

Information to extract:
1. Purchase time
2. Purchase store
3. Product name
4. Order number
5. Customer contact
6. Issue description
7. Issue discovery context

Output format (JSON):
```json
{{
  "purchase_time": "...",
  "purchase_store": "...",
  "product_name": "...",
  "order_number": "...",
  "customer_contact": "...",
  "issue_description": "...",
  "issue_discovery_context": "..."
}}
```

Note: If an item is not mentioned in the dialogue, fill in "Not mentioned".

Scenario classification

Feature description: Automatically identifies the business scenario of a dialogue and supports custom scenario categories.

Use cases:

  • Automatic dialogue routing to specialized teams
  • Statistics on inquiry volume for different scenarios
  • Targeted optimization of service processes

content example:

请判断以下对话属于哪个业务场景。

对话内容:
```
[1] Customer Service: Hello, welcome to the customer service hotline. How can I help you?
[2] Customer: I'd like to ask about your membership promotions.
[3] Customer Service: Okay, we currently offer a 20% discount for the first month for new members, and existing members can earn reward points for referring friends.
[4] Customer: So how do I register for a membership?
[5] Customer Service: You can register through our app or mini program. Just fill in your basic information.
[6] Customer: Okay, thanks.
```

可选场景类别:
1. 售前咨询 - 客户询问产品功能、价格、购买方式等
2. 售后投诉 - 客户反映产品问题、服务不满、要求退换货等
3. 物流查询 - 客户询问订单状态、配送进度、物流信息等
4. 会员服务 - 客户咨询会员权益、积分、优惠活动等
5. 技术支持 - 客户寻求产品使用帮助、故障排查等
6. 账户问题 - 客户反映登录、密码、账户安全等问题

输出格式:
```
Scenario category: [Select one from the categories above]
Confidence: [High/Medium/Low]
Rationale: [Briefly explain the reason in 1-2 sentences]
```

Satisfaction analysis

Feature description: Determines customer satisfaction based on custom rules and supports multi-dimensional assessment.

Use cases:

  • Customer service performance assessment
  • Service quality monitoring
  • Customer experience improvement

content example:

请根据以下对话判定客户满意度。

对话内容:
```
[1] Customer Service: Hello, this is Agent Li. How can I help you?
[2] Customer: Why hasn't my order shipped yet? It's been three days!
[3] Customer Service: I'm very sorry for the inconvenience. I'll check for you right away. What is your order number?
[4] Customer: 1234567890
[5] Customer Service: Okay, I see your order. Shipping is slightly delayed due to a recent logistics peak. I will contact the warehouse immediately to expedite it. It will be shipped out today.
[6] Customer: Then when will it arrive?
[7] Customer Service: It is expected to arrive in 3-5 business days. As an apology, I have added a 20 yuan coupon to your account for your next purchase.
[8] Customer: Alright, just ship it quickly.
[9] Customer Service: Absolutely! I will keep an eye on your order and notify you as soon as it ships. Is there anything else I can help you with?
[10] Customer: No.
```

满意度判定标准:
1. **不满意**:客户明确表达投诉、不满、要求赔偿或退款
2. **一般**:客户问题得到解决但未表达感谢或认可,或对解决方案持保留态度
3. **满意**:客户明确表达感谢、认可服务,或对解决方案表示接受和满意

评估维度:
- 客户情绪(初始情绪 vs 结束时情绪)
- 问题解决情况(是否给出解决方案)
- 客户反馈(是否表达感谢、认可或继续不满)
- 补偿措施(是否有额外补偿或优惠)

输出格式:
```
Satisfaction level: [Satisfied/Neutral/Dissatisfied]
Initial emotion: [Describe the customer's initial emotional state]
Final emotion: [Describe the customer's emotional state at the end of the dialogue]
Problem resolved: [Yes/No/Partially resolved]
Rationale: [Explain the basis for the determination in detail, referencing the assessment dimensions]
```

Complex quality inspection

Feature description: Supports complex quality inspection rules such as nested conditions and logical reasoning to accurately enforce company-specific quality standards.

Use cases:

  • Industries with high compliance requirements, such as finance and healthcare
  • Quality inspection for multi-step business processes
  • Compliance checks for complex scripts

content example:

请根据以下金融行业客服质检规则,对对话进行质检。

对话内容:
```
[1] Customer Service: Hello, welcome to the XX Bank Credit Card Center. I am Agent 8888, Zhang. How can I help you?
[2] Customer: I'd like to request a credit limit increase for my credit card.
[3] Customer Service: Okay, what is your name and ID card number?
[4] Customer: My name is Zhang San, and my ID card number is 110101199001011234.
[5] Customer Service: Okay, Mr. Zhang. Let me check for you. Your current credit card limit is 20,000 yuan. Based on your card usage history and credit score, we can increase it to 50,000 yuan. Would you like to proceed?
[6] Customer: Yes, go ahead.
[7] Customer Service: Okay, please confirm: Your credit card limit will be increased from 20,000 yuan to 50,000 yuan, effective immediately. Do you confirm?
[8] Customer: Confirmed.
[9] Customer Service: Okay, your application has been submitted and is expected to be completed within 2 business days. Thank you for calling. Have a great day. Goodbye.
```

质检规则(必须严格执行):

**一、开场白规则(必检项)**
- 规则1:必须包含"您好"或"欢迎"
- 规则2:必须自报工号
- 规则3:必须说明所属机构(如"XX银行信用卡中心")
- **判定**:以上三项全部满足才算合格

**二、身份验证规则(必检项)**
- 规则4:涉及账户操作时,必须核验客户身份(姓名+身份证号 或 姓名+银行卡号)
- **判定**:涉及账户操作但未核验身份,则为严重违规

**三、重要事项告知规则(必检项)**
- 规则5:涉及额度调整、费率变更、产品变更时,必须:
  - 明确告知变更前后的具体内容
  - 告知生效时间
  - 获得客户明确确认("是"、"确认"、"同意"等明确表述)
- **判定**:以上任一项缺失,则为严重违规

**四、结束语规则(建议项)**
- 规则6:建议包含感谢语
- 规则7:建议包含祝福语
- **判定**:不合格不影响整体质检结果,但会扣分

**输出格式**:
```
Inspection result: [Pass/Fail]
Number of violations: [Number]

Detailed check:
1. Opening script rules: [Pass/Fail] - [Explanation]
2. Identity verification rules: [Pass/Fail] - [Explanation]
3. Important information disclosure rules: [Pass/Fail] - [Explanation]
4. Closing script rules: [Pass/Fail (Recommended)] - [Explanation]

Overall evaluation: [Summary evaluation, 1-2 sentences]
```

Multi-turn dialogue understanding

Feature description: Automatically links previous and subsequent parts of a dialogue to accurately understand anaphora and contextual dependencies.

Use cases:

  • Dialogue analysis for complex business processes
  • Intent understanding in long dialogues
  • Context-aware information extraction

content example:

请从以下对话中提取完整的工单信息,需要整合多轮对话中分散的信息。

对话内容:
```
[1] Customer Service: Hello, how can I help you?
[2] Customer: The router I bought last week keeps disconnecting.
[3] Customer Service: Okay, which model did you purchase?
[4] Customer: The AX3000, the white one.
[5] Customer Service: Got it. How often does it disconnect?
[6] Customer: About once every 2-3 hours. It really affects my work.
[7] Customer Service: Understood. When did this start happening?
[8] Customer: Just in the last two days. It was working fine before.
[9] Customer Service: I see. Have you recently moved the router or changed any settings?
[10] Customer: No, it's always been in the living room, and I haven't touched the settings.
[11] Customer Service: Okay, this problem might be caused by an old firmware version. I suggest you try upgrading the firmware first.
[12] Customer: How do I upgrade it?
[13] Customer Service: Open our app on your phone, find this device, and tap "Firmware Upgrade".
[14] Customer: Okay, I'll try it now.
[15] Customer Service: Okay, the upgrade process takes about 5 minutes. The network will disconnect during this time. Do not turn off the router's power.
[16] Customer: Okay, will it reconnect automatically after the upgrade?
[17] Customer Service: Yes, it will restart automatically when finished. Then you can just reconnect to the Wi-Fi.
[18] Customer: I see. What if it still disconnects after the upgrade?
[19] Customer Service: If the problem persists after the upgrade, it might be a hardware failure. I will arrange a replacement or an on-site inspection for you.
[20] Customer: Okay, I'll try it first. Thanks.
```

Extract the following information (note: this information is scattered across different dialogue turns and requires contextual association):

1. **Product information** (model, appearance features, purchase time)
2. **Issue description** (specific symptoms, frequency)
3. **Issue timeline** (when it started, whether it was normal before)
4. **Customer actions** (any special operations or adjustments)
5. **Agent diagnosis** (preliminary cause assessment)
6. **Solution** (recommended handling steps)
7. **Fallback plan** (alternative options if the solution does not work)

Output in a structured format and indicate which dialogue turns each piece of information comes from.

Deep semantic understanding

Feature description: Accurately identifies implicit semantics, emotional sentiment, and subtext in dialogues.

Use cases:

  • Customer emotion monitoring
  • Potential complaint alerts
  • Sales opportunity identification

content example:

请对以下对话进行深层语义分析。

对话内容:
```
[1] Customer Service: Hello, how can I help you?
[2] Customer: Why did my membership suddenly expire? I could still use it last month.
[3] Customer Service: Hello, let me check for you. What is your phone number?
[4] Customer: 138****5678
[5] Customer Service: Okay, I see that you have an annual membership that expired on October 15 of last year.
[6] Customer: Oh, I see. Can I still use the coupons I bought before?
[7] Customer Service: Member-exclusive coupons cannot be used after the membership expires. However, you can renew your membership to continue using the coupons.
[8] Customer: Alright, I get it.
[9] Customer Service: Is there anything else I can help you with?
[10] Customer: No, thanks.
```

分析维度:

1. **客户情绪分析**
   - 第2轮:"我的会员怎么突然过期了?上个月还能用的" 的情绪和隐含语义是什么?
   - 第6轮:"哦,是这样啊" 的情绪变化是什么?
   - 第8轮:"好吧,我知道了" 的真实情感是什么?

2. **潜在问题识别**
   - 客户是否存在不满情绪?
   - 是否有潜在的投诉风险?
   - 是否对服务或规则有误解?

3. **客户真实诉求**
   - 客户最关心的是什么?
   - 客户的问题是否得到满意解决?
   - 客户是否有未表达的需求?

4. **改进建议**
   - 客服的回应是否得当?
   - 如何改进可以提升客户满意度?

输出格式:按照上述四个维度,清晰地输出分析结果。

API reference

For the input and output parameters of the model, see Text generation.