ixp
latest
false
UiPath logo, featuring letters U and I in white

Communications Mining 用户指南

上次更新日期 2025年10月20日

API 教程

这是 API 的教程式简介 - 如果您知道自己在寻找什么,请直接跳至参考资料。

所有数据(各个数据块称为消息)都被分组到不同的来源中。来源应与数据的来源相对应,例如单个邮箱或特定反馈渠道。您可以将这些数据源组合起来使用,以构建单个推理模型。因此,如果您有任何疑问,最好使用多个不同的来源,而不是使用单个整体。

数据集是来源与关联标签类别的组合。例如,一个数据集可能基于网站反馈来源构建,带有“易用性”或“可用信息”等标签,而不同的数据集可以基于各种购买后调查响应来源,并针对“打包”或“交付速度”应用完全不同的标签。

因此,在添加任何注释之前,您需要创建一个来源以放入注释。

创建源示例

重击

curl -X PUT 'https://<my_api_endpoint>/api/v1/sources/<project>/example' \
    -H "Authorization: Bearer $REINFER_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
  "source": {
    "description": "An optional long form description.",
    "title": "An Example Source"
  }
}'curl -X PUT 'https://<my_api_endpoint>/api/v1/sources/<project>/example' \
    -H "Authorization: Bearer $REINFER_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
  "source": {
    "description": "An optional long form description.",
    "title": "An Example Source"
  }
}'

节点

const request = require("request");

request.put(
  {
    url: "https://<my_api_endpoint>/api/v1/sources/<project>/example",
    headers: {
      Authorization: "Bearer " + process.env.REINFER_TOKEN,
    },
    json: true,
    body: {
      source: {
        description: "An optional long form description.",
        title: "An Example Source",
      },
    },
  },
  function (error, response, json) {
    // digest response
    console.log(JSON.stringify(json, null, 2));
  }
);const request = require("request");

request.put(
  {
    url: "https://<my_api_endpoint>/api/v1/sources/<project>/example",
    headers: {
      Authorization: "Bearer " + process.env.REINFER_TOKEN,
    },
    json: true,
    body: {
      source: {
        description: "An optional long form description.",
        title: "An Example Source",
      },
    },
  },
  function (error, response, json) {
    // digest response
    console.log(JSON.stringify(json, null, 2));
  }
);

Python

import json
import os

import requests

response = requests.put(
    "https://<my_api_endpoint>/api/v1/sources/<project>/example",
    headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
    json={
        "source": {
            "title": "An Example Source",
            "description": "An optional long form description.",
        }
    },
)

print(json.dumps(response.json(), indent=2, sort_keys=True))import json
import os

import requests

response = requests.put(
    "https://<my_api_endpoint>/api/v1/sources/<project>/example",
    headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
    json={
        "source": {
            "title": "An Example Source",
            "description": "An optional long form description.",
        }
    },
)

print(json.dumps(response.json(), indent=2, sort_keys=True))

响应

{
  "source": {
    "created_at": "2018-10-16T10:43:56.463000Z",
    "description": "An optional long form description.",
    "id": "22f0f76e82fd8867",
    "language": "en",
    "last_modified": "2018-10-16T10:43:56.463000Z",
    "name": "example",
    "owner": "<project>",
    "sensitive_properties": [],
    "should_translate": false,
    "title": "An Example Source",
    "updated_at": "2018-10-16T10:43:56.463000Z"
  },
  "status": "ok"
}{
  "source": {
    "created_at": "2018-10-16T10:43:56.463000Z",
    "description": "An optional long form description.",
    "id": "22f0f76e82fd8867",
    "language": "en",
    "last_modified": "2018-10-16T10:43:56.463000Z",
    "name": "example",
    "owner": "<project>",
    "sensitive_properties": [],
    "should_translate": false,
    "title": "An Example Source",
    "updated_at": "2018-10-16T10:43:56.463000Z"
  },
  "status": "ok"
}

要创建来源,您需要满足以下条件:

  1. 项目- 您所属的现有项目。
  2. 名称- 可以使用字母数字字符、连字符和下划线(例如“购买后”)。
  3. 标题- 用于显示在用户界面中的来源人类可读标题,例如“购买后调查回复”。
  4. 说明-(可选)要在来源“概述”页面上显示的来源的较长说明。

前两者构成来源的完全限定名称,可用于以编程方式引用来源。后两者供用户在用户界面中使用。

继续创建示例来源。

请查看您的来源页面,然后返回。

列表来源示例

让我们以编程方式检索源页面上可用的相同信息,以及所有源的所有元数据。 您应该会看到来源。

重击

curl -X GET 'https://<my_api_endpoint>/api/v1/sources' \
    -H "Authorization: Bearer $REINFER_TOKEN"curl -X GET 'https://<my_api_endpoint>/api/v1/sources' \
    -H "Authorization: Bearer $REINFER_TOKEN"

节点

const request = require("request");

request.get(
  {
    url: "https://<my_api_endpoint>/api/v1/sources",
    headers: {
      Authorization: "Bearer " + process.env.REINFER_TOKEN,
    },
  },
  function (error, response, json) {
    // digest response
    console.log(JSON.stringify(json, null, 2));
  }
);const request = require("request");

request.get(
  {
    url: "https://<my_api_endpoint>/api/v1/sources",
    headers: {
      Authorization: "Bearer " + process.env.REINFER_TOKEN,
    },
  },
  function (error, response, json) {
    // digest response
    console.log(JSON.stringify(json, null, 2));
  }
);

Python

import json
import os

import requests

response = requests.get(
    "https://<my_api_endpoint>/api/v1/sources",
    headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
)

print(json.dumps(response.json(), indent=2, sort_keys=True))import json
import os

import requests

response = requests.get(
    "https://<my_api_endpoint>/api/v1/sources",
    headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
)

print(json.dumps(response.json(), indent=2, sort_keys=True))

响应

{
  "sources": [
    {
      "created_at": "2018-10-16T10:43:56.463000Z",
      "description": "An optional long form description.",
      "id": "22f0f76e82fd8867",
      "language": "en",
      "last_modified": "2018-10-16T10:43:56.463000Z",
      "name": "example",
      "owner": "<project>",
      "sensitive_properties": [],
      "should_translate": false,
      "title": "An Example Source",
      "updated_at": "2018-10-16T10:43:56.463000Z"
    }
  ],
  "status": "ok"
}{
  "sources": [
    {
      "created_at": "2018-10-16T10:43:56.463000Z",
      "description": "An optional long form description.",
      "id": "22f0f76e82fd8867",
      "language": "en",
      "last_modified": "2018-10-16T10:43:56.463000Z",
      "name": "example",
      "owner": "<project>",
      "sensitive_properties": [],
      "should_translate": false,
      "title": "An Example Source",
      "updated_at": "2018-10-16T10:43:56.463000Z"
    }
  ],
  "status": "ok"
}

如果您只需要属于特定项目的来源,则可以将其名称添加到端点。

删除来源示例

删除来源将无法恢复地破坏所有消息以及与其关联的任何其他信息。 使用此来源的任何数据集也将丢失已添加到此来源中消息的任何标签提供的训练数据,因此应谨慎使用此端点。 也就是说,删除我们在上一节中为您的项目创建的来源应该是安全的。

重击

curl -X DELETE 'https://<my_api_endpoint>/api/v1/sources/id:22f0f76e82fd8867' \
    -H "Authorization: Bearer $REINFER_TOKEN"curl -X DELETE 'https://<my_api_endpoint>/api/v1/sources/id:22f0f76e82fd8867' \
    -H "Authorization: Bearer $REINFER_TOKEN"

节点

const request = require("request");

request.delete(
  {
    url: "https://<my_api_endpoint>/api/v1/sources/id:22f0f76e82fd8867",
    headers: {
      Authorization: "Bearer " + process.env.REINFER_TOKEN,
    },
  },
  function (error, response, json) {
    // digest response
    console.log(JSON.stringify(json, null, 2));
  }
);const request = require("request");

request.delete(
  {
    url: "https://<my_api_endpoint>/api/v1/sources/id:22f0f76e82fd8867",
    headers: {
      Authorization: "Bearer " + process.env.REINFER_TOKEN,
    },
  },
  function (error, response, json) {
    // digest response
    console.log(JSON.stringify(json, null, 2));
  }
);

Python

import json
import os

import requests

response = requests.delete(
    "https://<my_api_endpoint>/api/v1/sources/id:22f0f76e82fd8867",
    headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
)

print(json.dumps(response.json(), indent=2, sort_keys=True))import json
import os

import requests

response = requests.delete(
    "https://<my_api_endpoint>/api/v1/sources/id:22f0f76e82fd8867",
    headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
)

print(json.dumps(response.json(), indent=2, sort_keys=True))

响应

{
  "status": "ok"
}{
  "status": "ok"
}
响应应为{"status": "ok"} 。 为确保该问题已消失,您可以再次请求所有来源。

重击

curl -X GET 'https://<my_api_endpoint>/api/v1/sources' \
    -H "Authorization: Bearer $REINFER_TOKEN"curl -X GET 'https://<my_api_endpoint>/api/v1/sources' \
    -H "Authorization: Bearer $REINFER_TOKEN"

节点

const request = require("request");

request.get(
  {
    url: "https://<my_api_endpoint>/api/v1/sources",
    headers: {
      Authorization: "Bearer " + process.env.REINFER_TOKEN,
    },
  },
  function (error, response, json) {
    // digest response
    console.log(JSON.stringify(json, null, 2));
  }
);const request = require("request");

request.get(
  {
    url: "https://<my_api_endpoint>/api/v1/sources",
    headers: {
      Authorization: "Bearer " + process.env.REINFER_TOKEN,
    },
  },
  function (error, response, json) {
    // digest response
    console.log(JSON.stringify(json, null, 2));
  }
);

Python

import json
import os

import requests

response = requests.get(
    "https://<my_api_endpoint>/api/v1/sources",
    headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
)

print(json.dumps(response.json(), indent=2, sort_keys=True))import json
import os

import requests

response = requests.get(
    "https://<my_api_endpoint>/api/v1/sources",
    headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
)

print(json.dumps(response.json(), indent=2, sort_keys=True))

响应

{
  "sources": [],
  "status": "ok"
}{
  "sources": [],
  "status": "ok"
}

添加注释示例

如果来源中没有注释,那么来源将毫无用处。Communications Mining™ 中的注释可以是单个文本,也可以是组合到对话中的多个文本项目。前者的示例包括调查回复、支持工单和客户评论,而后者的示例包括电子邮件链。

我们将为上一节中创建的示例来源添加一些注释:

添加电子邮件

重击

curl -X POST 'https://<my_api_endpoint>/api/v1/sources/<project>/example/sync' \
    -H "Authorization: Bearer $REINFER_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
  "comments": [
    {
      "id": "0123456789abcdef",
      "messages": [
        {
          "body": {
            "text": "Hi Bob,\n\nCould you send me today'"'"'s figures?\n\nThanks,\nAlice"
          },
          "from": "[email protected]",
          "sent_at": "2011-12-11T11:02:03.000000+00:00",
          "to": [
            "[email protected]"
          ]
        },
        {
          "body": {
            "text": "Alice,\n\nHere are the figures for today.\n\nRegards,\nBob"
          },
          "from": "[email protected]",
          "sent_at": "2011-12-11T11:05:10.000000+00:00",
          "to": [
            "[email protected]"
          ]
        },
        {
          "body": {
            "text": "Hi Bob,\n\nI think these are the wrong numbers - could you check?\n\nThanks again,\nAlice"
          },
          "from": "[email protected]",
          "sent_at": "2011-12-11T11:18:43.000000+00:00",
          "to": [
            "[email protected]"
          ]
        }
      ],
      "timestamp": "2011-12-11T01:02:03.000000+00:00"
    },
    {
      "id": "abcdef0123456789",
      "messages": [
        {
          "body": {
            "text": "All,\n\nJust to let you know that processing is running late today.\n\nRegards,\nBob"
          },
          "from": "[email protected]",
          "sent_at": "2011-12-12T10:04:30.000000+00:00",
          "to": [
            "[email protected]",
            "[email protected]"
          ]
        },
        {
          "body": {
            "text": "Hi Bob,\n\nCould you estimate when you'"'"'ll be finished?\n\nThanks,\nCarol"
          },
          "from": "[email protected]",
          "sent_at": "2011-12-12T10:06:22.000000+00:00",
          "to": [
            "[email protected]",
            "[email protected]"
          ]
        },
        {
          "body": {
            "text": "Carol,\n\nWe should be done by 12pm. Sorry about the delay.\n\nBest,\nBob"
          },
          "from": "[email protected]",
          "sent_at": "2011-12-11T10:09:40.000000+00:00",
          "to": [
            "[email protected]",
            "[email protected]"
          ]
        }
      ],
      "timestamp": "2011-12-11T02:03:04.000000+00:00",
      "user_properties": {
        "number:severity": 3,
        "string:Recipient Domain": "company.com",
        "string:Sender Domain": "organisation.org"
      }
    }
  ]
}'curl -X POST 'https://<my_api_endpoint>/api/v1/sources/<project>/example/sync' \
    -H "Authorization: Bearer $REINFER_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
  "comments": [
    {
      "id": "0123456789abcdef",
      "messages": [
        {
          "body": {
            "text": "Hi Bob,\n\nCould you send me today'"'"'s figures?\n\nThanks,\nAlice"
          },
          "from": "[email protected]",
          "sent_at": "2011-12-11T11:02:03.000000+00:00",
          "to": [
            "[email protected]"
          ]
        },
        {
          "body": {
            "text": "Alice,\n\nHere are the figures for today.\n\nRegards,\nBob"
          },
          "from": "[email protected]",
          "sent_at": "2011-12-11T11:05:10.000000+00:00",
          "to": [
            "[email protected]"
          ]
        },
        {
          "body": {
            "text": "Hi Bob,\n\nI think these are the wrong numbers - could you check?\n\nThanks again,\nAlice"
          },
          "from": "[email protected]",
          "sent_at": "2011-12-11T11:18:43.000000+00:00",
          "to": [
            "[email protected]"
          ]
        }
      ],
      "timestamp": "2011-12-11T01:02:03.000000+00:00"
    },
    {
      "id": "abcdef0123456789",
      "messages": [
        {
          "body": {
            "text": "All,\n\nJust to let you know that processing is running late today.\n\nRegards,\nBob"
          },
          "from": "[email protected]",
          "sent_at": "2011-12-12T10:04:30.000000+00:00",
          "to": [
            "[email protected]",
            "[email protected]"
          ]
        },
        {
          "body": {
            "text": "Hi Bob,\n\nCould you estimate when you'"'"'ll be finished?\n\nThanks,\nCarol"
          },
          "from": "[email protected]",
          "sent_at": "2011-12-12T10:06:22.000000+00:00",
          "to": [
            "[email protected]",
            "[email protected]"
          ]
        },
        {
          "body": {
            "text": "Carol,\n\nWe should be done by 12pm. Sorry about the delay.\n\nBest,\nBob"
          },
          "from": "[email protected]",
          "sent_at": "2011-12-11T10:09:40.000000+00:00",
          "to": [
            "[email protected]",
            "[email protected]"
          ]
        }
      ],
      "timestamp": "2011-12-11T02:03:04.000000+00:00",
      "user_properties": {
        "number:severity": 3,
        "string:Recipient Domain": "company.com",
        "string:Sender Domain": "organisation.org"
      }
    }
  ]
}'

节点

const request = require("request");

request.post(
  {
    url: "https://<my_api_endpoint>/api/v1/sources/<project>/example/sync",
    headers: {
      Authorization: "Bearer " + process.env.REINFER_TOKEN,
    },
    json: true,
    body: {
      comments: [
        {
          id: "0123456789abcdef",
          messages: [
            {
              body: {
                text: "Hi Bob,\n\nCould you send me today's figures?\n\nThanks,\nAlice",
              },
              from: "[email protected]",
              sent_at: "2011-12-11T11:02:03.000000+00:00",
              to: ["[email protected]"],
            },
            {
              body: {
                text: "Alice,\n\nHere are the figures for today.\n\nRegards,\nBob",
              },
              from: "[email protected]",
              sent_at: "2011-12-11T11:05:10.000000+00:00",
              to: ["[email protected]"],
            },
            {
              body: {
                text: "Hi Bob,\n\nI think these are the wrong numbers - could you check?\n\nThanks again,\nAlice",
              },
              from: "[email protected]",
              sent_at: "2011-12-11T11:18:43.000000+00:00",
              to: ["[email protected]"],
            },
          ],
          timestamp: "2011-12-11T01:02:03.000000+00:00",
        },
        {
          id: "abcdef0123456789",
          messages: [
            {
              body: {
                text: "All,\n\nJust to let you know that processing is running late today.\n\nRegards,\nBob",
              },
              from: "[email protected]",
              sent_at: "2011-12-12T10:04:30.000000+00:00",
              to: ["[email protected]", "[email protected]"],
            },
            {
              body: {
                text: "Hi Bob,\n\nCould you estimate when you'll be finished?\n\nThanks,\nCarol",
              },
              from: "[email protected]",
              sent_at: "2011-12-12T10:06:22.000000+00:00",
              to: ["[email protected]", "[email protected]"],
            },
            {
              body: {
                text: "Carol,\n\nWe should be done by 12pm. Sorry about the delay.\n\nBest,\nBob",
              },
              from: "[email protected]",
              sent_at: "2011-12-11T10:09:40.000000+00:00",
              to: ["[email protected]", "[email protected]"],
            },
          ],
          timestamp: "2011-12-11T02:03:04.000000+00:00",
          user_properties: {
            "number:severity": 3,
            "string:Recipient Domain": "company.com",
            "string:Sender Domain": "organisation.org",
          },
        },
      ],
    },
  },
  function (error, response, json) {
    // digest response
    console.log(JSON.stringify(json, null, 2));
  }
);const request = require("request");

request.post(
  {
    url: "https://<my_api_endpoint>/api/v1/sources/<project>/example/sync",
    headers: {
      Authorization: "Bearer " + process.env.REINFER_TOKEN,
    },
    json: true,
    body: {
      comments: [
        {
          id: "0123456789abcdef",
          messages: [
            {
              body: {
                text: "Hi Bob,\n\nCould you send me today's figures?\n\nThanks,\nAlice",
              },
              from: "[email protected]",
              sent_at: "2011-12-11T11:02:03.000000+00:00",
              to: ["[email protected]"],
            },
            {
              body: {
                text: "Alice,\n\nHere are the figures for today.\n\nRegards,\nBob",
              },
              from: "[email protected]",
              sent_at: "2011-12-11T11:05:10.000000+00:00",
              to: ["[email protected]"],
            },
            {
              body: {
                text: "Hi Bob,\n\nI think these are the wrong numbers - could you check?\n\nThanks again,\nAlice",
              },
              from: "[email protected]",
              sent_at: "2011-12-11T11:18:43.000000+00:00",
              to: ["[email protected]"],
            },
          ],
          timestamp: "2011-12-11T01:02:03.000000+00:00",
        },
        {
          id: "abcdef0123456789",
          messages: [
            {
              body: {
                text: "All,\n\nJust to let you know that processing is running late today.\n\nRegards,\nBob",
              },
              from: "[email protected]",
              sent_at: "2011-12-12T10:04:30.000000+00:00",
              to: ["[email protected]", "[email protected]"],
            },
            {
              body: {
                text: "Hi Bob,\n\nCould you estimate when you'll be finished?\n\nThanks,\nCarol",
              },
              from: "[email protected]",
              sent_at: "2011-12-12T10:06:22.000000+00:00",
              to: ["[email protected]", "[email protected]"],
            },
            {
              body: {
                text: "Carol,\n\nWe should be done by 12pm. Sorry about the delay.\n\nBest,\nBob",
              },
              from: "[email protected]",
              sent_at: "2011-12-11T10:09:40.000000+00:00",
              to: ["[email protected]", "[email protected]"],
            },
          ],
          timestamp: "2011-12-11T02:03:04.000000+00:00",
          user_properties: {
            "number:severity": 3,
            "string:Recipient Domain": "company.com",
            "string:Sender Domain": "organisation.org",
          },
        },
      ],
    },
  },
  function (error, response, json) {
    // digest response
    console.log(JSON.stringify(json, null, 2));
  }
);

Python

import json
import os

import requests

response = requests.post(
    "https://<my_api_endpoint>/api/v1/sources/<project>/example/sync",
    headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
    json={
        "comments": [
            {
                "id": "0123456789abcdef",
                "timestamp": "2011-12-11T01:02:03.000000+00:00",
                "messages": [
                    {
                        "from": "[email protected]",
                        "to": ["[email protected]"],
                        "sent_at": "2011-12-11T11:02:03.000000+00:00",
                        "body": {
                            "text": "Hi Bob,\n\nCould you send me today's figures?\n\nThanks,\nAlice"
                        },
                    },
                    {
                        "from": "[email protected]",
                        "to": ["[email protected]"],
                        "sent_at": "2011-12-11T11:05:10.000000+00:00",
                        "body": {
                            "text": "Alice,\n\nHere are the figures for today.\n\nRegards,\nBob"
                        },
                    },
                    {
                        "from": "[email protected]",
                        "to": ["[email protected]"],
                        "sent_at": "2011-12-11T11:18:43.000000+00:00",
                        "body": {
                            "text": "Hi Bob,\n\nI think these are the wrong numbers - could you check?\n\nThanks again,\nAlice"
                        },
                    },
                ],
            },
            {
                "id": "abcdef0123456789",
                "timestamp": "2011-12-11T02:03:04.000000+00:00",
                "messages": [
                    {
                        "from": "[email protected]",
                        "to": ["[email protected]", "[email protected]"],
                        "sent_at": "2011-12-12T10:04:30.000000+00:00",
                        "body": {
                            "text": "All,\n\nJust to let you know that processing is running late today.\n\nRegards,\nBob"
                        },
                    },
                    {
                        "from": "[email protected]",
                        "to": ["[email protected]", "[email protected]"],
                        "sent_at": "2011-12-12T10:06:22.000000+00:00",
                        "body": {
                            "text": "Hi Bob,\n\nCould you estimate when you'll be finished?\n\nThanks,\nCarol"
                        },
                    },
                    {
                        "from": "[email protected]",
                        "to": ["[email protected]", "[email protected]"],
                        "sent_at": "2011-12-11T10:09:40.000000+00:00",
                        "body": {
                            "text": "Carol,\n\nWe should be done by 12pm. Sorry about the delay.\n\nBest,\nBob"
                        },
                    },
                ],
                "user_properties": {
                    "string:Sender Domain": "organisation.org",
                    "string:Recipient Domain": "company.com",
                    "number:severity": 3,
                },
            },
        ]
    },
)

print(json.dumps(response.json(), indent=2, sort_keys=True))import json
import os

import requests

response = requests.post(
    "https://<my_api_endpoint>/api/v1/sources/<project>/example/sync",
    headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
    json={
        "comments": [
            {
                "id": "0123456789abcdef",
                "timestamp": "2011-12-11T01:02:03.000000+00:00",
                "messages": [
                    {
                        "from": "[email protected]",
                        "to": ["[email protected]"],
                        "sent_at": "2011-12-11T11:02:03.000000+00:00",
                        "body": {
                            "text": "Hi Bob,\n\nCould you send me today's figures?\n\nThanks,\nAlice"
                        },
                    },
                    {
                        "from": "[email protected]",
                        "to": ["[email protected]"],
                        "sent_at": "2011-12-11T11:05:10.000000+00:00",
                        "body": {
                            "text": "Alice,\n\nHere are the figures for today.\n\nRegards,\nBob"
                        },
                    },
                    {
                        "from": "[email protected]",
                        "to": ["[email protected]"],
                        "sent_at": "2011-12-11T11:18:43.000000+00:00",
                        "body": {
                            "text": "Hi Bob,\n\nI think these are the wrong numbers - could you check?\n\nThanks again,\nAlice"
                        },
                    },
                ],
            },
            {
                "id": "abcdef0123456789",
                "timestamp": "2011-12-11T02:03:04.000000+00:00",
                "messages": [
                    {
                        "from": "[email protected]",
                        "to": ["[email protected]", "[email protected]"],
                        "sent_at": "2011-12-12T10:04:30.000000+00:00",
                        "body": {
                            "text": "All,\n\nJust to let you know that processing is running late today.\n\nRegards,\nBob"
                        },
                    },
                    {
                        "from": "[email protected]",
                        "to": ["[email protected]", "[email protected]"],
                        "sent_at": "2011-12-12T10:06:22.000000+00:00",
                        "body": {
                            "text": "Hi Bob,\n\nCould you estimate when you'll be finished?\n\nThanks,\nCarol"
                        },
                    },
                    {
                        "from": "[email protected]",
                        "to": ["[email protected]", "[email protected]"],
                        "sent_at": "2011-12-11T10:09:40.000000+00:00",
                        "body": {
                            "text": "Carol,\n\nWe should be done by 12pm. Sorry about the delay.\n\nBest,\nBob"
                        },
                    },
                ],
                "user_properties": {
                    "string:Sender Domain": "organisation.org",
                    "string:Recipient Domain": "company.com",
                    "number:severity": 3,
                },
            },
        ]
    },
)

print(json.dumps(response.json(), indent=2, sort_keys=True))

响应

nullnull

此示例显示如何添加包含多条消息的注释。 这通常用于添加电子邮件。

所附代码中请求中使用的字段应不言自明。 唯一的必填字段为idtimestampmessages.body.text 。 您可以在注释参考中了解有关可用字段的更多信息。
“ID” 字段应该是最多 256 位数字的十六进制数字,在注释之间唯一。 否则,留给 API 用户选择,从而更容易地与其他系统集成。 如果 ID 不是十六进制,则可以将其转换。 如果要额外保留原始 ID,可以将其放入用于保存任意用户定义元数据的user_properties字段中。

时间戳应以 UTC 为单位,并指的是记录注释的时间,例如,响应调查的时间,而不是当前时间。

响应应确认已创建两个新注释。

添加单消息注释

重击

curl -X POST 'https://<my_api_endpoint>/api/v1/sources/<project>/example/sync' \
    -H "Authorization: Bearer $REINFER_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
  "comments": [
    {
      "id": "fedcba098765",
      "messages": [
        {
          "body": {
            "text": "I was impressed with the speed of your service, but the price is quite high.",
            "translated_from": "J'"'"'ai \u00e9t\u00e9 impressionn\u00e9 par la rapidit\u00e9 de votre service, mais le prix est assez \u00e9lev\u00e9."
          },
          "language": "fr"
        }
      ],
      "timestamp": "2011-12-12T20:00:00.000000+00:00"
    }
  ]
}'curl -X POST 'https://<my_api_endpoint>/api/v1/sources/<project>/example/sync' \
    -H "Authorization: Bearer $REINFER_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
  "comments": [
    {
      "id": "fedcba098765",
      "messages": [
        {
          "body": {
            "text": "I was impressed with the speed of your service, but the price is quite high.",
            "translated_from": "J'"'"'ai \u00e9t\u00e9 impressionn\u00e9 par la rapidit\u00e9 de votre service, mais le prix est assez \u00e9lev\u00e9."
          },
          "language": "fr"
        }
      ],
      "timestamp": "2011-12-12T20:00:00.000000+00:00"
    }
  ]
}'

节点

const request = require("request");

request.post(
  {
    url: "https://<my_api_endpoint>/api/v1/sources/<project>/example/sync",
    headers: {
      Authorization: "Bearer " + process.env.REINFER_TOKEN,
    },
    json: true,
    body: {
      comments: [
        {
          id: "fedcba098765",
          messages: [
            {
              body: {
                text: "I was impressed with the speed of your service, but the price is quite high.",
                translated_from:
                  "J'ai \u00e9t\u00e9 impressionn\u00e9 par la rapidit\u00e9 de votre service, mais le prix est assez \u00e9lev\u00e9.",
              },
              language: "fr",
            },
          ],
          timestamp: "2011-12-12T20:00:00.000000+00:00",
        },
      ],
    },
  },
  function (error, response, json) {
    // digest response
    console.log(JSON.stringify(json, null, 2));
  }
);const request = require("request");

request.post(
  {
    url: "https://<my_api_endpoint>/api/v1/sources/<project>/example/sync",
    headers: {
      Authorization: "Bearer " + process.env.REINFER_TOKEN,
    },
    json: true,
    body: {
      comments: [
        {
          id: "fedcba098765",
          messages: [
            {
              body: {
                text: "I was impressed with the speed of your service, but the price is quite high.",
                translated_from:
                  "J'ai \u00e9t\u00e9 impressionn\u00e9 par la rapidit\u00e9 de votre service, mais le prix est assez \u00e9lev\u00e9.",
              },
              language: "fr",
            },
          ],
          timestamp: "2011-12-12T20:00:00.000000+00:00",
        },
      ],
    },
  },
  function (error, response, json) {
    // digest response
    console.log(JSON.stringify(json, null, 2));
  }
);

Python

import json
import os

import requests

response = requests.post(
    "https://<my_api_endpoint>/api/v1/sources/<project>/example/sync",
    headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
    json={
        "comments": [
            {
                "id": "fedcba098765",
                "timestamp": "2011-12-12T20:00:00.000000+00:00",
                "messages": [
                    {
                        "language": "fr",
                        "body": {
                            "text": "I was impressed with the speed of your service, but the price is quite high.",
                            "translated_from": "J'ai été impressionné par la rapidité de votre service, mais le prix est assez élevé.",
                        },
                    }
                ],
            }
        ]
    },
)

print(json.dumps(response.json(), indent=2, sort_keys=True))import json
import os

import requests

response = requests.post(
    "https://<my_api_endpoint>/api/v1/sources/<project>/example/sync",
    headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
    json={
        "comments": [
            {
                "id": "fedcba098765",
                "timestamp": "2011-12-12T20:00:00.000000+00:00",
                "messages": [
                    {
                        "language": "fr",
                        "body": {
                            "text": "I was impressed with the speed of your service, but the price is quite high.",
                            "translated_from": "J'ai été impressionné par la rapidité de votre service, mais le prix est assez élevé.",
                        },
                    }
                ],
            }
        ]
    },
)

print(json.dumps(response.json(), indent=2, sort_keys=True))

响应

{
  "new": 1,
  "status": "ok",
  "unchanged": 0,
  "updated": 0
}{
  "new": 1,
  "status": "ok",
  "unchanged": 0,
  "updated": 0
}

此示例演示如何添加包含单个消息的注释。此格式可以适合调查回复、客户评论等数据。

必填字段和可用字段与电子邮件示例中的相同,唯一的区别是“消息”字段应包含单个条目。您可以跳过不适合您的数据的电子邮件特定字段,因为这些字段不是必填项。

响应应确认已创建一个新注释。

检索注释示例

添加后,即可通过其 ID 检索注释。您应该会注意到上一部分中添加的注释。

重击

curl -X GET 'https://<my_api_endpoint>/api/v1/sources/<project>/example/comments/0123456789abcdef' \
    -H "Authorization: Bearer $REINFER_TOKEN"curl -X GET 'https://<my_api_endpoint>/api/v1/sources/<project>/example/comments/0123456789abcdef' \
    -H "Authorization: Bearer $REINFER_TOKEN"

节点

const request = require("request");

request.get(
  {
    url: "https://<my_api_endpoint>/api/v1/sources/<project>/example/comments/0123456789abcdef",
    headers: {
      Authorization: "Bearer " + process.env.REINFER_TOKEN,
    },
  },
  function (error, response, json) {
    // digest response
    console.log(JSON.stringify(json, null, 2));
  }
);const request = require("request");

request.get(
  {
    url: "https://<my_api_endpoint>/api/v1/sources/<project>/example/comments/0123456789abcdef",
    headers: {
      Authorization: "Bearer " + process.env.REINFER_TOKEN,
    },
  },
  function (error, response, json) {
    // digest response
    console.log(JSON.stringify(json, null, 2));
  }
);

Python

import json
import os

import requests

response = requests.get(
    "https://<my_api_endpoint>/api/v1/sources/<project>/example/comments/0123456789abcdef",
    headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
)

print(json.dumps(response.json(), indent=2, sort_keys=True))import json
import os

import requests

response = requests.get(
    "https://<my_api_endpoint>/api/v1/sources/<project>/example/comments/0123456789abcdef",
    headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
)

print(json.dumps(response.json(), indent=2, sort_keys=True))

响应

{
  "comment": {
    "context": "0",
    "id": "0123456789abcdef",
    "last_modified": "2018-10-16T10:51:46.247000Z",
    "messages": [
      {
        "body": {
          "text": "Hi Bob,\n\nCould you send me today's figures?\n\nThanks,\nAlice"
        },
        "from": "[email protected]",
        "sent_at": "2011-12-11T11:02:03.000000+00:00",
        "to": ["[email protected]"]
      },
      {
        "body": {
          "text": "Alice,\n\nHere are the figures for today.\n\nRegards,\nBob"
        },
        "from": "[email protected]",
        "sent_at": "2011-12-11T11:05:10.000000+00:00",
        "to": ["[email protected]"]
      },
      {
        "body": {
          "text": "Hi Bob,\n\nI think these are the wrong numbers - could you check?\n\nThanks again,\nAlice"
        },
        "from": "[email protected]",
        "sent_at": "2011-12-11T11:18:43.000000+00:00",
        "to": ["[email protected]"]
      }
    ],
    "source_id": "22f0f76e82fd8867",
    "text_format": "plain",
    "timestamp": "2011-12-11T01:02:03Z",
    "uid": "22f0f76e82fd8867.0123456789abcdef",
    "user_properties": {}
  },
  "status": "ok"
}{
  "comment": {
    "context": "0",
    "id": "0123456789abcdef",
    "last_modified": "2018-10-16T10:51:46.247000Z",
    "messages": [
      {
        "body": {
          "text": "Hi Bob,\n\nCould you send me today's figures?\n\nThanks,\nAlice"
        },
        "from": "[email protected]",
        "sent_at": "2011-12-11T11:02:03.000000+00:00",
        "to": ["[email protected]"]
      },
      {
        "body": {
          "text": "Alice,\n\nHere are the figures for today.\n\nRegards,\nBob"
        },
        "from": "[email protected]",
        "sent_at": "2011-12-11T11:05:10.000000+00:00",
        "to": ["[email protected]"]
      },
      {
        "body": {
          "text": "Hi Bob,\n\nI think these are the wrong numbers - could you check?\n\nThanks again,\nAlice"
        },
        "from": "[email protected]",
        "sent_at": "2011-12-11T11:18:43.000000+00:00",
        "to": ["[email protected]"]
      }
    ],
    "source_id": "22f0f76e82fd8867",
    "text_format": "plain",
    "timestamp": "2011-12-11T01:02:03Z",
    "uid": "22f0f76e82fd8867.0123456789abcdef",
    "user_properties": {}
  },
  "status": "ok"
}

创建数据集示例

成功将一些原始数据添加到 Communications Mining™ 后,我们现在可以开始添加数据集。数据集对应于标签的分类,以及通过将标签应用于一系列选定来源中的消息而提供的训练数据。您可以创建引用同一来源的多个数据集,而无需使用一个数据集的分类标记消息的行为会影响其他数据集或基础来源,从而允许不同的团队使用 Communications Mining 独立收集见解。

重击

curl -X PUT 'https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset' \
    -H "Authorization: Bearer $REINFER_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
  "dataset": {
    "description": "An optional long form description.",
    "source_ids": [
      "22f0f76e82fd8867"
    ],
    "title": "An Example Dataset"
  }
}'curl -X PUT 'https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset' \
    -H "Authorization: Bearer $REINFER_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
  "dataset": {
    "description": "An optional long form description.",
    "source_ids": [
      "22f0f76e82fd8867"
    ],
    "title": "An Example Dataset"
  }
}'

节点

const request = require("request");

request.put(
  {
    url: "https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset",
    headers: {
      Authorization: "Bearer " + process.env.REINFER_TOKEN,
    },
    json: true,
    body: {
      dataset: {
        description: "An optional long form description.",
        source_ids: ["22f0f76e82fd8867"],
        title: "An Example Dataset",
      },
    },
  },
  function (error, response, json) {
    // digest response
    console.log(JSON.stringify(json, null, 2));
  }
);const request = require("request");

request.put(
  {
    url: "https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset",
    headers: {
      Authorization: "Bearer " + process.env.REINFER_TOKEN,
    },
    json: true,
    body: {
      dataset: {
        description: "An optional long form description.",
        source_ids: ["22f0f76e82fd8867"],
        title: "An Example Dataset",
      },
    },
  },
  function (error, response, json) {
    // digest response
    console.log(JSON.stringify(json, null, 2));
  }
);

Python

import json
import os

import requests

response = requests.put(
    "https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset",
    headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
    json={
        "dataset": {
            "title": "An Example Dataset",
            "description": "An optional long form description.",
            "source_ids": ["22f0f76e82fd8867"],
        }
    },
)

print(json.dumps(response.json(), indent=2, sort_keys=True))import json
import os

import requests

response = requests.put(
    "https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset",
    headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
    json={
        "dataset": {
            "title": "An Example Dataset",
            "description": "An optional long form description.",
            "source_ids": ["22f0f76e82fd8867"],
        }
    },
)

print(json.dumps(response.json(), indent=2, sort_keys=True))

响应

{
  "dataset": {
    "created": "2018-10-16T10:57:44.667000Z",
    "description": "An optional long form description.",
    "has_sentiment": true,
    "id": "b2ad67f9dfd2e76b",
    "last_modified": "2018-10-16T10:57:44.667000Z",
    "limited_access": false,
    "model_family": "english",
    "name": "my-dataset",
    "owner": "<project>",
    "source_ids": ["22f0f76e82fd8867"],
    "title": "An Example Dataset"
  },
  "status": "ok"
}{
  "dataset": {
    "created": "2018-10-16T10:57:44.667000Z",
    "description": "An optional long form description.",
    "has_sentiment": true,
    "id": "b2ad67f9dfd2e76b",
    "last_modified": "2018-10-16T10:57:44.667000Z",
    "limited_access": false,
    "model_family": "english",
    "name": "my-dataset",
    "owner": "<project>",
    "source_ids": ["22f0f76e82fd8867"],
    "title": "An Example Dataset"
  },
  "status": "ok"
}

创建来源后,拥有适当权限的用户还可以在用户界面中创建数据集,这可能会更方便。

列出数据集示例

重击

curl -X GET 'https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset' \
    -H "Authorization: Bearer $REINFER_TOKEN"curl -X GET 'https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset' \
    -H "Authorization: Bearer $REINFER_TOKEN"

节点

const request = require("request");

request.get(
  {
    url: "https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset",
    headers: {
      Authorization: "Bearer " + process.env.REINFER_TOKEN,
    },
  },
  function (error, response, json) {
    // digest response
    console.log(JSON.stringify(json, null, 2));
  }
);const request = require("request");

request.get(
  {
    url: "https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset",
    headers: {
      Authorization: "Bearer " + process.env.REINFER_TOKEN,
    },
  },
  function (error, response, json) {
    // digest response
    console.log(JSON.stringify(json, null, 2));
  }
);

Python

import json
import os

import requests

response = requests.get(
    "https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset",
    headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
)

print(json.dumps(response.json(), indent=2, sort_keys=True))import json
import os

import requests

response = requests.get(
    "https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset",
    headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
)

print(json.dumps(response.json(), indent=2, sort_keys=True))

响应

{
  "dataset": {
    "created": "2018-10-16T10:57:44.667000Z",
    "description": "An optional long form description.",
    "has_sentiment": true,
    "id": "b2ad67f9dfd2e76b",
    "last_modified": "2018-10-16T10:57:44.667000Z",
    "limited_access": false,
    "model_family": "random",
    "name": "my-dataset",
    "owner": "<project>",
    "source_ids": ["22f0f76e82fd8867"],
    "title": "An Example Dataset"
  },
  "status": "ok"
}{
  "dataset": {
    "created": "2018-10-16T10:57:44.667000Z",
    "description": "An optional long form description.",
    "has_sentiment": true,
    "id": "b2ad67f9dfd2e76b",
    "last_modified": "2018-10-16T10:57:44.667000Z",
    "limited_access": false,
    "model_family": "random",
    "name": "my-dataset",
    "owner": "<project>",
    "source_ids": ["22f0f76e82fd8867"],
    "title": "An Example Dataset"
  },
  "status": "ok"
}

与源一样,数据集也有多个 GET 路由,对应于:

  • 用户有权访问的所有数据集;
  • 属于指定项目的数据集;
  • 由项目和名称指定的单个数据集。

我们提供后者的实际应用示例。

更新数据集示例

用于创建数据集的所有允许字段都可以更新,但has_sentiment除外,该字段对于给定数据集是固定的。

重击

curl -X POST 'https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset' \
    -H "Authorization: Bearer $REINFER_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
  "dataset": {
    "description": "An updated description."
  }
}'curl -X POST 'https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset' \
    -H "Authorization: Bearer $REINFER_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
  "dataset": {
    "description": "An updated description."
  }
}'

节点

const request = require("request");

request.post(
  {
    url: "https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset",
    headers: {
      Authorization: "Bearer " + process.env.REINFER_TOKEN,
    },
    json: true,
    body: { dataset: { description: "An updated description." } },
  },
  function (error, response, json) {
    // digest response
    console.log(JSON.stringify(json, null, 2));
  }
);const request = require("request");

request.post(
  {
    url: "https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset",
    headers: {
      Authorization: "Bearer " + process.env.REINFER_TOKEN,
    },
    json: true,
    body: { dataset: { description: "An updated description." } },
  },
  function (error, response, json) {
    // digest response
    console.log(JSON.stringify(json, null, 2));
  }
);

Python

import json
import os

import requests

response = requests.post(
    "https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset",
    headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
    json={"dataset": {"description": "An updated description."}},
)

print(json.dumps(response.json(), indent=2, sort_keys=True))import json
import os

import requests

response = requests.post(
    "https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset",
    headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
    json={"dataset": {"description": "An updated description."}},
)

print(json.dumps(response.json(), indent=2, sort_keys=True))

响应

{
  "dataset": {
    "created": "2018-10-16T10:57:44.667000Z",
    "description": "An updated description.",
    "has_sentiment": true,
    "id": "b2ad67f9dfd2e76b",
    "last_modified": "2018-10-16T10:57:44.667000Z",
    "limited_access": false,
    "model_family": "random",
    "name": "my-dataset",
    "owner": "<project>",
    "source_ids": ["22f0f76e82fd8867"],
    "title": "An Example Dataset"
  },
  "status": "ok"
}{
  "dataset": {
    "created": "2018-10-16T10:57:44.667000Z",
    "description": "An updated description.",
    "has_sentiment": true,
    "id": "b2ad67f9dfd2e76b",
    "last_modified": "2018-10-16T10:57:44.667000Z",
    "limited_access": false,
    "model_family": "random",
    "name": "my-dataset",
    "owner": "<project>",
    "source_ids": ["22f0f76e82fd8867"],
    "title": "An Example Dataset"
  },
  "status": "ok"
}

删除数据集示例

删除数据集将完全删除关联的分类以及已应用于其来源的所有标签。 您将无法再根据此分类获得预测,并且必须从头开始注释消息的训练流程,才能反转此操作,因此请谨慎使用。

重击

curl -X DELETE 'https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset' \
    -H "Authorization: Bearer $REINFER_TOKEN"curl -X DELETE 'https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset' \
    -H "Authorization: Bearer $REINFER_TOKEN"

节点

const request = require("request");

request.delete(
  {
    url: "https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset",
    headers: {
      Authorization: "Bearer " + process.env.REINFER_TOKEN,
    },
  },
  function (error, response, json) {
    // digest response
    console.log(JSON.stringify(json, null, 2));
  }
);const request = require("request");

request.delete(
  {
    url: "https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset",
    headers: {
      Authorization: "Bearer " + process.env.REINFER_TOKEN,
    },
  },
  function (error, response, json) {
    // digest response
    console.log(JSON.stringify(json, null, 2));
  }
);

Python

import json
import os

import requests

response = requests.delete(
    "https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset",
    headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
)

print(json.dumps(response.json(), indent=2, sort_keys=True))import json
import os

import requests

response = requests.delete(
    "https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset",
    headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
)

print(json.dumps(response.json(), indent=2, sort_keys=True))

响应

{
  "status": "ok"
}{
  "status": "ok"
}

从已固定的模型示例中获取预测

重击

curl -X POST 'https://<my_api_endpoint>/api/v1/datasets/<project>/<dataset>/labellers/<model_version>/predict' \
    -H "Authorization: Bearer $REINFER_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
  "documents": [
    {
      "messages": [
        {
          "body": {
            "text": "Hi Bob, has my trade settled yet? Thanks, Alice"
          },
          "from": "[email protected]",
          "sent_at": "2011-12-11T11:02:03.000000+00:00",
          "subject": {
            "text": "Trade Ref: 8726387 Settlement"
          },
          "to": [
            "[email protected]"
          ]
        }
      ],
      "user_properties": {
        "number:Deal Value": 12000,
        "string:City": "London"
      }
    },
    {
      "messages": [
        {
          "body": {
            "text": "All, just to let you know that processing is running late today. Regards, Bob"
          },
          "from": "[email protected]",
          "sent_at": "2011-12-12T10:04:30.000000+00:00",
          "subject": {
            "text": "Trade Processing Delay"
          },
          "to": [
            "[email protected]",
            "[email protected]"
          ]
        }
      ],
      "user_properties": {
        "number:Deal Value": 4.9,
        "string:City": "Luton"
      }
    }
  ],
  "labels": [
    {
      "name": [
        "Trade",
        "Settlement"
      ],
      "threshold": 0.8
    },
    {
      "name": [
        "Delay"
      ],
      "threshold": 0.75
    }
  ],
  "threshold": 0
}'curl -X POST 'https://<my_api_endpoint>/api/v1/datasets/<project>/<dataset>/labellers/<model_version>/predict' \
    -H "Authorization: Bearer $REINFER_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
  "documents": [
    {
      "messages": [
        {
          "body": {
            "text": "Hi Bob, has my trade settled yet? Thanks, Alice"
          },
          "from": "[email protected]",
          "sent_at": "2011-12-11T11:02:03.000000+00:00",
          "subject": {
            "text": "Trade Ref: 8726387 Settlement"
          },
          "to": [
            "[email protected]"
          ]
        }
      ],
      "user_properties": {
        "number:Deal Value": 12000,
        "string:City": "London"
      }
    },
    {
      "messages": [
        {
          "body": {
            "text": "All, just to let you know that processing is running late today. Regards, Bob"
          },
          "from": "[email protected]",
          "sent_at": "2011-12-12T10:04:30.000000+00:00",
          "subject": {
            "text": "Trade Processing Delay"
          },
          "to": [
            "[email protected]",
            "[email protected]"
          ]
        }
      ],
      "user_properties": {
        "number:Deal Value": 4.9,
        "string:City": "Luton"
      }
    }
  ],
  "labels": [
    {
      "name": [
        "Trade",
        "Settlement"
      ],
      "threshold": 0.8
    },
    {
      "name": [
        "Delay"
      ],
      "threshold": 0.75
    }
  ],
  "threshold": 0
}'

节点

const request = require("request");

request.post(
  {
    url: "https://<my_api_endpoint>/api/v1/datasets/<project>/<dataset>/labellers/<model_version>/predict",
    headers: {
      Authorization: "Bearer " + process.env.REINFER_TOKEN,
    },
    json: true,
    body: {
      documents: [
        {
          messages: [
            {
              body: { text: "Hi Bob, has my trade settled yet? Thanks, Alice" },
              from: "[email protected]",
              sent_at: "2011-12-11T11:02:03.000000+00:00",
              subject: { text: "Trade Ref: 8726387 Settlement" },
              to: ["[email protected]"],
            },
          ],
          user_properties: {
            "number:Deal Value": 12000,
            "string:City": "London",
          },
        },
        {
          messages: [
            {
              body: {
                text: "All, just to let you know that processing is running late today. Regards, Bob",
              },
              from: "[email protected]",
              sent_at: "2011-12-12T10:04:30.000000+00:00",
              subject: { text: "Trade Processing Delay" },
              to: ["[email protected]", "[email protected]"],
            },
          ],
          user_properties: { "number:Deal Value": 4.9, "string:City": "Luton" },
        },
      ],
      labels: [
        { name: ["Trade", "Settlement"], threshold: 0.8 },
        { name: ["Delay"], threshold: 0.75 },
      ],
      threshold: 0,
    },
  },
  function (error, response, json) {
    // digest response
    console.log(JSON.stringify(json, null, 2));
  }
);const request = require("request");

request.post(
  {
    url: "https://<my_api_endpoint>/api/v1/datasets/<project>/<dataset>/labellers/<model_version>/predict",
    headers: {
      Authorization: "Bearer " + process.env.REINFER_TOKEN,
    },
    json: true,
    body: {
      documents: [
        {
          messages: [
            {
              body: { text: "Hi Bob, has my trade settled yet? Thanks, Alice" },
              from: "[email protected]",
              sent_at: "2011-12-11T11:02:03.000000+00:00",
              subject: { text: "Trade Ref: 8726387 Settlement" },
              to: ["[email protected]"],
            },
          ],
          user_properties: {
            "number:Deal Value": 12000,
            "string:City": "London",
          },
        },
        {
          messages: [
            {
              body: {
                text: "All, just to let you know that processing is running late today. Regards, Bob",
              },
              from: "[email protected]",
              sent_at: "2011-12-12T10:04:30.000000+00:00",
              subject: { text: "Trade Processing Delay" },
              to: ["[email protected]", "[email protected]"],
            },
          ],
          user_properties: { "number:Deal Value": 4.9, "string:City": "Luton" },
        },
      ],
      labels: [
        { name: ["Trade", "Settlement"], threshold: 0.8 },
        { name: ["Delay"], threshold: 0.75 },
      ],
      threshold: 0,
    },
  },
  function (error, response, json) {
    // digest response
    console.log(JSON.stringify(json, null, 2));
  }
);

Python

import json
import os

import requests

response = requests.post(
    "https://<my_api_endpoint>/api/v1/datasets/<project>/<dataset>/labellers/<model_version>/predict",
    headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
    json={
        "documents": [
            {
                "messages": [
                    {
                        "body": {
                            "text": "Hi Bob, has my trade settled yet? Thanks, Alice"
                        },
                        "subject": {"text": "Trade Ref: 8726387 Settlement"},
                        "from": "[email protected]",
                        "sent_at": "2011-12-11T11:02:03.000000+00:00",
                        "to": ["[email protected]"],
                    }
                ],
                "user_properties": {
                    "number:Deal Value": 12000,
                    "string:City": "London",
                },
            },
            {
                "messages": [
                    {
                        "body": {
                            "text": "All, just to let you know that processing is running late today. Regards, Bob"
                        },
                        "subject": {"text": "Trade Processing Delay"},
                        "from": "[email protected]",
                        "sent_at": "2011-12-12T10:04:30.000000+00:00",
                        "to": ["[email protected]", "[email protected]"],
                    }
                ],
                "user_properties": {
                    "number:Deal Value": 4.9,
                    "string:City": "Luton",
                },
            },
        ],
        "labels": [
            {"name": ["Trade", "Settlement"], "threshold": 0.8},
            {"name": ["Delay"], "threshold": 0.75},
        ],
        "threshold": 0,
    },
)

print(json.dumps(response.json(), indent=2, sort_keys=True))import json
import os

import requests

response = requests.post(
    "https://<my_api_endpoint>/api/v1/datasets/<project>/<dataset>/labellers/<model_version>/predict",
    headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
    json={
        "documents": [
            {
                "messages": [
                    {
                        "body": {
                            "text": "Hi Bob, has my trade settled yet? Thanks, Alice"
                        },
                        "subject": {"text": "Trade Ref: 8726387 Settlement"},
                        "from": "[email protected]",
                        "sent_at": "2011-12-11T11:02:03.000000+00:00",
                        "to": ["[email protected]"],
                    }
                ],
                "user_properties": {
                    "number:Deal Value": 12000,
                    "string:City": "London",
                },
            },
            {
                "messages": [
                    {
                        "body": {
                            "text": "All, just to let you know that processing is running late today. Regards, Bob"
                        },
                        "subject": {"text": "Trade Processing Delay"},
                        "from": "[email protected]",
                        "sent_at": "2011-12-12T10:04:30.000000+00:00",
                        "to": ["[email protected]", "[email protected]"],
                    }
                ],
                "user_properties": {
                    "number:Deal Value": 4.9,
                    "string:City": "Luton",
                },
            },
        ],
        "labels": [
            {"name": ["Trade", "Settlement"], "threshold": 0.8},
            {"name": ["Delay"], "threshold": 0.75},
        ],
        "threshold": 0,
    },
)

print(json.dumps(response.json(), indent=2, sort_keys=True))

响应

{
  "entities": [
    [
      {
        "formatted_value": "2019-01-01 00:00 UTC",
        "kind": "date",
        "span": {
          "content_part": "body",
          "message_index": 0,
          "utf16_byte_end": 120,
          "utf16_byte_start": 94
        }
      },
      {
        "formatted_value": "Bob",
        "kind": "person",
        "span": {
          "content_part": "body",
          "message_index": 0,
          "utf16_byte_end": 6,
          "utf16_byte_start": 12
        }
      }
    ],
    []
  ],
  "model": {
    "time": "2018-12-20T15:05:43.906000Z",
    "version": "1"
  },
  "predictions": [
    [
      {
        "name": ["Trade", "Settlement"],
        "probability": 0.8668700814247131
      }
    ],
    [
      {
        "name": ["Delay"],
        "probability": 0.26687008142471313
      }
    ]
  ],
  "status": "ok"
}{
  "entities": [
    [
      {
        "formatted_value": "2019-01-01 00:00 UTC",
        "kind": "date",
        "span": {
          "content_part": "body",
          "message_index": 0,
          "utf16_byte_end": 120,
          "utf16_byte_start": 94
        }
      },
      {
        "formatted_value": "Bob",
        "kind": "person",
        "span": {
          "content_part": "body",
          "message_index": 0,
          "utf16_byte_end": 6,
          "utf16_byte_start": 12
        }
      }
    ],
    []
  ],
  "model": {
    "time": "2018-12-20T15:05:43.906000Z",
    "version": "1"
  },
  "predictions": [
    [
      {
        "name": ["Trade", "Settlement"],
        "probability": 0.8668700814247131
      }
    ],
    [
      {
        "name": ["Delay"],
        "probability": 0.26687008142471313
      }
    ]
  ],
  "status": "ok"
}

拥有经过训练的模型后,您现在可以使用此模型根据其他数据片段预测标签。 为此,您只需提供以下内容:

  1. 文档- 模型将为其预测标签的消息数据数组,每个消息对象只能包含一个消息以及任何可选属性。为了获得最佳模型性能,用户提供的数据需要与平台上批注的数据和格式保持一致,因为模型会考虑所有可用的数据和元数据。例如,电子邮件应包含“主题”、“发件人”、“密送”、“抄送” 字段等(前提是训练数据中存在这些字段)。此外,训练数据集中的用户属性也应包含在 API 请求正文中。
  2. 标签- 您希望模型在提供的数据中预测的经过模型训练的标签数组。此外,应为每个标签提供一个置信度阈值,作为筛选标签的依据。可以根据您的精度与召回率的权衡来确定最佳阈值。有关如何选择阈值的详细信息,请参阅用户指南的 “使用验证”部分下的。
  3. 默认阈值(可选) - 将应用于提供的所有标签的默认阈值。请注意,如果在请求中一起提供默认阈值和每个标签的阈值,则每个标签的阈值将覆盖默认阈值。作为最佳实践,默认阈值可用于测试或探索数据。为了在使用预测进行自动化决策时获得最佳结果,强烈建议使用基于标签的阈值。
注意:层次结构标签将被格式化为标签列表。 例如,标签“Trace > Settlements”在请求中的格式为 ["Trace", "Settlements"]。

在 API URL 中,传递以下参数非常重要:

  1. 项目名称- 您所属的现有项目。
  2. “数据集名称” - 用于训练模型的数据集。
  3. 模型版本- 模型版本是一个数字,可以在所选数据集的“模型”页面上找到。

了解响应

由于正在使用特定的模型版本,因此即使正在进一步训练模型,对同一请求的响应将始终返回相同的结果。 验证新模型的结果后,并希望提交针对新模型的请求,则应更新请求中的模型版本。 此外,您还应更新标签阈值以适应新模型。 对于每个新模型,您必须再次遍历这些步骤。

默认情况下,响应将始终为置信度高于提供的阈值级别的每条消息提供预测标签列表。

但是,如果为模型启用了实体识别和情感,则请求的响应可能会有所不同:

  1. 已启用通用字段- 响应还将提供已为每个标签识别的通用字段列表(第一个响应示例)
  2. “已启用情感”- 此响应还将为分类高于置信度阈值的每个标签对象提供介于 -1(完全消极)和 1(完全积极)之间的情感分数。(第二个响应示例)
{
  "model": { "time": "2018-12-20T15:05:43.906000Z", "version": "1" },
  "predictions": [
    [
      {
        "name": ["Trade", "Settlement"],
        "probability": 0.86687008142471313,
        "sentiment": 0.8762539502232571
      }
    ],
    [
      {
        "name": ["Delay"],
        "probability": 0.26687008142471313,
        "sentiment": 0.8762539502232571
      }
    ]
  ],
  "status": "ok"
}{
  "model": { "time": "2018-12-20T15:05:43.906000Z", "version": "1" },
  "predictions": [
    [
      {
        "name": ["Trade", "Settlement"],
        "probability": 0.86687008142471313,
        "sentiment": 0.8762539502232571
      }
    ],
    [
      {
        "name": ["Delay"],
        "probability": 0.26687008142471313,
        "sentiment": 0.8762539502232571
      }
    ]
  ],
  "status": "ok"
}

此页面有帮助吗?

获取您需要的帮助
了解 RPA - 自动化课程
UiPath Community 论坛
Uipath Logo
信任与安全
© 2005-2025 UiPath。保留所有权利。