main
HuangHai 2 months ago
parent e077c00418
commit 551c0db75d

@ -53,12 +53,6 @@
<artifactId>commons-io</artifactId>
<version>2.15.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.volcengine/volc-sdk-java -->
<dependency>
<groupId>com.volcengine</groupId>
<artifactId>volc-sdk-java</artifactId>
<version>1.0.221</version>
</dependency>
<!-- 数据库相关 -->
<dependency>
<groupId>com.alibaba</groupId>

@ -1,30 +0,0 @@
package com.dsideal.aiSupport.Util.DouBao;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.volcengine.service.visual.IVisualService;
import com.volcengine.service.visual.impl.VisualServiceImpl;
public class CVGetResultDemo {
public static void main(String[] args) {
IVisualService visualService = VisualServiceImpl.getInstance();
// call below method if you dont set ak and sk in /.vcloud/config
visualService.setAccessKey("your ak");
visualService.setSecretKey("your sk");
JSONObject req=new JSONObject();
//请求Body(查看接口文档请求参数-请求示例,将请求参数内容复制到此)
req.put("req_key","");
req.put("","");
try {
Object response = visualService.cvGetResult(req);
System.out.println(JSON.toJSONString(response));
} catch (Exception e) {
e.printStackTrace();
}
}
}

@ -1,35 +0,0 @@
package com.dsideal.aiSupport.Util.DouBao;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.dsideal.aiSupport.AiSupportApplication;
import com.volcengine.service.visual.IVisualService;
import com.volcengine.service.visual.impl.VisualServiceImpl;
public class CVSubmitTaskDemo {
public static void main(String[] args) {
IVisualService visualService = VisualServiceImpl.getInstance();
String ak = AiSupportApplication.PropKit.get("HuoShan.accessKey");
String sk = AiSupportApplication.PropKit.get("HuoShan.secretKey");
visualService.setAccessKey(ak);
visualService.setSecretKey(sk);
JSONObject req = new JSONObject();
req.put("req_key", "high_aes_general_v20_L");
req.put("prompt", "千军万马");
req.put("model_version", "general_v2.0_L");
req.put("seed", -1);
req.put("scale", 3.5);
req.put("ddim_steps", 16);
req.put("width", 512);
req.put("height", 512);
req.put("use_sr", true);
try {
Object response = visualService.cvSubmitTask(req);
System.out.println(JSON.toJSONString(response));
} catch (Exception e) {
e.printStackTrace();
}
}
}

@ -3,7 +3,6 @@ package com.dsideal.aiSupport.Util;
import com.dsideal.aiSupport.Config.GatewayConfig;
import okhttp3.*;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@ -45,38 +44,6 @@ public class HttpClient {
}
}
/**
* POSTJSON
*
* @param url URL
* @param jsonBody JSON
* @param headers
* @return
*/
public static String postJson(String url, String jsonBody, Map<String, String> headers) {
MediaType JSON = MediaType.parse("application/json; charset=utf-8");
RequestBody body = RequestBody.create(jsonBody, JSON);
Request.Builder builder = new Request.Builder()
.url(url)
.post(body);
// 添加请求头
if (headers != null) {
headers.forEach(builder::addHeader);
}
try (Response response = OK_HTTP_CLIENT.newCall(builder.build()).execute()) {
if (!response.isSuccessful()) {
throw new IOException("请求失败: " + response);
}
ResponseBody responseBody = response.body();
return responseBody != null ? responseBody.string() : null;
} catch (IOException e) {
throw new RuntimeException("POST请求异常: " + url, e);
}
}
/**
* POST
*
@ -113,42 +80,6 @@ public class HttpClient {
}
}
/**
* POST
*
* @param url URL
* @param file
* @param fileName
* @param headers
* @return
*/
public static String postFile(String url, File file, String fileName, Map<String, String> headers) {
RequestBody requestBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("file", fileName,
RequestBody.create(file, MediaType.parse("application/octet-stream")))
.build();
Request.Builder builder = new Request.Builder()
.url(url)
.post(requestBody);
// 添加请求头
if (headers != null) {
headers.forEach(builder::addHeader);
}
try (Response response = OK_HTTP_CLIENT.newCall(builder.build()).execute()) {
if (!response.isSuccessful()) {
throw new IOException("请求失败: " + response);
}
ResponseBody responseBody = response.body();
return responseBody != null ? responseBody.string() : null;
} catch (IOException e) {
throw new RuntimeException("文件上传异常: " + url, e);
}
}
public static void main(String[] args) {
//正常在Controller中获取到此人员的jwt
// String jwtToken =JwtUtil.getPersonJwt(req);

@ -0,0 +1,10 @@
package com.dsideal.aiSupport.Util.HuoShanFangZhou.Kit;
public class HuoShanCommon {
//火山方舟大模型
//https://console.volcengine.com/ark/region:ark+cn-beijing/apiKey?apikey=%7B%7D
// String apiKeyName = "api-key-20250418163654";
protected static String API_BASE_URL="https://ark.cn-beijing.volces.com";
protected static String ARK_API_KEY = "f6150e6c-422a-4265-8b63-4d941b271220";
}

@ -0,0 +1,162 @@
package com.dsideal.aiSupport.Util.HuoShanFangZhou;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.dsideal.aiSupport.Util.HuoShanFangZhou.Kit.HuoShanCommon;
import okhttp3.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
* API
*/
public class Txt2Img extends HuoShanCommon {
// 日志
private static final Logger log = LoggerFactory.getLogger(Txt2Img.class);
// 文生图API路径
private static final String TXT_TO_IMG_PATH = "/api/v3/images/generations";
// 默认图片尺寸
private static final String DEFAULT_SIZE = "1024x1024";
// 默认引导系数
private static final double DEFAULT_GUIDANCE_SCALE = 7.0;
// 默认水印设置
private static final boolean DEFAULT_WATERMARK = true;
// 默认响应格式
private static final String DEFAULT_RESPONSE_FORMAT = "url";
/**
*
*
* @param model
* @param prompt
* @return URL
* @throws IOException
*/
public static String generateImage(String model, String prompt) throws IOException {
return generateImage(model, prompt, DEFAULT_SIZE, -1, DEFAULT_GUIDANCE_SCALE, DEFAULT_WATERMARK);
}
/**
*
*
* @param model
* @param prompt
* @param size "1024x1024"
* @param seed -1
* @param guidanceScale
* @param watermark
* @return URL
* @throws IOException
*/
public static String generateImage(String model, String prompt, String size, long seed,
double guidanceScale, boolean watermark) throws IOException {
// 创建OkHttpClient
OkHttpClient client = new OkHttpClient.Builder()
.connectTimeout(30, TimeUnit.SECONDS)
.readTimeout(60, TimeUnit.SECONDS)
.writeTimeout(60, TimeUnit.SECONDS)
.build();
// 构建请求体
JSONObject requestBody = new JSONObject();
requestBody.put("model", model);
requestBody.put("prompt", prompt);
requestBody.put("response_format", DEFAULT_RESPONSE_FORMAT);
requestBody.put("size", size);
// 如果种子不是-1则添加种子参数
if (seed != -1) {
requestBody.put("seed", seed);
}
requestBody.put("guidance_scale", guidanceScale);
requestBody.put("watermark", watermark);
// 创建请求
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, requestBody.toJSONString());
Request request = new Request.Builder()
.url(API_BASE_URL + TXT_TO_IMG_PATH)
.method("POST", body)
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "Bearer " + ARK_API_KEY)
.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);
// 获取生成的图片URL
String imageUrl = responseJson.getJSONArray("data").getJSONObject(0).getString("url");
log.info("生成的图片URL: {}", imageUrl);
return imageUrl;
}
/**
*
*
* @param model
* @param prompt
* @param count
* @return URL
* @throws IOException
*/
public static List<String> generateImages(String model, String prompt, int count) throws IOException {
List<String> imageUrls = new ArrayList<>();
for (int i = 0; i < count; i++) {
String imageUrl = generateImage(model, prompt);
imageUrls.add(imageUrl);
}
return imageUrls;
}
/**
* 使
*/
public static void main(String[] args) {
try {
// 模型名称
String model = "doubao-seedream-3-0-t2i-250415";
// 提示词
String prompt = "鱼眼镜头,一只猫咪的头部,画面呈现出猫咪的五官因为拍摄方式扭曲的效果。";
// 图片尺寸
String size = "1024x1024";
// 随机种子
long seed = 12;
// 引导系数
double guidanceScale = 2.5;
// 是否添加水印
boolean watermark = true;
// 生成图片
String imageUrl = generateImage(model, prompt, size, seed, guidanceScale, watermark);
// 输出生成的图片URL
log.info("生成的图片URL: {}", imageUrl);
} catch (Exception e) {
log.error("文生图任务执行失败", e);
}
}
}

@ -53,36 +53,4 @@ excel:
# 导出excel 的模板配置路径
excelExportTemplatePathSuffix: /ExcelExportTemplate/
# 导入excel 的模板配置路径
ExcelImportTemplatePathSuffix: /ExcelImportTemplate/
# 即梦
JiMeng:
# Access Key ID
ak: AKLTZjVlOGU1NzA1YWZkNDExMzkzYzY5YTNlOTRmMTMxODg
# Secret Access Key
sk: WkdabU9UTXdNVEJpTmpWbE5HVTJZVGxtTnpWbU5XSTBaRGN5TW1NMk5tRQ==
# 可灵
KeLing:
# Access Key ID
ak: c992fd02624d4900a93ca3b6da03d9e9
# Secret Access Key
sk: b37f67a00eb44f9bb57e4d530c328e1d
# GPTNB GOAPI
GPTNB:
sk: sk-amQHwiEzPIZIB2KuF5A10dC23a0e4b02B48a7a2b6aFa0662
# 人工智能生成PPT
AIPPT:
BASE_URL: https://open.docmee.cn
API_KEY: ak_uKoKrRF63333E2lcBq
# 阿里云API KEY
aliyun:
API_KEY: sk-01d13a39e09844038322108ecdbd1bbc
# LIBLIB
LIBLIB:
accessKey: sOCtVLVTNOZkRMajlhzCmg
secretKey: PUe8QTRG9i0G9EbpedHmIpLQ0FyxoYY9
ExcelImportTemplatePathSuffix: /ExcelImportTemplate/
Loading…
Cancel
Save