使用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 訪問地址,開啟創作
文檔內容是否對您有幫助?