故事生成

本文介绍如何使用故事功能。

应用场景

故事相册

故事功能可以将数据集中的照片使用AI算法按照时间或人物来生成一组照片故事集,并选取一张较好的照片作为封面。使用故事功能,您可以轻松实现故事相册功能,感受生活中的美好时刻。

前提条件

已根据使用场景为文件建立元数据索引。具体操作,请参见建立元数据索引

创建故事

调用CreateStory - 创建故事接口根据故事类型、时间范围等条件对test-project项目下,test-dataset数据集中符合要求的故事文件进行分组。

重要

任务开始执行后,任务信息只保存7天,超过7天则无法再获取。您可以通过以下几种方式及时获取任务信息:

请求示例

{
    "ProjectName": "test-project",
    "DatasetName": "test-dataset",
    "ObjectId": "id1",
    "StoryName": "name1",
    "StoryType": "PeopleMemory",
    "StorySubType": "Solo",
    "StoryStartTime": "2016-12-30T16:00:00Z",
    "StoryEndTime": "2022-12-30T16:00:00Z",
    "MinFileCount": 1,
    "UserData": "abcdef",
    "Tags": "{\"test\": \"test val1\"}",
    "MaxFileCount": 3,
}

返回示例

{
    "TaskId": "CreateStory-234047f7-07bd-48bd-b248-4bf5f445****",
    "RequestId": "80C00576-B137-083B-B8CD-BD4F1907****",
    "EventId": "108-1RG91at3VV0dCqBAripTktO****"
}

示例代码

# -*- coding: utf-8 -*-
# This file is auto-generated, don't edit it. Thanks.
import sys
import os
from typing import List

from alibabacloud_imm20200930.client import Client as imm20200930Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_imm20200930 import models as imm_20200930_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient


class Sample:
    def __init__(self):
        pass

    @staticmethod
    def create_client(
        access_key_id: str,
        access_key_secret: str,
    ) -> imm20200930Client:
        """
        使用AccessKey ID&AccessKey Secret初始化账号Client。
        @param access_key_id:
        @param access_key_secret:
        @return: Client
        @throws Exception
        """
        config = open_api_models.Config(
            access_key_id=access_key_id,
            access_key_secret=access_key_secret
        )
        # 填写访问的域名。
        config.endpoint = f'imm.cn-beijing.aliyuncs.com'
        return imm20200930Client(config)

    @staticmethod
    def main(
        args: List[str],
    ) -> None:
        # 阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
        # 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
        # 本示例通过从环境变量中读取AccessKey,来实现API访问的身份验证。如何配置环境变量,请参见https://help.aliyun.com/document_detail/2361894.html。
        imm_access_key_id = os.getenv("AccessKeyId")
        imm_access_key_secret = os.getenv("AccessKeySecret")
        # 初始化客户端。
        client = Sample.create_client(imm_access_key_id, imm_access_key_secret)
        tags = {}
        create_story_request = imm_20200930_models.CreateStoryRequest(
            # 填写如下请求参数。
            project_name='test-project',
            dataset_name='test-dataset',
            story_type='PeopleMemory',
            story_name='name1',
            object_id='id1',
            story_sub_type='Solo',
            story_start_time='2016-12-30T16:00:00Z',
            story_end_time='2022-12-30T16:00:00Z',
            max_file_count=3,
            min_file_count=1,
            user_data='abcdef',
            tags=tags
        )
        runtime = util_models.RuntimeOptions()
        try:
            # 复制代码运行请自行打印API的返回值。
            client.create_story_with_options(create_story_request, runtime)
        except Exception as error:
            # 如有需要,请打印错误信息。
            UtilClient.assert_as_string(error.message)

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

获取故事

调用GetStory - 获取故事信息接口获取test-project项目下,test-dataset数据集中指定ObjectId的分组信息。

请求示例

{
    "ProjectName": "test-project",
    "DatasetName": "test-dataset",
    "ObjectId": "id2"
}

返回示例

{
    "RequestId": "1D8F812A-205C-3708-B16C-AAF2EBB7****",
    "Story": {
        "StoryName": "name2",
        "ProjectName": "test-project",
        "ObjectId": "id2",
        "CreateTime": "2022-11-25T10:19:32.289204882+08:00",
        "StoryType": "PeopleMemory",
        "Addresses": [
            {
                "Township": "",
                "Country": "",
                "City": "",
                "District": "",
                "Province": ""
            }
        ],
        "ObjectType": "story",
        "Cover": {
            "OSSURI": "",
            "URI": "oss://test-bucket/test-object"
        },
        "OwnerId": "1023210024677934",
        "DatasetName": "test-dataset",
        "StoryEndTime": "2022-12-31T00:00:00+08:00",
        "StorySubType": "Solo",
        "UpdateTime": "2022-11-25T10:19:32.289204882+08:00",
        "StoryStartTime": "2016-12-31T00:00:00+08:00",
        "Files": [
            {
                "URI": "oss://test-bucket/test-object"
            },
            {
                "URI": "oss://test-bucket/test-object-1"
            },
            {
                "URI": "oss://test-bucket/test-object-2"
            }
        ]
    }
}

示例代码

# -*- coding: utf-8 -*-
# This file is auto-generated, don't edit it. Thanks.
import sys
import os
from typing import List

from alibabacloud_imm20200930.client import Client as imm20200930Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_imm20200930 import models as imm_20200930_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient


class Sample:
    def __init__(self):
        pass

    @staticmethod
    def create_client(
        access_key_id: str,
        access_key_secret: str,
    ) -> imm20200930Client:
        """
        使用AccessKey ID&AccessKey Secret初始化账号Client。
        @param access_key_id:
        @param access_key_secret:
        @return: Client
        @throws Exception
        """
        config = open_api_models.Config(
            access_key_id=access_key_id,
            access_key_secret=access_key_secret
        )
        # 填写访问的域名。
        config.endpoint = f'imm.cn-beijing.aliyuncs.com'
        return imm20200930Client(config)

    @staticmethod
    def main(
        args: List[str],
    ) -> None:
        # 阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
        # 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
        # 本示例通过从环境变量中读取AccessKey,来实现API访问的身份验证。如何配置环境变量,请参见https://help.aliyun.com/document_detail/2361894.html。
        imm_access_key_id = os.getenv("AccessKeyId")
        imm_access_key_secret = os.getenv("AccessKeySecret")
        # 初始化客户端。
        client = Sample.create_client(imm_access_key_id, imm_access_key_secret)
        get_story_request = imm_20200930_models.GetStoryRequest(
            # 填写如下3个参数信息。
            project_name='test-project',
            dataset_name='test-dataset',
            object_id='1D8F812A-205C-3708-B16C-AAF2EBB7****'
        )
        runtime = util_models.RuntimeOptions()
        try:
            # 复制代码运行请自行打印API的返回值。
            client.get_story_with_options(get_story_request, runtime)
        except Exception as error:
            # 如有需要,请打印错误信息。
            UtilClient.assert_as_string(error.message)

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

查询故事

调用QueryStories - 查询故事接口查询test-project项目下,test-dataset数据集中的故事分组信息。

请求示例

{
    "ProjectName": "test-project",
    "DatasetName": "test-dataset"
}

返回示例

{
    "RequestId": "434321B1-3663-02F0-9410-0CC9ADFD****",
    "NextToken": "",
    "Stories": [
        {
            "StoryName": "name2",
            "ProjectName": "test-project",
            "ObjectId": "id2",
            "CreateTime": "2022-11-25T10:19:32.289204882+08:00",
            "StoryType": "PeopleMemory",
            "Addresses": [
                {
                    "Township": "",
                    "Country": "",
                    "City": "",
                    "District": "",
                    "Province": ""
                }
            ],
            "ObjectType": "story",
            "Cover": {
                "OSSURI": "",
                "URI": "oss://test-bucket/test-object"
            },
            "OwnerId": "1023210024677934",
            "DatasetName": "test-dataset",
            "StoryEndTime": "2022-12-31T00:00:00+08:00",
            "StorySubType": "Solo",
            "UpdateTime": "2022-11-25T10:19:32.289204882+08:00",
            "StoryStartTime": "2016-12-31T00:00:00+08:00",
            "Files": [
                {
                    "URI": "oss://test-bucket/test-object"
                },
                {
                    "URI": "oss://test-bucket/test-object-1"
                },
                {
                    "URI": "oss://test-bucket/test-object-2"
                }
            ]
        }
    ]
}

示例代码

# -*- coding: utf-8 -*-
# This file is auto-generated, don't edit it. Thanks.
import sys
import os
from typing import List

from alibabacloud_imm20200930.client import Client as imm20200930Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_imm20200930 import models as imm_20200930_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient


class Sample:
    def __init__(self):
        pass

    @staticmethod
    def create_client(
        access_key_id: str,
        access_key_secret: str,
    ) -> imm20200930Client:
        """
        使用AccessKey ID&AccessKey Secret初始化账号Client。
        @param access_key_id:
        @param access_key_secret:
        @return: Client
        @throws Exception
        """
        config = open_api_models.Config(
            access_key_id=access_key_id,
            access_key_secret=access_key_secret
        )
        # 填写访问的域名。
        config.endpoint = f'imm.cn-beijing.aliyuncs.com'
        return imm20200930Client(config)

    @staticmethod
    def main(
        args: List[str],
    ) -> None:
        # 阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
        # 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
        # 本示例通过从环境变量中读取AccessKey,来实现API访问的身份验证。如何配置环境变量,请参见https://help.aliyun.com/document_detail/2361894.html。
        imm_access_key_id = os.getenv("AccessKeyId")
        imm_access_key_secret = os.getenv("AccessKeySecret")
        # 初始化客户端。
        client = Sample.create_client(imm_access_key_id, imm_access_key_secret)
        query_stories_request = imm_20200930_models.QueryStoriesRequest(
            # 填写以下2个参数。
            project_name='test-project',
            dataset_name='test-dataset'
        )
        runtime = util_models.RuntimeOptions()
        try:
            # 复制代码运行请自行打印API的返回值。
            client.query_stories_with_options(query_stories_request, runtime)
        except Exception as error:
            # 如有需要,请打印错误信息。
            UtilClient.assert_as_string(error.message)

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

添加故事文件

调用AddStoryFiles - 添加故事文件接口为test-project项目下,test-dataset数据集中指定ObjectId分组中添加故事文件。

请求示例

{
    "ProjectName": "test-project",
    "DatasetName": "test-dataset",
    "ObjectId": "id2",
    "Files": "[{\"URI\": \"oss://test-bucket/test-object-3\"}]"
}

返回示例

{
    "RequestId": "7151955F-88E0-0FE3-9A3A-A5780276****",
    "Files": [
        {
            "ErrorCode": "",
            "ErrorMessage": "",
            "URI": "oss://test-bucket/test-object-3"
        }
    ]
}

示例代码

# -*- coding: utf-8 -*-
# This file is auto-generated, don't edit it. Thanks.
import sys
import os
from typing import List

from alibabacloud_imm20200930.client import Client as imm20200930Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_imm20200930 import models as imm_20200930_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient


class Sample:
    def __init__(self):
        pass

    @staticmethod
    def create_client(
        access_key_id: str,
        access_key_secret: str,
    ) -> imm20200930Client:
        """
        使用AccessKey ID&AccessKey Secret初始化账号Client。
        @param access_key_id:
        @param access_key_secret:
        @return: Client
        @throws Exception
        """
        config = open_api_models.Config(
            access_key_id=access_key_id,
            access_key_secret=access_key_secret
        )
        # 填写访问的域名。
        config.endpoint = f'imm.cn-beijing.aliyuncs.com'
        return imm20200930Client(config)

    @staticmethod
    def main(
        args: List[str],
    ) -> None:
        # 阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
        # 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
        # 本示例通过从环境变量中读取AccessKey,来实现API访问的身份验证。如何配置环境变量,请参见https://help.aliyun.com/document_detail/2361894.html。
        imm_access_key_id = os.getenv("AccessKeyId")
        imm_access_key_secret = os.getenv("AccessKeySecret")
        # 初始化客户端。
        client = Sample.create_client(imm_access_key_id, imm_access_key_secret)
        files_0 = imm_20200930_models.AddStoryFilesRequestFiles(
            uri='oss://test-bucket/test-object-3'
        )
        add_story_files_request = imm_20200930_models.AddStoryFilesRequest(
            # 填写如下3个参数。
            project_name='test-project',
            dataset_name='test-dataset',
            object_id='id2',
            files=[
                files_0
            ]
        )
        runtime = util_models.RuntimeOptions()
        try:
            # 复制代码运行请自行打印API的返回值。
            client.add_story_files_with_options(add_story_files_request, runtime)
        except Exception as error:
            # 如有需要,请打印错误信息。
            UtilClient.assert_as_string(error.message)

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

移除故事文件

调用RemoveStoryFiles - 从故事中删除文件接口在test-project项目下,test-dataset数据集中指定ObjectId的分组中移除故事文件。

请求示例

{
    "ProjectName": "test-project",
    "DatasetName": "test-dataset",
    "ObjectId": "id2",
    "Files": "[{\"URI\": \"oss://test-bucket/test-object-2\"}]"
}

返回示例

{
    "RequestId": "C4F402BB-AA28-0CB0-8FFF-C7EC4855****"
}

示例代码

# -*- coding: utf-8 -*-
# This file is auto-generated, don't edit it. Thanks.
import sys
import os
from typing import List

from alibabacloud_imm20200930.client import Client as imm20200930Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_imm20200930 import models as imm_20200930_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient


class Sample:
    def __init__(self):
        pass

    @staticmethod
    def create_client(
        access_key_id: str,
        access_key_secret: str,
    ) -> imm20200930Client:
        """
        使用AccessKey ID&AccessKey Secret初始化账号Client。
        @param access_key_id:
        @param access_key_secret:
        @return: Client
        @throws Exception
        """
        config = open_api_models.Config(
            access_key_id=access_key_id,
            access_key_secret=access_key_secret
        )
        # 填写访问的域名。
        config.endpoint = f'imm.cn-beijing.aliyuncs.com'
        return imm20200930Client(config)

    @staticmethod
    def main(
        args: List[str],
    ) -> None:
        # 阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
        # 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
        # 本示例通过从环境变量中读取AccessKey,来实现API访问的身份验证。如何配置环境变量,请参见https://help.aliyun.com/document_detail/2361894.html。
        imm_access_key_id = os.getenv("AccessKeyId")
        imm_access_key_secret = os.getenv("AccessKeySecret")
        # 初始化客户端。
        client = Sample.create_client(imm_access_key_id, imm_access_key_secret)
        files_0 = imm_20200930_models.RemoveStoryFilesRequestFiles(
            uri='oss://test-bucket/test-object-2'
        )
        remove_story_files_request = imm_20200930_models.RemoveStoryFilesRequest(
            # 填写以下3个参数。
            project_name='test-project',
            dataset_name='test-dataset',
            object_id='id2',
            files=[
                files_0
            ]
        )
        runtime = util_models.RuntimeOptions()
        try:
            # 复制代码运行请自行打印API的返回值。
            client.remove_story_files_with_options(remove_story_files_request, runtime)
        except Exception as error:
            # 如有需要,请打印错误信息。
            UtilClient.assert_as_string(error.message)


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

更新故事

调用UpdateStory - 更新故事接口为test-project项目下,test-dataset数据集中指定分组ObjetcId附加StoryName、CustomLabels等信息。

请求示例

{
    "ProjectName": "test-project",
    "DatasetName": "test-dataset",
    "ObjectId": "id2",
    "StoryName": "new name",
    "CustomLabels": "{\"key1\": \"val1\"}",
    "Cover": null
}

返回示例

{
    "RequestId": "7DBA0367-4280-0D53-B48F-F228F1A5****"
}

示例代码

# -*- coding: utf-8 -*-
# This file is auto-generated, don't edit it. Thanks.
import sys
import os
from typing import List

from alibabacloud_imm20200930.client import Client as imm20200930Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_imm20200930 import models as imm_20200930_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient


class Sample:
    def __init__(self):
        pass

    @staticmethod
    def create_client(
        access_key_id: str,
        access_key_secret: str,
    ) -> imm20200930Client:
        """
        使用AccessKey ID&AccessKey Secret初始化账号Client。
        @param access_key_id:
        @param access_key_secret:
        @return: Client
        @throws Exception
        """
        config = open_api_models.Config(
            access_key_id=access_key_id,
            access_key_secret=access_key_secret
        )
        # 填写访问的域名。
        config.endpoint = f'imm.cn-beijing.aliyuncs.com'
        return imm20200930Client(config)

    @staticmethod
    def main(
        args: List[str],
    ) -> None:
        # 阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
        # 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
        # 本示例通过从环境变量中读取AccessKey,来实现API访问的身份验证。如何配置环境变量,请参见https://help.aliyun.com/document_detail/2361894.html。
        imm_access_key_id = os.getenv("AccessKeyId")
        imm_access_key_secret = os.getenv("AccessKeySecret")
        # 初始化客户端。
        client = Sample.create_client(imm_access_key_id, imm_access_key_secret)
        custom_labels = {}
        update_story_request = imm_20200930_models.UpdateStoryRequest(
            # 填写以下5个参数。
            project_name='test-project',
            dataset_name='test-dataset',
            object_id='id',
            story_name='new name',
            custom_labels={"key1": "val1"}
        )
        runtime = util_models.RuntimeOptions()
        try:
            # 复制代码运行请自行打印API的返回值。
            client.update_story_with_options(update_story_request, runtime)
        except Exception as error:
            # 如有需要,请打印错误信息。
            UtilClient.assert_as_string(error.message)

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

创建自定义故事

调用CreateCustomizedStory - 创建自定义故事接口为test-project项目下,test-dataset数据集创建自定义故事分组。

请求示例

{
    "ProjectName": "test-project",
    "DatasetName": "test-dataset",
    "StoryName": "name1",
    "StoryType": "PeopleMemory",
    "StorySubType": "Solo",
    "Cover": "{\"URI\": \"oss://test-bucket/test-object\"}",
    "Files": "[{\"URI\": \"oss://test-bucket/test-object-1\"}, {\"URI\": \"oss://test-bucket/test-object-2\"}, {\"URI\": \"oss://test-bucket/test-object-3\"}]",
    "CustomLabels": "{\"name\": \"test\"}"
}

返回示例

{
    "RequestId": "2400041F-9AA7-018E-9E34-CC178BA2****",
    "ObjectId": "b5b4820d-5ca5-4beb-9b52-d7428346****"
}

示例代码

# -*- coding: utf-8 -*-
# This file is auto-generated, don't edit it. Thanks.
import sys
import os
from typing import List

from alibabacloud_imm20200930.client import Client as imm20200930Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_imm20200930 import models as imm_20200930_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient


class Sample:
    def __init__(self):
        pass

    @staticmethod
    def create_client(
        access_key_id: str,
        access_key_secret: str,
    ) -> imm20200930Client:
        """
        使用AccessKey ID&AccessKey Secret初始化账号Client。
        @param access_key_id:
        @param access_key_secret:
        @return: Client
        @throws Exception
        """
        config = open_api_models.Config(
            access_key_id=access_key_id,
            access_key_secret=access_key_secret
        )
        # 填写访问的域名。
        config.endpoint = f'imm.cn-beijing.aliyuncs.com'
        return imm20200930Client(config)

    @staticmethod
    def main(
        args: List[str],
    ) -> None:
        # 阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
        # 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
        # 本示例通过从环境变量中读取AccessKey,来实现API访问的身份验证。如何配置环境变量,请参见https://help.aliyun.com/document_detail/2361894.html。
        imm_access_key_id = os.getenv("AccessKeyId")
        imm_access_key_secret = os.getenv("AccessKeySecret")
        # 初始化客户端。
        client = Sample.create_client(imm_access_key_id, imm_access_key_secret)
        custom_labels = {}
        files_0 = imm_20200930_models.CreateCustomizedStoryRequestFiles(
            uri='oss://test-bucket/test-object'
        )
        files_1 = imm_20200930_models.CreateCustomizedStoryRequestFiles(
            uri='oss://test-bucket/test-object-1'
        )
        files_2 = imm_20200930_models.CreateCustomizedStoryRequestFiles(
            uri='oss://test-bucket/test-object-2'
        )
        files_3 = imm_20200930_models.CreateCustomizedStoryRequestFiles(
            uri='oss://test-bucket/test-object-3'
        )
        cover = imm_20200930_models.CreateCustomizedStoryRequestCover(
            uri='oss://test-bucket/test-object'
        )
        create_customized_story_request = imm_20200930_models.CreateCustomizedStoryRequest(
            # 填写以下8个参数。
            project_name='test-project',
            dataset_name='test-dataset',
            story_type='PeopleMemory',
            story_sub_type='Solo',
            story_name='name1',
            cover=cover,
            files=[
                files_0, files_1, files_2, files_3
            ],
            custom_labels=custom_labels
        )
        runtime = util_models.RuntimeOptions()
        try:
            # 复制代码运行请自行打印API的返回值。
            client.create_customized_story_with_options(create_customized_story_request, runtime)
        except Exception as error:
            # 如有需要,请打印错误信息。
            UtilClient.assert_as_string(error.message)

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

删除故事

调用DeleteStory - 删除故事接口删除test-project项目下,test-dataset数据集中的指定ObjectId分组。

请求示例

{
    "ProjectName": "test-project",
    "DatasetName": "test-dataset",
    "ObjectId": "id1"
}

返回示例

{
    "RequestId": "17040B87-3176-0356-8262-C8B39ABA****"
}

示例代码

# -*- coding: utf-8 -*-
# This file is auto-generated, don't edit it. Thanks.
import sys
import os
from typing import List

from alibabacloud_imm20200930.client import Client as imm20200930Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_imm20200930 import models as imm_20200930_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient


class Sample:
    def __init__(self):
        pass

    @staticmethod
    def create_client(
        access_key_id: str,
        access_key_secret: str,
    ) -> imm20200930Client:
        """
        使用AccessKey ID&AccessKey Secret初始化账号Client。
        @param access_key_id:
        @param access_key_secret:
        @return: Client
        @throws Exception
        """
        config = open_api_models.Config(
            access_key_id=access_key_id,
            access_key_secret=access_key_secret
        )
        # 填写访问的域名。
        config.endpoint = f'imm.cn-beijing.aliyuncs.com'
        return imm20200930Client(config)

    @staticmethod
    def main(
        args: List[str],
    ) -> None:
        # 阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
        # 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
        # 本示例通过从环境变量中读取AccessKey,来实现API访问的身份验证。如何配置环境变量,请参见https://help.aliyun.com/document_detail/2361894.html。
        imm_access_key_id = os.getenv("AccessKeyId")
        imm_access_key_secret = os.getenv("AccessKeySecret")
        # 初始化客户端。
        client = Sample.create_client(imm_access_key_id, imm_access_key_secret)
        delete_story_request = imm_20200930_models.DeleteStoryRequest(
            # 填写以下3个参数。
            project_name='test-project',
            dataset_name='test-dataset',
            object_id='id1'
        )
        runtime = util_models.RuntimeOptions()
        try:
            # 复制代码运行请自行打印API的返回值。
            client.delete_story_with_options(delete_story_request, runtime)
        except Exception as error:
            # 如有需要,请打印错误信息。
            UtilClient.assert_as_string(error.message)

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