跳转至

意图识别 API

请参阅 快速上手指南 获取您的 API 密钥。

$YOUR_API_KEY 替换为你实际生成的 API 密钥。
本平台基于 API 密钥进行数据隔离,即使是同一用户账户下,不同的 API 密钥所访问的数据也是彼此独立、互不共享的。


接口概览

方法 路由 功能描述 API 接口地址
POST /v1/intent/recog 用户意图识别 https://api-platform.ope.ai/v1/intent/recog
POST /v1/intent/update 批量更新意图 https://api-platform.ope.ai/v1/intent/update
DELETE /v1/intent 批量删除意图节点 https://api-platform.ope.ai/v1/intent

用户意图识别

POST /v1/intent/recog

curl --location --request POST 'https://api-platform.ope.ai/v1/intent/recog' \
  --header 'Authorization: Bearer $YOUR_API_KEY' \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "model": "opeai/JointId-v1",
    "node_id": "1",
    "intent_type": "single",
    "answer": "我是老师"
  }'
import requests

url = 'https://api-platform.ope.ai/v1/intent/recog'
headers = {
    'Authorization': 'Bearer $YOUR_API_KEY',
    'Content-Type': 'application/json',
}

payload = {
    'model': 'opeai/JointId-v1',
    'node_id': '1',
    'intent_type': 'single',
    'answer': '我是老师',
}

response = requests.post(url, headers=headers, json=payload)
print(response.json())

请求参数

名称 位置 类型 必填 说明
Authorization header string API 访问密钥(格式:Bearer YOUR_API_KEY
Content-Type header string 固定值:application/json
model body string 使用的模型名称,例如:opeai/JointId-v1
node_id body string 当前识别节点的唯一 ID
intent_id body string 用于多轮识别的上轮意图 ID(当 intent_type=multi 时必填)
intent_type body string 识别类型:single(单轮)或 multi(多轮)
answer body string 用户输入文本

多轮识别时必须传入 intent_id

返回示例

{
  "code": 1,
  "msg": "",
  "data": {
    "intent": "重复",
    "intent_id": "123123123"
  },
  "success": true,
  "message": ""
}

返回数据结构

字段 类型 说明
code integer 1 表示成功,其它表示失败
msg string 错误信息(如有)
data object 包含识别出的意图信息
intent string 意图名称(若为空字符串需注意处理)
intent_id string 当前使用或生成的意图 ID
success boolean 忽略
message string 忽略

POST 批量更新(无则新增)

POST /v1/intent/update

请求示例:

[
  {
    "node_id": "node_1000",
    "question": "好的,请问阁下的职业是?",
    "intent": [
      {
        "name": "职业符合",
        "example": [
          "学生", "无业", "老师", "办公室", "IT互联网", "低风险职业"
        ],
        "relation": 1
      },
      {
        "name": "职业不符合",
        "example": [
          "军人", "高危职业", "矿工", "司机", "消防员"
        ],
        "relation": 1
      },
      {
        "name": "AI 无法响应处理",
        "example": [
          "ai 无法响应处理"
        ]
      }
    ]
  }
]

为了提升识别准确率,强烈建议每个意图节点至少包含一个兜底意图,例如:

{
  "name": "AI 无法响应处理",
  "example": [
    "ai 无法响应处理"
  ]
}

请求参数

名称 位置 类型 必填 说明
Authorization header string API 访问密钥
Content-Type header string 固定值:application/json
body body array[object] 包含意图配置的数组

intent 项字段说明

字段 类型 说明
name string 意图名称
example array[string] 该意图下的用户表达示例
relation integer 意图关联关系分组(一般为 1)

返回示例

{
  "code": 1,
  "msg": "",
  "data": {},
  "success": true,
  "message": ""
}

返回数据结构

字段 类型 说明
code integer 1 表示成功,其它为失败
msg string 错误信息(如有)
data object 通常为空对象 {}
success boolean 忽略
message string 忽略

DELETE 批量删除意图节点

DELETE /v1/intent

请求示例:

{
  "node_ids": ["node_1000", "node_1001"]
}

请求参数

名称 位置 类型 必填 说明
Authorization header string API 访问密钥(格式:Bearer YOUR_API_KEY
Content-Type header string 固定值:application/json
body body object 请求体对象
node_ids body array[string] 要删除的节点 ID 数组,例如:["node_1000", "node_1001"]

返回示例

{
  "code": 1,
  "msg": "",
  "data": {},
  "success": true,
  "message": ""
}

返回数据结构

字段 类型 说明
code integer 1 表示成功,其它为失败
msg string 错误信息(如有)
data object 通常为空对象 {}
success boolean 忽略
message string 忽略