数据归档

本文将为您介绍如何实现数据归档。

功能说明

数据归档是将用户与AI智能体的对话转化为文本信息并进行存储,企业可通过API接口调用以消费这部分数据。同时,企业也可以将用户与AI智能体通话的音视频数据存储至对象存储服务(OSS)或视频点播(VOD)平台。

功能实现

阿里云为您提供以下几种数据归档方式:文本内容的聊天记录、音频逐句回调以及ARTC录制的通话内容:

文本聊天记录

您可以通过调用DescribeAIAgentInstance - 查询智能体实例详情API,获取CallLogUrl字段中的文本文件地址,将生成的文本聊天记录进行存储。

调用示例

import os
import sys

from typing import List

from alibabacloud_ice20201109.client import Client as ICE20201109Client
from alibabacloud_credentials.client import Client as CredentialClient
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_ice20201109 import models as ice20201109_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_console.client import Client as ConsoleClient
from alibabacloud_tea_util.client import Client as UtilClient


class Sample:
    def __init__(self):
        pass

    @staticmethod
    def create_client() -> ICE20201109Client:
        """
        使用凭据初始化账号Client
        @return: Client
        @throws Exception
        """
        # 工程代码建议使用更安全的无AK方式,凭据配置方式请参见:https://help.aliyun.com/document_detail/378659.html。
        credential = CredentialClient()
        config = open_api_models.Config(
            credential=credential
        )
        # Endpoint 请参考 https://api.aliyun.com/product/ICE
        config.endpoint = f'ice.us-west-1.aliyuncs.com'
        return ICE20201109Client(config)

    @staticmethod
    def main(
        args: List[str],
    ) -> None:
        client = Sample.create_client()
        describe_aiagent_instance_request = ice20201109_models.DescribeAIAgentInstanceRequest(
            instance_id='YOUR_INSTANCE_ID'
        )
        runtime = util_models.RuntimeOptions()
        try:
            resp = client.describe_aiagent_instance_with_options(describe_aiagent_instance_request, runtime)
            ConsoleClient.log(UtilClient.to_jsonstring(resp))
            ConsoleClient.log(UtilClient.to_jsonstring(resp.body.instance.call_log_url))
        except Exception as error:
            # 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
            # 错误 message
            print(error.message)
            # 诊断地址
            print(error.data.get("Recommend"))
            UtilClient.assert_as_string(error.message)

if __name__ == '__main__':
    Sample.main(sys.argv[1:])

CallLogUrl结构示例

{
    "instanceid": "b9566********************3c5eb2",
    "startTime": 1755138072.2456193,
    "agentUserId": "AGENT_USER1b7**************fac945",
    "remoteUserId": "210413545",
    "dialog": [
        {
            "id": 1,
            "begin": 4.45,
            "role": "agent",
            "type": "greeting",
            "text": "哈喽,我是阿里视频云的小云,来聊聊天吧"
        },
        {
            "id": 2,
            "begin": 5.383,
            "role": "user",
            "type": "normal",
            "text": "讲个有趣的儿童故事。"
        },
        {
            "id": 3,
            "begin": 53.951,
            "role": "agent",
            "type": "normal",
            "text": "从前,有一只叫巧巧的小狐狸,它住在一个奇妙的森林里。巧巧特别喜欢收集五彩的树叶,每片叶子都是它的宝贝。有一天,它捡到了一片魔法叶子,这片叶子每天会变出一个小惊喜。有一天是美味的蜂蜜,另一次是漂亮的彩虹雨伞,森林里的动物们都羡慕极了。\n\n巧巧决定分享这份快乐,它邀请小伙伴们一起游戏,分享魔法叶子的惊喜。从此,森林里的快乐和友情日益增长,大家一起度过了许多难忘的时光。这就是小巧和她的魔法叶子的故事,每晚听着这个故事,孩子们就会甜甜地进入梦乡。"
        },
        {
            "id": 4,
            "begin": 54.922,
            "role": "user",
            "type": "normal",
            "text": "换个故事。"
        },
        {
            "id": 5,
            "begin": 81.97,
            "role": "agent",
            "type": "normal",
            "text": "在很久很久以前,有一个叫星尘的宇宙探险家,他有一把星星做成的钥匙。每当他遇到难题,钥匙就会亮起,指引他找到解决问题的办法。他的朋友们都很爱他,因为每次冒险回来,他总是带着新奇的故事和满满的勇气。和星尘一起去探索未知的宇宙,就成了孩子们最向往的冒险。"
        },
        {
            "id": 6,
            "begin": 84.78,
            "role": "user",
            "type": "normal",
            "text": "再换个故事。"
        },
        {
            "id": 7,
            "begin": 88.561,
            "role": "user",
            "type": "normal",
            "text": "我。那个。"
        }
    ]
}

音频逐句回调

您可以通过在控制台配置聊天记录实时回调以及用户、智能体音频逐句回调。回调具体详情,请参见智能体回调

image

ARTC通话录制

您可使用实时音视频(ARTC)的云端录制功能进行录制,具体详情请参见云端录制

说明

该方法仅适用于ARTC,不适用于电话呼出、呼入。