阿里云-大模型
大约 2 分钟
阿里云-大模型
https://bailian.console.aliyun.com/#/home
阿里通义千问大模型-api调用 https://www.cnblogs.com/npe/p/18068334
通义万相
文字生成图像
1. http的方式调用
需要调用2个接口
- 作业提交接口调用
- 结果获取接口(有上面的请求中拿到task_id,然后调用第二个接口)
作业提交接口调用
const fetch = require('node-fetch');
let url = 'https://dashscope.aliyuncs.com/api/v1/services/aigc/text2image/image-synthesis';
let options = {
method: 'POST',
headers: {
Authorization: 'sk-xxx', // 替换为自己的 api-key
'Content-Type': 'application/json',
'X-DashScope-Async': 'enable',
'content-type': 'application/json'
},
body: '{"model":"wanx-v1","input":{"prompt":"一只奔跑的猫"},"parameters":{"style":"<sketch>","size":"1024*1024","n":4,"seed":42,"strength":0.5,"ref_mode":"repaint"}}'
};
fetch(url, options)
.then(res => res.json())
.then(json => console.log(json))
.catch(err => console.error('error:' + err));
结果获取接口
GET https://dashscope.aliyuncs.com/api/v1/tasks/{task_id}
入参描述
| 传参方式 | 字段 | 类型 | 必选 | 描述 | 示例值 |
|---|---|---|---|---|---|
| Url Path | task_id | String | 是 | 需要查询作业的 task_id | 13b1848b-5493-4c0e-8c44-68d038b492af |
| Header | Authorization | String | 是 | API-Key,例如:sk d1**2a | sk d1**2a |
出参描述
| 字段 | 类型 | 描述 | 示例值 |
|---|---|---|---|
| output.task_id | String | 本次请求的异步任务的作业 id,实际作业结果需要通过异步任务查询接口获取。 | 13b1848b-5493-4c0e-8c44-68d038b492af |
| output.task_status | String | 被查询作业的作业状态 | 任务状态:PENDING 排队中RUNNING 处理中SUCCEEDED 成功FAILED 失败UNKNOWN 作业不存在或状态未知 |
| usage.task_metrics | Object | 作业中每个batch任务的状态:TOTAL:总batch数目SUCCEEDED:已经成功的batch数目FAILED:已经失败的batch数目 | "task_metrics": |
| usage.image_count | Integer | 本次请求成功生成的图片张数 | 2 |
| request_id | String | 本次请求的系统唯一码 | 7574ee8f-38a3-4b1e-9280-11c33ab46e51 |
const FormData = require('form-data');
const fetch = require('node-fetch');
const formData = new FormData();
let url = 'https://dashscope.aliyuncs.com/api/v1/tasks/{task_id}';
let options = {
method: 'GET',
headers: {
Authorization: 'sk-xxx', // 替换为自己的 api-key
'content-type': 'multipart/form-data; boundary=---011000010111000001101001'
}
};
options.body = formData;
fetch(url, options)
.then(res => res.json())
.then(json => console.log(json))
.catch(err => console.error('error:' + err));
生成的图片的时效
调用通义万相-基础文生图API生成的图片URL有效时长为30分钟 如果您通过SDK生成URL,则有效期为1天 请注意在有效期内及时使用这些链接。