文档

搜索判定API

更新时间:

1. 参数

1.1 入参

一级参数

参数

类型

是否必传

说明

algorithm

string

标识符

model

string

模型版本,默认不传

input

map<string, object>

输入参数

parameters

map<string, object>

配置参数

debug

boolean

调试模式,默认false

二级参数

二级参数

类型

是否必传

说明

input.query

string

搜索判定内容

{
    "algorithm": "retrieve_router",
    "model": "",
    "input": {
        "query": "你好"
    }
}

1.2 出参

一级参数

参数

类型

说明

requestId

string

请求id

status

int

请求结果状态

message

string

响应信息

data

map<string, object>

搜索判定结果

debugInfo

map<string, object>

调试信息

二级参数

二级参数

类型

说明

data.retrieveRouter

boolean

搜索判定的结果:

  • true:需要搜索

  • false:不需要搜索

data.timeCost

float

服务时间消耗,单位ms

data.inputTokens

int

输入token数

data.outputTokens

int

输出token数

{
    "data": {
        "retrieveRouter": false,
        "outputTokens": 1,
        "timeCost": 36.9,
        "inputTokens": 4
    },
    "requestId": null,
    "debugInfo": null,
    "message": null,
    "status": 0
}

2. SDK调用

2.1 Java SDK

2.1.1 Maven依赖

<dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>alinlp20200629</artifactId>
    <version>3.0.0</version>
</dependency>

<!--出现java.lang.NoSuchMethodError: com.aliyun.credentials.Client.getCredential()Lcom/aliyun/credentials/models/CredentialModel;异常则引入-->
<dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>credentials-java</artifactId>
    <version>0.3.0</version>
</dependency>

2.1.2 调用示例

 * 使用AK&SK初始化账号Client
 * @param accessKeyId
 * @param accessKeySecret
 * @return Client
 * @throws Exception
 */
public static Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
    Config config = new Config()
    // 必填,您的 AccessKey ID
    .setAccessKeyId(accessKeyId)
    // 必填,您的 AccessKey Secret
    .setAccessKeySecret(accessKeySecret);
    // Endpoint 请参考 https://api.aliyun.com/product/alinlp
    config.endpoint = "alinlp.cn-beijing.aliyuncs.com";
    return new Client(config);
}

public static void main(String[] args) throws Exception {
    String accessKeyId = "xxx";
    String accessKeySecret = "xxx";
    Client client = createClient(accessKeyId, accessKeySecret);
		PostISRetrieveRouterRequest request = new PostISRetrieveRouterRequest();
		request.setAlgorithm("retrieve_router");
		String input = "{\"query\": \"你好\"}";
		Map<String, Object> inputMap = JSONObject.parseObject(input, Map.class);
    request.setInput(inputMap);
    PostISRetrieveRouterResponse response = client.postISRetrieveRouter(request);
    System.out.println(JSONObject.toJSONString(response.getBody()));
}

2.2 Python SDK

2.2.1 pip源

pip install alibabacloud-alinlp20200629==3.0.0

2.2.2 调用示例

import json

from alibabacloud_alinlp20200629 import client
from alibabacloud_tea_openapi import models as api_models
from alibabacloud_alinlp20200629 import models


def retrieve_router():
    config = api_models.Config(
        access_key_id='xxx',
        access_key_secret='xxx',
        region_id="cn-beijing")
    nlp_client = client.Client(config)
    request = models.PostISRetrieveRouterRequest()
    input_str = '{\"query\": \"你好\"}'
    request.input = json.loads(input_str)
    request.algorithm = 'retrieve_router'
    response = nlp_client.post_isretrieve_router(request)
    print(json.dumps(response.body.data, ensure_ascii=False))


if __name__ == '__main__':
    retrieve_router()

  • 本页导读 (0)