阿里云-大模型

lishihuan大约 2 分钟

阿里云-大模型

https://bailian.console.aliyun.com/#/homeopen in new window

阿里通义千问大模型-api调用 https://www.cnblogs.com/npe/p/18068334open in new window

通义万相

文字生成图像

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}open in new window

入参描述

传参方式字段类型必选描述示例值
Url Pathtask_idString需要查询作业的 task_id13b1848b-5493-4c0e-8c44-68d038b492af
HeaderAuthorizationStringAPI-Key,例如:sk d1**2ask d1**2a

出参描述

字段类型描述示例值
output.task_idString本次请求的异步任务的作业 id,实际作业结果需要通过异步任务查询接口获取。13b1848b-5493-4c0e-8c44-68d038b492af
output.task_statusString被查询作业的作业状态任务状态:PENDING 排队中RUNNING 处理中SUCCEEDED 成功FAILED 失败UNKNOWN 作业不存在或状态未知
usage.task_metricsObject作业中每个batch任务的状态:TOTAL:总batch数目SUCCEEDED:已经成功的batch数目FAILED:已经失败的batch数目"task_metrics":
usage.image_countInteger本次请求成功生成的图片张数2
request_idString本次请求的系统唯一码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天 请注意在有效期内及时使用这些链接。