main
HuangHai 2 months ago
parent 62f9749254
commit e6b36b3c57

@ -297,70 +297,7 @@ public class LiblibTextToImage {
return responseJson.getJSONObject("data");
}
/**
*
* @param generateUuid UUID
* @return
* @throws IOException
*/
public static JSONObject queryGenerateStatus(String generateUuid) throws IOException {
// 创建OkHttpClient
OkHttpClient client = createHttpClient();
// 构建请求体
JSONObject requestBody = new JSONObject();
requestBody.put("generateUuid", generateUuid);
// 获取API路径
String uri = "/api/generate/webui/status";
// 生成签名信息
SignUtil.SignatureInfo signInfo = SignUtil.makeSign(uri, secretKey);
// 构建带签名的URL
HttpUrl.Builder urlBuilder = HttpUrl.parse(QUERY_STATUS_URL).newBuilder()
.addQueryParameter("AccessKey", accessKey)
.addQueryParameter("Signature", signInfo.getSignature())
.addQueryParameter("Timestamp", String.valueOf(signInfo.getTimestamp()))
.addQueryParameter("SignatureNonce", signInfo.getSignatureNonce());
// 创建请求
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, requestBody.toJSONString());
Request request = new Request.Builder()
.url(urlBuilder.build())
.method("POST", body)
.addHeader("Content-Type", "application/json")
.build();
// 执行请求
log.info("查询生图状态: {}", requestBody.toJSONString());
Response response = client.newCall(request).execute();
// 处理响应
if (!response.isSuccessful()) {
String errorMsg = "查询生图状态失败,状态码: " + response.code();
log.error(errorMsg);
throw new IOException(errorMsg);
}
// 解析响应
String responseBody = response.body().string();
log.info("查询生图状态响应: {}", responseBody);
JSONObject responseJson = JSON.parseObject(responseBody);
int code = responseJson.getIntValue("code");
if (code != 0) {
String errorMsg = "查询生图状态失败,错误码: " + code + ", 错误信息: " + responseJson.getString("msg");
log.error(errorMsg);
throw new IOException(errorMsg);
}
return responseJson.getJSONObject("data");
}
/**
*
* @param imageUrl URL

@ -0,0 +1,140 @@
package com.dsideal.aiSupport.Util.Liblib;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.dsideal.aiSupport.Plugin.YamlProp;
import com.jfinal.kit.Prop;
import okhttp3.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import static com.dsideal.aiSupport.AiSupportApplication.getEnvPrefix;
/**
* Liblib
*/
public class QueryModel {
private static final String API_BASE_URL = "https://openapi.liblibai.cloud";
private static final String MODEL_VERSION_URL = API_BASE_URL + "/api/model/version/get";
private static final Logger log = LoggerFactory.getLogger(QueryModel.class);
// API访问密钥
protected static String accessKey;
protected static String secretKey;
public static Prop PropKit;
static {
//加载配置文件
String configFile = "application_{?}.yaml".replace("{?}", getEnvPrefix());
PropKit = new YamlProp(configFile);
accessKey = PropKit.get("LIBLIB.accessKey");
secretKey = PropKit.get("LIBLIB.secretKey");
}
/**
* OkHttpClient
* @return OkHttpClient
*/
private static OkHttpClient createHttpClient() {
return new OkHttpClient.Builder()
.connectTimeout(30, TimeUnit.SECONDS)
.readTimeout(60, TimeUnit.SECONDS)
.writeTimeout(60, TimeUnit.SECONDS)
.build();
}
/**
*
* @param versionUuid UUID
* @return
* @throws IOException
*/
public static JSONObject queryModelVersion(String versionUuid) throws IOException {
// 创建OkHttpClient
OkHttpClient client = createHttpClient();
// 构建请求体
JSONObject requestBody = new JSONObject();
requestBody.put("versionUuid", versionUuid);
// 获取API路径
String uri = "/api/model/version/get";
// 生成签名信息
SignUtil.SignatureInfo signInfo = SignUtil.makeSign(uri, secretKey);
// 构建带签名的URL
HttpUrl.Builder urlBuilder = HttpUrl.parse(MODEL_VERSION_URL).newBuilder()
.addQueryParameter("AccessKey", accessKey)
.addQueryParameter("Signature", signInfo.getSignature())
.addQueryParameter("Timestamp", String.valueOf(signInfo.getTimestamp()))
.addQueryParameter("SignatureNonce", signInfo.getSignatureNonce());
// 创建请求
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, requestBody.toJSONString());
Request request = new Request.Builder()
.url(urlBuilder.build())
.method("POST", body)
.addHeader("Content-Type", "application/json")
.build();
// 执行请求
log.info("查询模型版本信息: {}", requestBody.toJSONString());
log.info("请求URL: {}", urlBuilder.build());
Response response = client.newCall(request).execute();
// 处理响应
if (!response.isSuccessful()) {
String errorMsg = "查询模型版本信息失败,状态码: " + response.code();
log.error(errorMsg);
throw new IOException(errorMsg);
}
// 解析响应
String responseBody = response.body().string();
log.info("查询模型版本信息响应: {}", responseBody);
JSONObject responseJson = JSON.parseObject(responseBody);
int code = responseJson.getIntValue("code");
if (code != 0) {
String errorMsg = "查询模型版本信息失败,错误码: " + code + ", 错误信息: " + responseJson.getString("msg");
log.error(errorMsg);
throw new IOException(errorMsg);
}
return responseJson.getJSONObject("data");
}
/**
* 使
*/
public static void main(String[] args) {
try {
// 查询模型版本信息
String versionUuid = "86961315d0b34f229d58fadb7f284972";
JSONObject modelVersionInfo = queryModelVersion(versionUuid);
// 打印模型版本信息
log.info("模型版本信息: {}", modelVersionInfo);
// 提取关键信息
String modelName = modelVersionInfo.getString("modelName");
String versionName = modelVersionInfo.getString("versionName");
String description = modelVersionInfo.getString("description");
log.info("模型名称: {}", modelName);
log.info("版本名称: {}", versionName);
log.info("描述: {}", description);
} catch (Exception e) {
log.error("查询模型版本信息失败", e);
}
}
}
Loading…
Cancel
Save