1. 参数
1.1 入参
一级参数
参数 | 类型 | 是否必传 | 说明 |
algorithm | string | 是 | 标识符 |
model | string | 否 | 模型版本,默认不传。可选择 dashscope-conv-rewrite-1.8b dashscope-conv-rewrite-14b |
input | map<string, object> | 是 | 输入参数 |
parameters | map<string, object> | 否 | 配置参数 |
debug | boolean | 否 | 调试模式,默认false |
二级参数
二级参数 | 类型 | 是否必传 | 说明 |
input.query | string | 是 | 当前轮输入内容 |
input.history | array(map/dict/json) | 否 | 历史对话记录
[ {"role": "user", "content": "user_content"}, {"role": "assistant", "content": "assistant_content"} ] |
{
"algorithm": "conversation_rewriter",
"model": "dashscope-conv-rewrite-14b",
"input": {
"query": "贵吗",
"history": [
{
"role": "user",
"content": "什么是黑梓木"
},
{
"role": "assistant",
"content": "黑梓木是一种用材最广的木头,在我国东北地区也称之为臭梧桐,分布比较广泛,产量也大,很多装饰部件都会用黑梓木制作。"
}
]
}
}
1.2 出参
一级参数
参数 | 类型 | 说明 |
requestId | string | 请求id |
status | int | 请求结果状态 |
message | string | 响应信息 |
data | map<string, object> | 多轮改写结果 |
debugInfo | map<string, object> | 调试信息 |
二级参数
二级参数 | 类型 | 说明 |
data.conversationRewriter | array(string) | 多轮改写后的query list |
data.timeCost | float | 服务时间消耗,单位ms |
data.inputTokens | int | 输入token数 |
data.outputTokens | int | 输出token数 |
{
"requestId": null,
"data": {
"conversationRewriter": [
"黑梓木的价格贵吗"
],
"outputTokens": 8,
"timeCost": 424.08,
"inputTokens": 61
},
"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);
PostISConvRewriterRequest request = new PostISConvRewriterRequest();
request.setAlgorithm("conversation_rewriter");
String input = "{\n" +
" \"query\": \"贵吗\",\n" +
" \"history\": [\n" +
" {\n" +
" \"role\": \"user\",\n" +
" \"content\": \"什么是黑梓木\"\n" +
" },\n" +
" {\n" +
" \"role\": \"assistant\",\n" +
" \"content\": \"黑梓木是一种用材最广的木头,在我国东北地区也称之为臭梧桐,分布比较广泛,产量也大,很多装饰部件都会用黑梓木制作。\"\n" +
" }\n" +
" ]\n" +
"}";
Map<String, Object> inputMap = JSONObject.parseObject(input, Map.class);
request.setInput(inputMap);
PostISConvRewriterResponse response = client.postISConvRewriter(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 conversation_rewriter():
config = api_models.Config(
access_key_id='xxx',
access_key_secret='xxx',
region_id="cn-beijing")
nlp_client = client.Client(config)
request = models.PostISConvRewriterRequest()
input_str = '{\n' + \
' \"query\": \"贵吗\",\n' + \
' \"history\": [\n' + \
' {\n' + \
' \"role\": \"user\",\n' + \
' \"content\": \"什么是黑梓木\"\n' + \
' },\n' + \
' {\n' + \
' \"role\": \"assistant\",\n' + \
' \"content\": \"黑梓木是一种用材最广的木头,在我国东北地区也称之为臭梧桐,分布比较广泛,产量也大,很多装饰部件都会用黑梓木制作。\"\n' + \
' }\n' + \
' ]\n' + \
'}'
request.input = json.loads(input_str)
request.algorithm = 'conversation_rewriter'
response = nlp_client.post_isconv_rewriter(request)
print(json.dumps(response.body.data, ensure_ascii=False))
if __name__ == '__main__':
conversation_rewriter()
文档内容是否对您有帮助?