使用SD生图服务
更新时间:
前提条件
已开通智作工坊公有云服务
快速测试
操作步骤
步骤一:创建应用并查看应用详情
控制台进入应用管理,点击创建应用,填写应用信息
选择创建的应用,点击查看详情
步骤二:获取WebUI访问地址
点击生成测试链接,选择默认角色,点击立即生成,浏览器前往 WebUI 访问地址,开启创作
SDK调用
操作步骤
步骤一:创建应用并获取服务AK和SK
控制台进入应用管理,点击创建应用,填写应用信息
选择创建的应用,点击查看详情,查看应用AK和SK
步骤二:接入SDK
语言 | 文档 |
java | |
python | |
node.js |
步骤三:分配Token(以Java接入为例)
package com.example.demo;
import com.alibaba.cloudapi.sdk.model.ApiResponse;
import com.alibaba.cloudapi.sdk.model.HttpClientBuilderParams;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import java.util.Map;
public class Demo {
public static void main(String[] args) throws Exception {
String endpoint = "openai.edu-aliyun.com";
HttpClientBuilderParams httpsParam = new HttpClientBuilderParams();
httpsParam.setHost(endpoint);
httpsParam.setAppKey("应用AK");
httpsParam.setAppSecret("应用SK");
httpsParam.setReadTimeout(300000L);
HttpsApiClient.instance.init(httpsParam);
// token api path
String apiPath = "/scc/allocate_token";
ApiResponse apiResponse = HttpsApiClient.instance.invoke(apiPath, null);
System.out.println("Result Code:" + apiResponse.getCode());
System.out.println("Message:" + apiResponse.getMessage());
// get api token
JSONObject body = JSON.parseObject(new String(apiResponse.getBody()));
System.out.println("Token:" + ((Map<String, Object>) body.get("data")).get("apiToken"));
}
}
步骤四:Token分配Session获取WebUI访问地址(以Java接入为例)
package com.example.demo;
import com.alibaba.cloudapi.sdk.model.ApiResponse;
import com.alibaba.cloudapi.sdk.model.HttpClientBuilderParams;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import java.util.HashMap;
import java.util.Map;
public class Demo {
public static void main(String[] args) throws Exception {
String endpoint = "openai.edu-aliyun.com";
HttpClientBuilderParams httpsParam = new HttpClientBuilderParams();
httpsParam.setHost(endpoint);
httpsParam.setAppKey("应用AK");
httpsParam.setAppSecret("应用SK");
httpsParam.setReadTimeout(300000L);
HttpsApiClient.instance.init(httpsParam);
// token api path
String apiPath = "/scc/spRefreshOrCreateSession";
Map<String, Object> params = new HashMap<>();
params.put("apiToken", "分配的Token");
ApiResponse apiResponse = HttpsApiClient.instance.invoke(apiPath, params);
System.out.println("Result Code:" + apiResponse.getCode());
System.out.println("Message:" + apiResponse.getMessage());
// get api token
JSONObject body = JSON.parseObject(new String(apiResponse.getBody()));
System.out.println("SD WebUI Url:" + ((Map<String, Object>) body.get("data")).get("sessionUrl"));
}
}
浏览器前往 WebUI 访问地址,开启创作
文档内容是否对您有帮助?