|
@@ -1,4 +1,4 @@
|
|
-package cn.iocoder.yudao.framework.ai.core.model.xunfei.api;
|
|
|
|
|
|
+package cn.iocoder.yudao.framework.ai.core.model.xinghuo.api;
|
|
|
|
|
|
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
|
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
|
@@ -28,10 +28,11 @@ import java.util.Map;
|
|
import java.util.function.Function;
|
|
import java.util.function.Function;
|
|
import java.util.function.Predicate;
|
|
import java.util.function.Predicate;
|
|
|
|
|
|
|
|
+// TODO @新:要不改成 XunFeiPptApi
|
|
/**
|
|
/**
|
|
- * 讯飞智能PPT生成 API
|
|
|
|
- * <p>
|
|
|
|
- * 对接讯飞:<a href="https://www.xfyun.cn/doc/spark/PPTv2.html">智能 PPT 生成 API</a>
|
|
|
|
|
|
+ * 讯飞智能 PPT 生成 API
|
|
|
|
+ *
|
|
|
|
+ * @see <a href="https://www.xfyun.cn/doc/spark/PPTv2.html">智能 PPT 生成 API</a>
|
|
*
|
|
*
|
|
* @author xiaoxin
|
|
* @author xiaoxin
|
|
*/
|
|
*/
|
|
@@ -52,7 +53,9 @@ public class XunfeiPptApi {
|
|
sink.error(new IllegalStateException("[xunfei-ppt-api] 调用失败!"));
|
|
sink.error(new IllegalStateException("[xunfei-ppt-api] 调用失败!"));
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+ // TODO @新:是不是不用 baseUrl 哈
|
|
public XunfeiPptApi(String baseUrl, String appId, String apiSecret) {
|
|
public XunfeiPptApi(String baseUrl, String appId, String apiSecret) {
|
|
|
|
+ // TODO @新:建议,增加 defaultheaders,例如说 appid 之类的;或者每个请求,通过 headers customer 处理。
|
|
this.webClient = WebClient.builder()
|
|
this.webClient = WebClient.builder()
|
|
.baseUrl(baseUrl)
|
|
.baseUrl(baseUrl)
|
|
.build();
|
|
.build();
|
|
@@ -82,6 +85,7 @@ public class XunfeiPptApi {
|
|
*/
|
|
*/
|
|
private String generateSignature(String appId, String apiSecret, long timestamp) {
|
|
private String generateSignature(String appId, String apiSecret, long timestamp) {
|
|
try {
|
|
try {
|
|
|
|
+ // TODO @新:使用 hutool 简化
|
|
String auth = md5(appId + timestamp);
|
|
String auth = md5(appId + timestamp);
|
|
return hmacSHA1Encrypt(auth, apiSecret);
|
|
return hmacSHA1Encrypt(auth, apiSecret);
|
|
} catch (NoSuchAlgorithmException | InvalidKeyException e) {
|
|
} catch (NoSuchAlgorithmException | InvalidKeyException e) {
|
|
@@ -120,7 +124,7 @@ public class XunfeiPptApi {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 获取PPT模板列表
|
|
|
|
|
|
+ * 获取 PPT 模板列表
|
|
*
|
|
*
|
|
* @param style 风格,如"商务"
|
|
* @param style 风格,如"商务"
|
|
* @param pageSize 每页数量
|
|
* @param pageSize 每页数量
|
|
@@ -130,8 +134,8 @@ public class XunfeiPptApi {
|
|
SignatureInfo signInfo = getSignature();
|
|
SignatureInfo signInfo = getSignature();
|
|
Map<String, Object> requestBody = new HashMap<>();
|
|
Map<String, Object> requestBody = new HashMap<>();
|
|
requestBody.put("style", style);
|
|
requestBody.put("style", style);
|
|
- requestBody.put("pageSize", pageSize != null ? pageSize.toString() : "10");
|
|
|
|
-
|
|
|
|
|
|
+ // TODO @新:可以使用 ObjUtil.defaultIfNull
|
|
|
|
+ requestBody.put("pageSize", pageSize != null ? pageSize : 10);
|
|
return this.webClient.post()
|
|
return this.webClient.post()
|
|
.uri("/template/list")
|
|
.uri("/template/list")
|
|
.header("appId", signInfo.appId)
|
|
.header("appId", signInfo.appId)
|
|
@@ -155,7 +159,6 @@ public class XunfeiPptApi {
|
|
SignatureInfo signInfo = getSignature();
|
|
SignatureInfo signInfo = getSignature();
|
|
MultiValueMap<String, Object> formData = new LinkedMultiValueMap<>();
|
|
MultiValueMap<String, Object> formData = new LinkedMultiValueMap<>();
|
|
formData.add("query", query);
|
|
formData.add("query", query);
|
|
-
|
|
|
|
return this.webClient.post()
|
|
return this.webClient.post()
|
|
.uri("/createOutline")
|
|
.uri("/createOutline")
|
|
.header("appId", signInfo.appId)
|
|
.header("appId", signInfo.appId)
|
|
@@ -171,7 +174,7 @@ public class XunfeiPptApi {
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 直接创建PPT(简化版 - 通过文本)
|
|
|
|
|
|
+ * 直接创建 PPT(简化版 - 通过文本)
|
|
*
|
|
*
|
|
* @param query 查询文本
|
|
* @param query 查询文本
|
|
* @return 创建响应
|
|
* @return 创建响应
|
|
@@ -184,7 +187,7 @@ public class XunfeiPptApi {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 直接创建PPT(简化版 - 通过文件)
|
|
|
|
|
|
+ * 直接创建 PPT(简化版 - 通过文件)
|
|
*
|
|
*
|
|
* @param file 文件
|
|
* @param file 文件
|
|
* @param fileName 文件名
|
|
* @param fileName 文件名
|
|
@@ -192,14 +195,12 @@ public class XunfeiPptApi {
|
|
*/
|
|
*/
|
|
public CreateResponse create(MultipartFile file, String fileName) {
|
|
public CreateResponse create(MultipartFile file, String fileName) {
|
|
CreatePptRequest request = CreatePptRequest.builder()
|
|
CreatePptRequest request = CreatePptRequest.builder()
|
|
- .file(file)
|
|
|
|
- .fileName(fileName)
|
|
|
|
- .build();
|
|
|
|
|
|
+ .file(file).fileName(fileName).build();
|
|
return create(request);
|
|
return create(request);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 直接创建PPT(完整版)
|
|
|
|
|
|
+ * 直接创建 PPT(完整版)
|
|
*
|
|
*
|
|
* @param request 请求参数
|
|
* @param request 请求参数
|
|
* @return 创建响应
|
|
* @return 创建响应
|
|
@@ -207,7 +208,6 @@ public class XunfeiPptApi {
|
|
public CreateResponse create(CreatePptRequest request) {
|
|
public CreateResponse create(CreatePptRequest request) {
|
|
SignatureInfo signInfo = getSignature();
|
|
SignatureInfo signInfo = getSignature();
|
|
MultiValueMap<String, Object> formData = buildCreateFormData(request);
|
|
MultiValueMap<String, Object> formData = buildCreateFormData(request);
|
|
-
|
|
|
|
return this.webClient.post()
|
|
return this.webClient.post()
|
|
.uri("/create")
|
|
.uri("/create")
|
|
.header("appId", signInfo.appId)
|
|
.header("appId", signInfo.appId)
|
|
@@ -223,7 +223,7 @@ public class XunfeiPptApi {
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 通过大纲创建PPT(简化版)
|
|
|
|
|
|
+ * 通过大纲创建 PPT(简化版)
|
|
*
|
|
*
|
|
* @param outline 大纲内容
|
|
* @param outline 大纲内容
|
|
* @param query 查询文本
|
|
* @param query 查询文本
|
|
@@ -238,14 +238,13 @@ public class XunfeiPptApi {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 通过大纲创建PPT(完整版)
|
|
|
|
|
|
+ * 通过大纲创建 PPT(完整版)
|
|
*
|
|
*
|
|
* @param request 请求参数
|
|
* @param request 请求参数
|
|
* @return 创建响应
|
|
* @return 创建响应
|
|
*/
|
|
*/
|
|
public CreateResponse createPptByOutline(CreatePptByOutlineRequest request) {
|
|
public CreateResponse createPptByOutline(CreatePptByOutlineRequest request) {
|
|
SignatureInfo signInfo = getSignature();
|
|
SignatureInfo signInfo = getSignature();
|
|
-
|
|
|
|
return this.webClient.post()
|
|
return this.webClient.post()
|
|
.uri("/createPptByOutline")
|
|
.uri("/createPptByOutline")
|
|
.header("appId", signInfo.appId)
|
|
.header("appId", signInfo.appId)
|
|
@@ -260,14 +259,13 @@ public class XunfeiPptApi {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 检查PPT生成进度
|
|
|
|
|
|
+ * 检查 PPT 生成进度
|
|
*
|
|
*
|
|
- * @param sid 任务ID
|
|
|
|
|
|
+ * @param sid 任务 ID
|
|
* @return 进度响应
|
|
* @return 进度响应
|
|
*/
|
|
*/
|
|
public ProgressResponse checkProgress(String sid) {
|
|
public ProgressResponse checkProgress(String sid) {
|
|
SignatureInfo signInfo = getSignature();
|
|
SignatureInfo signInfo = getSignature();
|
|
-
|
|
|
|
return this.webClient.get()
|
|
return this.webClient.get()
|
|
.uri(uriBuilder -> uriBuilder
|
|
.uri(uriBuilder -> uriBuilder
|
|
.path("/progress")
|
|
.path("/progress")
|
|
@@ -290,8 +288,7 @@ public class XunfeiPptApi {
|
|
String appId,
|
|
String appId,
|
|
String timestamp,
|
|
String timestamp,
|
|
String signature
|
|
String signature
|
|
- ) {
|
|
|
|
- }
|
|
|
|
|
|
+ ) { }
|
|
|
|
|
|
/**
|
|
/**
|
|
* 模板列表响应
|
|
* 模板列表响应
|
|
@@ -303,8 +300,7 @@ public class XunfeiPptApi {
|
|
String desc,
|
|
String desc,
|
|
Integer count,
|
|
Integer count,
|
|
TemplatePageData data
|
|
TemplatePageData data
|
|
- ) {
|
|
|
|
- }
|
|
|
|
|
|
+ ) { }
|
|
|
|
|
|
/**
|
|
/**
|
|
* 模板列表数据
|
|
* 模板列表数据
|
|
@@ -314,8 +310,7 @@ public class XunfeiPptApi {
|
|
String total,
|
|
String total,
|
|
List<TemplateInfo> records,
|
|
List<TemplateInfo> records,
|
|
Integer pageNum
|
|
Integer pageNum
|
|
- ) {
|
|
|
|
- }
|
|
|
|
|
|
+ ) { }
|
|
|
|
|
|
/**
|
|
/**
|
|
* 模板信息
|
|
* 模板信息
|
|
@@ -329,8 +324,7 @@ public class XunfeiPptApi {
|
|
String industry,
|
|
String industry,
|
|
String style,
|
|
String style,
|
|
String detailImage
|
|
String detailImage
|
|
- ) {
|
|
|
|
- }
|
|
|
|
|
|
+ ) { }
|
|
|
|
|
|
/**
|
|
/**
|
|
* 创建响应
|
|
* 创建响应
|
|
@@ -342,8 +336,7 @@ public class XunfeiPptApi {
|
|
String desc,
|
|
String desc,
|
|
Integer count,
|
|
Integer count,
|
|
CreateResponseData data
|
|
CreateResponseData data
|
|
- ) {
|
|
|
|
- }
|
|
|
|
|
|
+ ) { }
|
|
|
|
|
|
/**
|
|
/**
|
|
* 创建响应数据
|
|
* 创建响应数据
|
|
@@ -355,8 +348,7 @@ public class XunfeiPptApi {
|
|
String title,
|
|
String title,
|
|
String subTitle,
|
|
String subTitle,
|
|
OutlineData outline
|
|
OutlineData outline
|
|
- ) {
|
|
|
|
- }
|
|
|
|
|
|
+ ) { }
|
|
|
|
|
|
/**
|
|
/**
|
|
* 大纲数据结构
|
|
* 大纲数据结构
|
|
@@ -367,6 +359,7 @@ public class XunfeiPptApi {
|
|
String subTitle,
|
|
String subTitle,
|
|
List<Chapter> chapters
|
|
List<Chapter> chapters
|
|
) {
|
|
) {
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 章节结构
|
|
* 章节结构
|
|
*/
|
|
*/
|
|
@@ -375,14 +368,15 @@ public class XunfeiPptApi {
|
|
String chapterTitle,
|
|
String chapterTitle,
|
|
List<ChapterContent> chapterContents
|
|
List<ChapterContent> chapterContents
|
|
) {
|
|
) {
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 章节内容
|
|
* 章节内容
|
|
*/
|
|
*/
|
|
@JsonInclude(value = JsonInclude.Include.NON_NULL)
|
|
@JsonInclude(value = JsonInclude.Include.NON_NULL)
|
|
public record ChapterContent(
|
|
public record ChapterContent(
|
|
String chapterTitle
|
|
String chapterTitle
|
|
- ) {
|
|
|
|
- }
|
|
|
|
|
|
+ ) { }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -403,8 +397,7 @@ public class XunfeiPptApi {
|
|
int code,
|
|
int code,
|
|
String desc,
|
|
String desc,
|
|
ProgressResponseData data
|
|
ProgressResponseData data
|
|
- ) {
|
|
|
|
- }
|
|
|
|
|
|
+ ) { }
|
|
|
|
|
|
/**
|
|
/**
|
|
* 进度响应数据
|
|
* 进度响应数据
|
|
@@ -414,6 +407,7 @@ public class XunfeiPptApi {
|
|
int process,
|
|
int process,
|
|
String pptId,
|
|
String pptId,
|
|
String pptUrl,
|
|
String pptUrl,
|
|
|
|
+ // TODO @新:字段注释,去掉
|
|
String pptStatus, // PPT构建状态:building(构建中),done(已完成),build_failed(生成失败)
|
|
String pptStatus, // PPT构建状态:building(构建中),done(已完成),build_failed(生成失败)
|
|
String aiImageStatus, // ai配图状态:building(构建中),done(已完成)
|
|
String aiImageStatus, // ai配图状态:building(构建中),done(已完成)
|
|
String cardNoteStatus, // 演讲备注状态:building(构建中),done(已完成)
|
|
String cardNoteStatus, // 演讲备注状态:building(构建中),done(已完成)
|
|
@@ -421,6 +415,7 @@ public class XunfeiPptApi {
|
|
Integer totalPages, // 生成PPT的总页数
|
|
Integer totalPages, // 生成PPT的总页数
|
|
Integer donePages // 生成PPT的完成页数
|
|
Integer donePages // 生成PPT的完成页数
|
|
) {
|
|
) {
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 是否全部完成
|
|
* 是否全部完成
|
|
*
|
|
*
|
|
@@ -452,10 +447,11 @@ public class XunfeiPptApi {
|
|
}
|
|
}
|
|
return (int) (donePages * 100.0 / totalPages);
|
|
return (int) (donePages * 100.0 / totalPages);
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 通过大纲创建PPT请求参数
|
|
|
|
|
|
+ * 通过大纲创建 PPT 请求参数
|
|
*/
|
|
*/
|
|
@JsonInclude(value = JsonInclude.Include.NON_NULL)
|
|
@JsonInclude(value = JsonInclude.Include.NON_NULL)
|
|
public record CreatePptByOutlineRequest(
|
|
public record CreatePptByOutlineRequest(
|
|
@@ -473,6 +469,7 @@ public class XunfeiPptApi {
|
|
Boolean isFigure, // 是否自动配图
|
|
Boolean isFigure, // 是否自动配图
|
|
String aiImage // ai配图类型:normal、advanced
|
|
String aiImage // ai配图类型:normal、advanced
|
|
) {
|
|
) {
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 创建构建器
|
|
* 创建构建器
|
|
*
|
|
*
|
|
@@ -482,10 +479,12 @@ public class XunfeiPptApi {
|
|
return new Builder();
|
|
return new Builder();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // TODO @新:这个可以用 lombok 简化么?
|
|
/**
|
|
/**
|
|
* 构建器类
|
|
* 构建器类
|
|
*/
|
|
*/
|
|
public static class Builder {
|
|
public static class Builder {
|
|
|
|
+
|
|
private String query;
|
|
private String query;
|
|
private String outlineSid;
|
|
private String outlineSid;
|
|
private OutlineData outline;
|
|
private OutlineData outline;
|
|
@@ -575,7 +574,7 @@ public class XunfeiPptApi {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 构建创建PPT的表单数据
|
|
|
|
|
|
+ * 构建创建 PPT 的表单数据
|
|
*
|
|
*
|
|
* @param request 请求参数
|
|
* @param request 请求参数
|
|
* @return 表单数据
|
|
* @return 表单数据
|
|
@@ -586,7 +585,6 @@ public class XunfeiPptApi {
|
|
if (request.query() != null) {
|
|
if (request.query() != null) {
|
|
formData.add("query", request.query());
|
|
formData.add("query", request.query());
|
|
}
|
|
}
|
|
-
|
|
|
|
if (request.file() != null) {
|
|
if (request.file() != null) {
|
|
try {
|
|
try {
|
|
formData.add("file", new ByteArrayResource(request.file().getBytes()) {
|
|
formData.add("file", new ByteArrayResource(request.file().getBytes()) {
|
|
@@ -600,47 +598,37 @@ public class XunfeiPptApi {
|
|
throw new IllegalStateException("[xunfei-ppt-api] 文件处理失败", e);
|
|
throw new IllegalStateException("[xunfei-ppt-api] 文件处理失败", e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ // TODO @新:要不搞个 MapUtil.addIfPresent 方法?
|
|
if (request.fileUrl() != null) {
|
|
if (request.fileUrl() != null) {
|
|
formData.add("fileUrl", request.fileUrl());
|
|
formData.add("fileUrl", request.fileUrl());
|
|
}
|
|
}
|
|
-
|
|
|
|
if (request.fileName() != null) {
|
|
if (request.fileName() != null) {
|
|
formData.add("fileName", request.fileName());
|
|
formData.add("fileName", request.fileName());
|
|
}
|
|
}
|
|
-
|
|
|
|
if (request.templateId() != null) {
|
|
if (request.templateId() != null) {
|
|
formData.add("templateId", request.templateId());
|
|
formData.add("templateId", request.templateId());
|
|
}
|
|
}
|
|
-
|
|
|
|
if (request.businessId() != null) {
|
|
if (request.businessId() != null) {
|
|
formData.add("businessId", request.businessId());
|
|
formData.add("businessId", request.businessId());
|
|
}
|
|
}
|
|
-
|
|
|
|
if (request.author() != null) {
|
|
if (request.author() != null) {
|
|
formData.add("author", request.author());
|
|
formData.add("author", request.author());
|
|
}
|
|
}
|
|
-
|
|
|
|
if (request.isCardNote() != null) {
|
|
if (request.isCardNote() != null) {
|
|
formData.add("isCardNote", request.isCardNote().toString());
|
|
formData.add("isCardNote", request.isCardNote().toString());
|
|
}
|
|
}
|
|
-
|
|
|
|
if (request.search() != null) {
|
|
if (request.search() != null) {
|
|
formData.add("search", request.search().toString());
|
|
formData.add("search", request.search().toString());
|
|
}
|
|
}
|
|
-
|
|
|
|
if (request.language() != null) {
|
|
if (request.language() != null) {
|
|
formData.add("language", request.language());
|
|
formData.add("language", request.language());
|
|
}
|
|
}
|
|
-
|
|
|
|
if (request.isFigure() != null) {
|
|
if (request.isFigure() != null) {
|
|
formData.add("isFigure", request.isFigure().toString());
|
|
formData.add("isFigure", request.isFigure().toString());
|
|
}
|
|
}
|
|
-
|
|
|
|
if (request.aiImage() != null) {
|
|
if (request.aiImage() != null) {
|
|
formData.add("aiImage", request.aiImage());
|
|
formData.add("aiImage", request.aiImage());
|
|
}
|
|
}
|
|
-
|
|
|
|
return formData;
|
|
return formData;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -662,6 +650,7 @@ public class XunfeiPptApi {
|
|
Boolean isFigure, // 是否自动配图
|
|
Boolean isFigure, // 是否自动配图
|
|
String aiImage // ai配图类型:normal、advanced
|
|
String aiImage // ai配图类型:normal、advanced
|
|
) {
|
|
) {
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 创建构建器
|
|
* 创建构建器
|
|
*
|
|
*
|
|
@@ -675,6 +664,7 @@ public class XunfeiPptApi {
|
|
* 构建器类
|
|
* 构建器类
|
|
*/
|
|
*/
|
|
public static class Builder {
|
|
public static class Builder {
|
|
|
|
+
|
|
private String query;
|
|
private String query;
|
|
private MultipartFile file;
|
|
private MultipartFile file;
|
|
private String fileUrl;
|
|
private String fileUrl;
|
|
@@ -688,6 +678,8 @@ public class XunfeiPptApi {
|
|
private Boolean isFigure;
|
|
private Boolean isFigure;
|
|
private String aiImage;
|
|
private String aiImage;
|
|
|
|
|
|
|
|
+ // TODO @新:这个可以用 lombok 简化么?
|
|
|
|
+
|
|
public Builder query(String query) {
|
|
public Builder query(String query) {
|
|
this.query = query;
|
|
this.query = query;
|
|
return this;
|
|
return this;
|
|
@@ -763,4 +755,5 @@ public class XunfeiPptApi {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-}
|
|
|
|
|
|
+
|
|
|
|
+}
|