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()
文檔內容是否對您有幫助?