Merge branch 'feature/ai' of https://gitee.com/zhijiantianya/ruoyi-vue-pro into master-jdk17
This commit is contained in:
commit
e56b99f2a7
|
@ -8,6 +8,7 @@ import org.springframework.core.ParameterizedTypeReference;
|
||||||
import org.springframework.http.HttpRequest;
|
import org.springframework.http.HttpRequest;
|
||||||
import org.springframework.http.HttpStatusCode;
|
import org.springframework.http.HttpStatusCode;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.LinkedMultiValueMap;
|
import org.springframework.util.LinkedMultiValueMap;
|
||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
@ -24,18 +25,17 @@ import java.util.Objects;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
// TODO @新:要不改成 WenDuoDuoPptApi
|
|
||||||
/**
|
/**
|
||||||
* 文多多 API
|
* 文多多 API
|
||||||
*
|
*
|
||||||
* @see <a href="https://docmee.cn/open-platform/api">PPT 生成 API</a>
|
|
||||||
*
|
|
||||||
* @author xiaoxin
|
* @author xiaoxin
|
||||||
|
* @see <a href="https://docmee.cn/open-platform/api">PPT 生成 API</a>
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class WddPptApi {
|
public class WenDuoDuoPptApi {
|
||||||
|
|
||||||
public static final String BASE_URL = "https://docmee.cn";
|
public static final String BASE_URL = "https://docmee.cn";
|
||||||
|
public static final String TOKEN_NAME = "token";
|
||||||
|
|
||||||
private final WebClient webClient;
|
private final WebClient webClient;
|
||||||
|
|
||||||
|
@ -44,17 +44,19 @@ public class WddPptApi {
|
||||||
private final Function<Object, Function<ClientResponse, Mono<? extends Throwable>>> EXCEPTION_FUNCTION =
|
private final Function<Object, Function<ClientResponse, Mono<? extends Throwable>>> EXCEPTION_FUNCTION =
|
||||||
reqParam -> response -> response.bodyToMono(String.class).handle((responseBody, sink) -> {
|
reqParam -> response -> response.bodyToMono(String.class).handle((responseBody, sink) -> {
|
||||||
HttpRequest request = response.request();
|
HttpRequest request = response.request();
|
||||||
log.error("[wdd-api] 调用失败!请求方式:[{}],请求地址:[{}],请求参数:[{}],响应数据: [{}]",
|
log.error("[WenDuoDuoPptApi] 调用失败!请求方式:[{}],请求地址:[{}],请求参数:[{}],响应数据: [{}]",
|
||||||
request.getMethod(), request.getURI(), reqParam, responseBody);
|
request.getMethod(), request.getURI(), reqParam, responseBody);
|
||||||
sink.error(new IllegalStateException("[wdd-api] 调用失败!"));
|
sink.error(new IllegalStateException("[WenDuoDuoPptApi] 调用失败!"));
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO @新:是不是不用 baseUrl 哈
|
public WenDuoDuoPptApi(String token) {
|
||||||
public WddPptApi(String baseUrl) {
|
Assert.hasText(token, "token 不能为空");
|
||||||
this.webClient = WebClient.builder()
|
this.webClient = WebClient.builder()
|
||||||
.baseUrl(baseUrl)
|
.baseUrl(BASE_URL)
|
||||||
// TODO @新:建议,token 作为 defaultHeader
|
.defaultHeaders((headers) -> {
|
||||||
.defaultHeaders((headers) -> headers.setContentType(MediaType.APPLICATION_JSON))
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
headers.add(TOKEN_NAME, token);
|
||||||
|
})
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,37 +84,16 @@ public class WddPptApi {
|
||||||
.block();
|
.block();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO @xin:是不是给个 API 连接,这样 type、content、files 都不用写注释太细了
|
|
||||||
/**
|
/**
|
||||||
* 创建任务
|
* 创建任务
|
||||||
*
|
*
|
||||||
* @param type 类型
|
* @param type 类型
|
||||||
* 1.智能生成(主题、要求)
|
|
||||||
* 2.上传文件生成
|
|
||||||
* 3.上传思维导图生成
|
|
||||||
* 4.通过word精准转ppt
|
|
||||||
* 5.通过网页链接生成
|
|
||||||
* 6.粘贴文本内容生成
|
|
||||||
* 7.Markdown大纲生成
|
|
||||||
* @param content 内容
|
* @param content 内容
|
||||||
* type=1 用户输入主题或要求(不超过1000字符)
|
|
||||||
* type=2、4 不传
|
|
||||||
* type=3 幕布等分享链接
|
|
||||||
* type=5 网页链接地址(http/https)
|
|
||||||
* type=6 粘贴文本内容(不超过20000字符)
|
|
||||||
* type=7 大纲内容(markdown)
|
|
||||||
* @param files 文件列表
|
* @param files 文件列表
|
||||||
* 文件列表(文件数不超过5个,总大小不超过50M):
|
|
||||||
* type=1 上传参考文件(非必传,支持多个)
|
|
||||||
* type=2 上传文件(支持多个)
|
|
||||||
* type=3 上传思维导图(xmind/mm/md)(仅支持一个)
|
|
||||||
* type=4 上传word文件(仅支持一个)
|
|
||||||
* type=5、6、7 不传
|
|
||||||
* <p>
|
|
||||||
* 支持格式:doc/docx/pdf/ppt/pptx/txt/md/xls/xlsx/csv/html/epub/mobi/xmind/mm
|
|
||||||
* @return 任务 ID
|
* @return 任务 ID
|
||||||
|
* @see <a href="https://docmee.cn/open-platform/api#%E5%88%9B%E5%BB%BA%E4%BB%BB%E5%8A%A1">创建任务</a>
|
||||||
*/
|
*/
|
||||||
public ApiResponse createTask(String token, Integer type, String content, List<MultipartFile> files) {
|
public ApiResponse createTask(Integer type, String content, List<MultipartFile> files) {
|
||||||
MultiValueMap<String, Object> formData = new LinkedMultiValueMap<>();
|
MultiValueMap<String, Object> formData = new LinkedMultiValueMap<>();
|
||||||
formData.add("type", type);
|
formData.add("type", type);
|
||||||
if (content != null) {
|
if (content != null) {
|
||||||
|
@ -125,7 +106,6 @@ public class WddPptApi {
|
||||||
}
|
}
|
||||||
return this.webClient.post()
|
return this.webClient.post()
|
||||||
.uri("/api/ppt/v2/createTask")
|
.uri("/api/ppt/v2/createTask")
|
||||||
.header("token", token)
|
|
||||||
.contentType(MediaType.MULTIPART_FORM_DATA)
|
.contentType(MediaType.MULTIPART_FORM_DATA)
|
||||||
.body(BodyInserters.fromMultipartData(formData))
|
.body(BodyInserters.fromMultipartData(formData))
|
||||||
.retrieve()
|
.retrieve()
|
||||||
|
@ -168,10 +148,9 @@ public class WddPptApi {
|
||||||
* @param request 请求体
|
* @param request 请求体
|
||||||
* @return 模板列表
|
* @return 模板列表
|
||||||
*/
|
*/
|
||||||
public PagePptTemplateInfo getTemplatePage(String token, TemplateQueryRequest request) {
|
public PagePptTemplateInfo getTemplatePage(TemplateQueryRequest request) {
|
||||||
return this.webClient.post()
|
return this.webClient.post()
|
||||||
.uri("/api/ppt/templates")
|
.uri("/api/ppt/templates")
|
||||||
.header("token", token)
|
|
||||||
.bodyValue(request)
|
.bodyValue(request)
|
||||||
.retrieve()
|
.retrieve()
|
||||||
.onStatus(STATUS_PREDICATE, EXCEPTION_FUNCTION.apply(request))
|
.onStatus(STATUS_PREDICATE, EXCEPTION_FUNCTION.apply(request))
|
||||||
|
@ -185,10 +164,9 @@ public class WddPptApi {
|
||||||
*
|
*
|
||||||
* @return 大纲内容流
|
* @return 大纲内容流
|
||||||
*/
|
*/
|
||||||
public Flux<Map<String, Object>> createOutline(String token, CreateOutlineRequest request) {
|
public Flux<Map<String, Object>> createOutline(CreateOutlineRequest request) {
|
||||||
return this.webClient.post()
|
return this.webClient.post()
|
||||||
.uri("/api/ppt/v2/generateContent")
|
.uri("/api/ppt/v2/generateContent")
|
||||||
.header("token", token)
|
|
||||||
.body(Mono.just(request), CreateOutlineRequest.class)
|
.body(Mono.just(request), CreateOutlineRequest.class)
|
||||||
.retrieve()
|
.retrieve()
|
||||||
.onStatus(STATUS_PREDICATE, EXCEPTION_FUNCTION.apply(request))
|
.onStatus(STATUS_PREDICATE, EXCEPTION_FUNCTION.apply(request))
|
||||||
|
@ -202,10 +180,9 @@ public class WddPptApi {
|
||||||
* @param request 请求体
|
* @param request 请求体
|
||||||
* @return 大纲内容流
|
* @return 大纲内容流
|
||||||
*/
|
*/
|
||||||
public Flux<Map<String, Object>> updateOutline(String token, UpdateOutlineRequest request) {
|
public Flux<Map<String, Object>> updateOutline(UpdateOutlineRequest request) {
|
||||||
return this.webClient.post()
|
return this.webClient.post()
|
||||||
.uri("/api/ppt/v2/updateContent")
|
.uri("/api/ppt/v2/updateContent")
|
||||||
.header("token", token)
|
|
||||||
.body(Mono.just(request), UpdateOutlineRequest.class)
|
.body(Mono.just(request), UpdateOutlineRequest.class)
|
||||||
.retrieve()
|
.retrieve()
|
||||||
.onStatus(STATUS_PREDICATE, EXCEPTION_FUNCTION.apply(request))
|
.onStatus(STATUS_PREDICATE, EXCEPTION_FUNCTION.apply(request))
|
||||||
|
@ -218,11 +195,10 @@ public class WddPptApi {
|
||||||
*
|
*
|
||||||
* @return PPT信息
|
* @return PPT信息
|
||||||
*/
|
*/
|
||||||
public PptInfo create(String token, CreatePptRequest request) {
|
public PptInfo create(PptCreateRequest request) {
|
||||||
return this.webClient.post()
|
return this.webClient.post()
|
||||||
.uri("/api/ppt/v2/generatePptx")
|
.uri("/api/ppt/v2/generatePptx")
|
||||||
.header("token", token)
|
.body(Mono.just(request), PptCreateRequest.class)
|
||||||
.body(Mono.just(request), CreatePptRequest.class)
|
|
||||||
.retrieve()
|
.retrieve()
|
||||||
.onStatus(STATUS_PREDICATE, EXCEPTION_FUNCTION.apply(request))
|
.onStatus(STATUS_PREDICATE, EXCEPTION_FUNCTION.apply(request))
|
||||||
.bodyToMono(ApiResponse.class)
|
.bodyToMono(ApiResponse.class)
|
||||||
|
@ -236,7 +212,9 @@ public class WddPptApi {
|
||||||
.block();
|
.block();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建 Token 请求参数
|
||||||
|
*/
|
||||||
@JsonInclude(value = JsonInclude.Include.NON_NULL)
|
@JsonInclude(value = JsonInclude.Include.NON_NULL)
|
||||||
public record CreateTokenRequest(
|
public record CreateTokenRequest(
|
||||||
String apiKey,
|
String apiKey,
|
||||||
|
@ -258,7 +236,8 @@ public class WddPptApi {
|
||||||
Integer code,
|
Integer code,
|
||||||
String message,
|
String message,
|
||||||
Map<String, Object> data
|
Map<String, Object> data
|
||||||
) { }
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建任务
|
* 创建任务
|
||||||
|
@ -268,7 +247,8 @@ public class WddPptApi {
|
||||||
Integer type,
|
Integer type,
|
||||||
String content,
|
String content,
|
||||||
List<MultipartFile> files
|
List<MultipartFile> files
|
||||||
) { }
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成大纲内容请求
|
* 生成大纲内容请求
|
||||||
|
@ -281,7 +261,8 @@ public class WddPptApi {
|
||||||
String audience,
|
String audience,
|
||||||
String lang,
|
String lang,
|
||||||
String prompt
|
String prompt
|
||||||
) { }
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改大纲内容请求
|
* 修改大纲内容请求
|
||||||
|
@ -291,20 +272,23 @@ public class WddPptApi {
|
||||||
String id,
|
String id,
|
||||||
String markdown,
|
String markdown,
|
||||||
String question
|
String question
|
||||||
) { }
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成 PPT 请求
|
* 生成 PPT 请求参数
|
||||||
*/
|
*/
|
||||||
// TODO @新:要不按照 PptCreateRequest 这样的风格
|
|
||||||
@JsonInclude(value = JsonInclude.Include.NON_NULL)
|
@JsonInclude(value = JsonInclude.Include.NON_NULL)
|
||||||
public record CreatePptRequest(
|
public record PptCreateRequest(
|
||||||
String id,
|
String id,
|
||||||
String templateId,
|
String templateId,
|
||||||
String markdown
|
String markdown
|
||||||
) { }
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
// TODO @新:要不写下类注释
|
/**
|
||||||
|
* PPT 信息
|
||||||
|
*/
|
||||||
@JsonInclude(value = JsonInclude.Include.NON_NULL)
|
@JsonInclude(value = JsonInclude.Include.NON_NULL)
|
||||||
public record PptInfo(
|
public record PptInfo(
|
||||||
String id,
|
String id,
|
||||||
|
@ -323,9 +307,12 @@ public class WddPptApi {
|
||||||
LocalDateTime createTime,
|
LocalDateTime createTime,
|
||||||
String createUser,
|
String createUser,
|
||||||
String updateUser
|
String updateUser
|
||||||
) { }
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
// TODO @新:要不写下类注释
|
/**
|
||||||
|
* 模板查询请求参数
|
||||||
|
*/
|
||||||
@JsonInclude(value = JsonInclude.Include.NON_NULL)
|
@JsonInclude(value = JsonInclude.Include.NON_NULL)
|
||||||
public record TemplateQueryRequest(
|
public record TemplateQueryRequest(
|
||||||
int page,
|
int page,
|
||||||
|
@ -333,25 +320,33 @@ public class WddPptApi {
|
||||||
Filter filters
|
Filter filters
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模板查询过滤条件
|
||||||
|
*/
|
||||||
@JsonInclude(value = JsonInclude.Include.NON_NULL)
|
@JsonInclude(value = JsonInclude.Include.NON_NULL)
|
||||||
public record Filter(
|
public record Filter(
|
||||||
int type,
|
int type,
|
||||||
String category,
|
String category,
|
||||||
String style,
|
String style,
|
||||||
String themeColor
|
String themeColor
|
||||||
) { }
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO @新:要不写下类注释
|
/**
|
||||||
|
* PPT模板分页信息
|
||||||
|
*/
|
||||||
@JsonInclude(value = JsonInclude.Include.NON_NULL)
|
@JsonInclude(value = JsonInclude.Include.NON_NULL)
|
||||||
public record PagePptTemplateInfo(
|
public record PagePptTemplateInfo(
|
||||||
List<PptTemplateInfo> data,
|
List<PptTemplateInfo> data,
|
||||||
String total
|
String total
|
||||||
) {}
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
// TODO @新:要不写下类注释
|
* PPT模板信息
|
||||||
|
*/
|
||||||
@JsonInclude(value = JsonInclude.Include.NON_NULL)
|
@JsonInclude(value = JsonInclude.Include.NON_NULL)
|
||||||
public record PptTemplateInfo(
|
public record PptTemplateInfo(
|
||||||
String id,
|
String id,
|
||||||
|
@ -380,6 +375,7 @@ public class WddPptApi {
|
||||||
LocalDateTime createTime,
|
LocalDateTime createTime,
|
||||||
String createUser,
|
String createUser,
|
||||||
String updateUser
|
String updateUser
|
||||||
) { }
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,45 +1,44 @@
|
||||||
package cn.iocoder.yudao.framework.ai.core.model.xinghuo.api;
|
package cn.iocoder.yudao.framework.ai.core.model.xinghuo.api;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjUtil;
|
||||||
|
import cn.hutool.crypto.SecureUtil;
|
||||||
|
import cn.hutool.crypto.digest.HmacAlgorithm;
|
||||||
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;
|
||||||
|
import lombok.Builder;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.core.io.ByteArrayResource;
|
import org.springframework.core.io.ByteArrayResource;
|
||||||
import org.springframework.http.HttpStatusCode;
|
import org.springframework.http.HttpStatusCode;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.util.LinkedMultiValueMap;
|
import org.springframework.util.LinkedMultiValueMap;
|
||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
import org.springframework.web.reactive.function.BodyInserters;
|
import org.springframework.web.reactive.function.BodyInserters;
|
||||||
import org.springframework.web.reactive.function.client.ClientResponse;
|
import org.springframework.web.reactive.function.client.ClientResponse;
|
||||||
import org.springframework.web.reactive.function.client.WebClient;
|
import org.springframework.web.reactive.function.client.WebClient;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
import javax.crypto.Mac;
|
|
||||||
import javax.crypto.spec.SecretKeySpec;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.security.InvalidKeyException;
|
|
||||||
import java.security.MessageDigest;
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.util.Base64;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
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
|
* 讯飞智能 PPT 生成 API
|
||||||
*
|
*
|
||||||
* @see <a href="https://www.xfyun.cn/doc/spark/PPTv2.html">智能 PPT 生成 API</a>
|
|
||||||
*
|
|
||||||
* @author xiaoxin
|
* @author xiaoxin
|
||||||
|
* @see <a href="https://www.xfyun.cn/doc/spark/PPTv2.html">智能 PPT 生成 API</a>
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class XunfeiPptApi {
|
public class XunFeiPptApi {
|
||||||
|
|
||||||
public static final String BASE_URL = "https://zwapi.xfyun.cn/api/ppt/v2";
|
public static final String BASE_URL = "https://zwapi.xfyun.cn/api/ppt/v2";
|
||||||
|
private static final String HEADER_APP_ID = "appId";
|
||||||
|
private static final String HEADER_TIMESTAMP = "timestamp";
|
||||||
|
private static final String HEADER_SIGNATURE = "signature";
|
||||||
|
|
||||||
private final WebClient webClient;
|
private final WebClient webClient;
|
||||||
private final String appId;
|
private final String appId;
|
||||||
|
@ -49,18 +48,21 @@ public class XunfeiPptApi {
|
||||||
|
|
||||||
private final Function<Object, Function<ClientResponse, Mono<? extends Throwable>>> EXCEPTION_FUNCTION =
|
private final Function<Object, Function<ClientResponse, Mono<? extends Throwable>>> EXCEPTION_FUNCTION =
|
||||||
reqParam -> response -> response.bodyToMono(String.class).handle((responseBody, sink) -> {
|
reqParam -> response -> response.bodyToMono(String.class).handle((responseBody, sink) -> {
|
||||||
log.error("[xunfei-ppt-api] 调用失败!请求参数:[{}],响应数据: [{}]", reqParam, responseBody);
|
log.error("[XunFeiPptApi] 调用失败!请求参数:[{}],响应数据: [{}]", reqParam, responseBody);
|
||||||
sink.error(new IllegalStateException("[xunfei-ppt-api] 调用失败!"));
|
sink.error(new IllegalStateException("[XunFeiPptApi] 调用失败!"));
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO @新:是不是不用 baseUrl 哈
|
public XunFeiPptApi(String appId, String apiSecret) {
|
||||||
public XunfeiPptApi(String baseUrl, String appId, String apiSecret) {
|
|
||||||
// TODO @新:建议,增加 defaultheaders,例如说 appid 之类的;或者每个请求,通过 headers customer 处理。
|
|
||||||
this.webClient = WebClient.builder()
|
|
||||||
.baseUrl(baseUrl)
|
|
||||||
.build();
|
|
||||||
this.appId = appId;
|
this.appId = appId;
|
||||||
this.apiSecret = apiSecret;
|
this.apiSecret = apiSecret;
|
||||||
|
this.webClient = WebClient.builder()
|
||||||
|
.baseUrl(BASE_URL)
|
||||||
|
.defaultHeaders((headers) -> {
|
||||||
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
headers.add(HEADER_APP_ID, appId);
|
||||||
|
})
|
||||||
|
.build();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -72,7 +74,7 @@ public class XunfeiPptApi {
|
||||||
long timestamp = System.currentTimeMillis() / 1000;
|
long timestamp = System.currentTimeMillis() / 1000;
|
||||||
String ts = String.valueOf(timestamp);
|
String ts = String.valueOf(timestamp);
|
||||||
String signature = generateSignature(appId, apiSecret, timestamp);
|
String signature = generateSignature(appId, apiSecret, timestamp);
|
||||||
return new SignatureInfo(appId, ts, signature);
|
return new SignatureInfo(ts, signature);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -84,43 +86,8 @@ public class XunfeiPptApi {
|
||||||
* @return 签名
|
* @return 签名
|
||||||
*/
|
*/
|
||||||
private String generateSignature(String appId, String apiSecret, long timestamp) {
|
private String generateSignature(String appId, String apiSecret, long timestamp) {
|
||||||
try {
|
String auth = SecureUtil.md5(appId + timestamp);
|
||||||
// TODO @新:使用 hutool 简化
|
return SecureUtil.hmac(HmacAlgorithm.HmacSHA1, apiSecret).digestBase64(auth, false);
|
||||||
String auth = md5(appId + timestamp);
|
|
||||||
return hmacSHA1Encrypt(auth, apiSecret);
|
|
||||||
} catch (NoSuchAlgorithmException | InvalidKeyException e) {
|
|
||||||
log.error("[xunfei-ppt-api] 生成签名失败", e);
|
|
||||||
throw new IllegalStateException("[xunfei-ppt-api] 生成签名失败");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* HMAC SHA1 加密
|
|
||||||
*/
|
|
||||||
private String hmacSHA1Encrypt(String encryptText, String encryptKey)
|
|
||||||
throws NoSuchAlgorithmException, InvalidKeyException {
|
|
||||||
SecretKeySpec keySpec = new SecretKeySpec(
|
|
||||||
encryptKey.getBytes(StandardCharsets.UTF_8), "HmacSHA1");
|
|
||||||
|
|
||||||
Mac mac = Mac.getInstance("HmacSHA1");
|
|
||||||
mac.init(keySpec);
|
|
||||||
byte[] result = mac.doFinal(encryptText.getBytes(StandardCharsets.UTF_8));
|
|
||||||
|
|
||||||
return Base64.getEncoder().encodeToString(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* MD5 哈希
|
|
||||||
*/
|
|
||||||
private String md5(String text) throws NoSuchAlgorithmException {
|
|
||||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
|
||||||
byte[] digest = md.digest(text.getBytes(StandardCharsets.UTF_8));
|
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
for (byte b : digest) {
|
|
||||||
sb.append(String.format("%02x", b));
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -134,13 +101,11 @@ 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);
|
||||||
// TODO @新:可以使用 ObjUtil.defaultIfNull
|
requestBody.put("pageSize", ObjUtil.defaultIfNull(pageSize, 20));
|
||||||
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(HEADER_TIMESTAMP, signInfo.timestamp)
|
||||||
.header("timestamp", signInfo.timestamp)
|
.header(HEADER_SIGNATURE, signInfo.signature)
|
||||||
.header("signature", signInfo.signature)
|
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
.bodyValue(requestBody)
|
.bodyValue(requestBody)
|
||||||
.retrieve()
|
.retrieve()
|
||||||
|
@ -161,9 +126,8 @@ public class XunfeiPptApi {
|
||||||
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(HEADER_TIMESTAMP, signInfo.timestamp)
|
||||||
.header("timestamp", signInfo.timestamp)
|
.header(HEADER_SIGNATURE, signInfo.signature)
|
||||||
.header("signature", signInfo.signature)
|
|
||||||
.contentType(MediaType.MULTIPART_FORM_DATA)
|
.contentType(MediaType.MULTIPART_FORM_DATA)
|
||||||
.body(BodyInserters.fromMultipartData(formData))
|
.body(BodyInserters.fromMultipartData(formData))
|
||||||
.retrieve()
|
.retrieve()
|
||||||
|
@ -207,12 +171,11 @@ 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 = buildCreatePptFormData(request);
|
||||||
return this.webClient.post()
|
return this.webClient.post()
|
||||||
.uri("/create")
|
.uri("/create")
|
||||||
.header("appId", signInfo.appId)
|
.header(HEADER_TIMESTAMP, signInfo.timestamp)
|
||||||
.header("timestamp", signInfo.timestamp)
|
.header(HEADER_SIGNATURE, signInfo.signature)
|
||||||
.header("signature", signInfo.signature)
|
|
||||||
.contentType(MediaType.MULTIPART_FORM_DATA)
|
.contentType(MediaType.MULTIPART_FORM_DATA)
|
||||||
.body(BodyInserters.fromMultipartData(formData))
|
.body(BodyInserters.fromMultipartData(formData))
|
||||||
.retrieve()
|
.retrieve()
|
||||||
|
@ -247,9 +210,8 @@ public class XunfeiPptApi {
|
||||||
SignatureInfo signInfo = getSignature();
|
SignatureInfo signInfo = getSignature();
|
||||||
return this.webClient.post()
|
return this.webClient.post()
|
||||||
.uri("/createPptByOutline")
|
.uri("/createPptByOutline")
|
||||||
.header("appId", signInfo.appId)
|
.header(HEADER_TIMESTAMP, signInfo.timestamp)
|
||||||
.header("timestamp", signInfo.timestamp)
|
.header(HEADER_SIGNATURE, signInfo.signature)
|
||||||
.header("signature", signInfo.signature)
|
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
.bodyValue(request)
|
.bodyValue(request)
|
||||||
.retrieve()
|
.retrieve()
|
||||||
|
@ -271,9 +233,8 @@ public class XunfeiPptApi {
|
||||||
.path("/progress")
|
.path("/progress")
|
||||||
.queryParam("sid", sid)
|
.queryParam("sid", sid)
|
||||||
.build())
|
.build())
|
||||||
.header("appId", signInfo.appId)
|
.header(HEADER_TIMESTAMP, signInfo.timestamp)
|
||||||
.header("timestamp", signInfo.timestamp)
|
.header(HEADER_SIGNATURE, signInfo.signature)
|
||||||
.header("signature", signInfo.signature)
|
|
||||||
.retrieve()
|
.retrieve()
|
||||||
.onStatus(STATUS_PREDICATE, EXCEPTION_FUNCTION.apply(sid))
|
.onStatus(STATUS_PREDICATE, EXCEPTION_FUNCTION.apply(sid))
|
||||||
.bodyToMono(ProgressResponse.class)
|
.bodyToMono(ProgressResponse.class)
|
||||||
|
@ -285,10 +246,10 @@ public class XunfeiPptApi {
|
||||||
*/
|
*/
|
||||||
@JsonInclude(value = JsonInclude.Include.NON_NULL)
|
@JsonInclude(value = JsonInclude.Include.NON_NULL)
|
||||||
private record SignatureInfo(
|
private record SignatureInfo(
|
||||||
String appId,
|
|
||||||
String timestamp,
|
String timestamp,
|
||||||
String signature
|
String signature
|
||||||
) { }
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 模板列表响应
|
* 模板列表响应
|
||||||
|
@ -300,7 +261,8 @@ public class XunfeiPptApi {
|
||||||
String desc,
|
String desc,
|
||||||
Integer count,
|
Integer count,
|
||||||
TemplatePageData data
|
TemplatePageData data
|
||||||
) { }
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 模板列表数据
|
* 模板列表数据
|
||||||
|
@ -310,7 +272,8 @@ public class XunfeiPptApi {
|
||||||
String total,
|
String total,
|
||||||
List<TemplateInfo> records,
|
List<TemplateInfo> records,
|
||||||
Integer pageNum
|
Integer pageNum
|
||||||
) { }
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 模板信息
|
* 模板信息
|
||||||
|
@ -324,7 +287,8 @@ public class XunfeiPptApi {
|
||||||
String industry,
|
String industry,
|
||||||
String style,
|
String style,
|
||||||
String detailImage
|
String detailImage
|
||||||
) { }
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建响应
|
* 创建响应
|
||||||
|
@ -336,7 +300,8 @@ public class XunfeiPptApi {
|
||||||
String desc,
|
String desc,
|
||||||
Integer count,
|
Integer count,
|
||||||
CreateResponseData data
|
CreateResponseData data
|
||||||
) { }
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建响应数据
|
* 创建响应数据
|
||||||
|
@ -348,7 +313,8 @@ public class XunfeiPptApi {
|
||||||
String title,
|
String title,
|
||||||
String subTitle,
|
String subTitle,
|
||||||
OutlineData outline
|
OutlineData outline
|
||||||
) { }
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 大纲数据结构
|
* 大纲数据结构
|
||||||
|
@ -375,7 +341,8 @@ public class XunfeiPptApi {
|
||||||
@JsonInclude(value = JsonInclude.Include.NON_NULL)
|
@JsonInclude(value = JsonInclude.Include.NON_NULL)
|
||||||
public record ChapterContent(
|
public record ChapterContent(
|
||||||
String chapterTitle
|
String chapterTitle
|
||||||
) { }
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -397,7 +364,8 @@ public class XunfeiPptApi {
|
||||||
int code,
|
int code,
|
||||||
String desc,
|
String desc,
|
||||||
ProgressResponseData data
|
ProgressResponseData data
|
||||||
) { }
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 进度响应数据
|
* 进度响应数据
|
||||||
|
@ -407,13 +375,12 @@ public class XunfeiPptApi {
|
||||||
int process,
|
int process,
|
||||||
String pptId,
|
String pptId,
|
||||||
String pptUrl,
|
String pptUrl,
|
||||||
// TODO @新:字段注释,去掉
|
String pptStatus,
|
||||||
String pptStatus, // PPT构建状态:building(构建中),done(已完成),build_failed(生成失败)
|
String aiImageStatus,
|
||||||
String aiImageStatus, // ai配图状态:building(构建中),done(已完成)
|
String cardNoteStatus,
|
||||||
String cardNoteStatus, // 演讲备注状态:building(构建中),done(已完成)
|
String errMsg,
|
||||||
String errMsg, // 生成PPT的失败信息
|
Integer totalPages,
|
||||||
Integer totalPages, // 生成PPT的总页数
|
Integer donePages
|
||||||
Integer donePages // 生成PPT的完成页数
|
|
||||||
) {
|
) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -454,6 +421,7 @@ public class XunfeiPptApi {
|
||||||
* 通过大纲创建 PPT 请求参数
|
* 通过大纲创建 PPT 请求参数
|
||||||
*/
|
*/
|
||||||
@JsonInclude(value = JsonInclude.Include.NON_NULL)
|
@JsonInclude(value = JsonInclude.Include.NON_NULL)
|
||||||
|
@Builder
|
||||||
public record CreatePptByOutlineRequest(
|
public record CreatePptByOutlineRequest(
|
||||||
String query, // 用户生成PPT要求(最多8000字)
|
String query, // 用户生成PPT要求(最多8000字)
|
||||||
String outlineSid, // 已生成大纲后,响应返回的请求大纲唯一id
|
String outlineSid, // 已生成大纲后,响应返回的请求大纲唯一id
|
||||||
|
@ -469,109 +437,8 @@ public class XunfeiPptApi {
|
||||||
Boolean isFigure, // 是否自动配图
|
Boolean isFigure, // 是否自动配图
|
||||||
String aiImage // ai配图类型:normal、advanced
|
String aiImage // ai配图类型:normal、advanced
|
||||||
) {
|
) {
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建构建器
|
|
||||||
*
|
|
||||||
* @return 构建器
|
|
||||||
*/
|
|
||||||
public static Builder builder() {
|
|
||||||
return new Builder();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO @新:这个可以用 lombok 简化么?
|
|
||||||
/**
|
|
||||||
* 构建器类
|
|
||||||
*/
|
|
||||||
public static class Builder {
|
|
||||||
|
|
||||||
private String query;
|
|
||||||
private String outlineSid;
|
|
||||||
private OutlineData outline;
|
|
||||||
private String templateId;
|
|
||||||
private String businessId;
|
|
||||||
private String author;
|
|
||||||
private Boolean isCardNote;
|
|
||||||
private Boolean search;
|
|
||||||
private String language;
|
|
||||||
private String fileUrl;
|
|
||||||
private String fileName;
|
|
||||||
private Boolean isFigure;
|
|
||||||
private String aiImage;
|
|
||||||
|
|
||||||
public Builder query(String query) {
|
|
||||||
this.query = query;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder outlineSid(String outlineSid) {
|
|
||||||
this.outlineSid = outlineSid;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder outline(OutlineData outline) {
|
|
||||||
this.outline = outline;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder templateId(String templateId) {
|
|
||||||
this.templateId = templateId;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder businessId(String businessId) {
|
|
||||||
this.businessId = businessId;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder author(String author) {
|
|
||||||
this.author = author;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder isCardNote(Boolean isCardNote) {
|
|
||||||
this.isCardNote = isCardNote;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder search(Boolean search) {
|
|
||||||
this.search = search;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder language(String language) {
|
|
||||||
this.language = language;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder fileUrl(String fileUrl) {
|
|
||||||
this.fileUrl = fileUrl;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder fileName(String fileName) {
|
|
||||||
this.fileName = fileName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder isFigure(Boolean isFigure) {
|
|
||||||
this.isFigure = isFigure;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder aiImage(String aiImage) {
|
|
||||||
this.aiImage = aiImage;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CreatePptByOutlineRequest build() {
|
|
||||||
return new CreatePptByOutlineRequest(
|
|
||||||
query, outlineSid, outline, templateId, businessId, author,
|
|
||||||
isCardNote, search, language, fileUrl, fileName, isFigure, aiImage
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建创建 PPT 的表单数据
|
* 构建创建 PPT 的表单数据
|
||||||
|
@ -579,12 +446,8 @@ public class XunfeiPptApi {
|
||||||
* @param request 请求参数
|
* @param request 请求参数
|
||||||
* @return 表单数据
|
* @return 表单数据
|
||||||
*/
|
*/
|
||||||
private MultiValueMap<String, Object> buildCreateFormData(CreatePptRequest request) {
|
private MultiValueMap<String, Object> buildCreatePptFormData(CreatePptRequest request) {
|
||||||
MultiValueMap<String, Object> formData = new LinkedMultiValueMap<>();
|
MultiValueMap<String, Object> formData = new LinkedMultiValueMap<>();
|
||||||
// 添加请求参数
|
|
||||||
if (request.query() != null) {
|
|
||||||
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()) {
|
||||||
|
@ -594,48 +457,51 @@ public class XunfeiPptApi {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("[xunfei-ppt-api] 文件处理失败", e);
|
log.error("[XunFeiPptApi] 文件处理失败", e);
|
||||||
throw new IllegalStateException("[xunfei-ppt-api] 文件处理失败", e);
|
throw new IllegalStateException("[XunFeiPptApi] 文件处理失败", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO @新:要不搞个 MapUtil.addIfPresent 方法?
|
Map<String, Object> param = new HashMap<>();
|
||||||
if (request.fileUrl() != null) {
|
addIfPresent(param, "query", request.query());
|
||||||
formData.add("fileUrl", request.fileUrl());
|
addIfPresent(param, "fileUrl", request.fileUrl());
|
||||||
}
|
addIfPresent(param, "fileName", request.fileName());
|
||||||
if (request.fileName() != null) {
|
addIfPresent(param, "templateId", request.templateId());
|
||||||
formData.add("fileName", request.fileName());
|
addIfPresent(param, "businessId", request.businessId());
|
||||||
}
|
addIfPresent(param, "author", request.author());
|
||||||
if (request.templateId() != null) {
|
addIfPresent(param, "isCardNote", request.isCardNote());
|
||||||
formData.add("templateId", request.templateId());
|
addIfPresent(param, "search", request.search());
|
||||||
}
|
addIfPresent(param, "language", request.language());
|
||||||
if (request.businessId() != null) {
|
addIfPresent(param, "isFigure", request.isFigure());
|
||||||
formData.add("businessId", request.businessId());
|
addIfPresent(param, "aiImage", request.aiImage());
|
||||||
}
|
param.forEach(formData::add);
|
||||||
if (request.author() != null) {
|
|
||||||
formData.add("author", request.author());
|
|
||||||
}
|
|
||||||
if (request.isCardNote() != null) {
|
|
||||||
formData.add("isCardNote", request.isCardNote().toString());
|
|
||||||
}
|
|
||||||
if (request.search() != null) {
|
|
||||||
formData.add("search", request.search().toString());
|
|
||||||
}
|
|
||||||
if (request.language() != null) {
|
|
||||||
formData.add("language", request.language());
|
|
||||||
}
|
|
||||||
if (request.isFigure() != null) {
|
|
||||||
formData.add("isFigure", request.isFigure().toString());
|
|
||||||
}
|
|
||||||
if (request.aiImage() != null) {
|
|
||||||
formData.add("aiImage", request.aiImage());
|
|
||||||
}
|
|
||||||
return formData;
|
return formData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <K, V> void addIfPresent(Map<K, V> map, K key, V value) {
|
||||||
|
if (ObjUtil.isNull(key) || ObjUtil.isNull(map)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isPresent = false;
|
||||||
|
if (ObjUtil.isNotNull(value)) {
|
||||||
|
if (value instanceof String) {
|
||||||
|
// 字符串:需要有实际内容
|
||||||
|
isPresent = StringUtils.hasText((String) value);
|
||||||
|
} else {
|
||||||
|
// 其他类型:非 null 即视为存在
|
||||||
|
isPresent = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isPresent) {
|
||||||
|
map.put(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 直接生成PPT请求参数
|
* 直接生成PPT请求参数
|
||||||
*/
|
*/
|
||||||
@JsonInclude(value = JsonInclude.Include.NON_NULL)
|
@JsonInclude(value = JsonInclude.Include.NON_NULL)
|
||||||
|
@Builder
|
||||||
public record CreatePptRequest(
|
public record CreatePptRequest(
|
||||||
String query, // 用户生成PPT要求(最多8000字)
|
String query, // 用户生成PPT要求(最多8000字)
|
||||||
MultipartFile file, // 上传文件
|
MultipartFile file, // 上传文件
|
||||||
|
@ -651,109 +517,6 @@ public class XunfeiPptApi {
|
||||||
String aiImage // ai配图类型:normal、advanced
|
String aiImage // ai配图类型:normal、advanced
|
||||||
) {
|
) {
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建构建器
|
|
||||||
*
|
|
||||||
* @return 构建器
|
|
||||||
*/
|
|
||||||
public static Builder builder() {
|
|
||||||
return new Builder();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 构建器类
|
|
||||||
*/
|
|
||||||
public static class Builder {
|
|
||||||
|
|
||||||
private String query;
|
|
||||||
private MultipartFile file;
|
|
||||||
private String fileUrl;
|
|
||||||
private String fileName;
|
|
||||||
private String templateId;
|
|
||||||
private String businessId;
|
|
||||||
private String author;
|
|
||||||
private Boolean isCardNote;
|
|
||||||
private Boolean search;
|
|
||||||
private String language;
|
|
||||||
private Boolean isFigure;
|
|
||||||
private String aiImage;
|
|
||||||
|
|
||||||
// TODO @新:这个可以用 lombok 简化么?
|
|
||||||
|
|
||||||
public Builder query(String query) {
|
|
||||||
this.query = query;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder file(MultipartFile file) {
|
|
||||||
this.file = file;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder fileUrl(String fileUrl) {
|
|
||||||
this.fileUrl = fileUrl;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder fileName(String fileName) {
|
|
||||||
this.fileName = fileName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder templateId(String templateId) {
|
|
||||||
this.templateId = templateId;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder businessId(String businessId) {
|
|
||||||
this.businessId = businessId;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder author(String author) {
|
|
||||||
this.author = author;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder isCardNote(Boolean isCardNote) {
|
|
||||||
this.isCardNote = isCardNote;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder search(Boolean search) {
|
|
||||||
this.search = search;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder language(String language) {
|
|
||||||
this.language = language;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder isFigure(Boolean isFigure) {
|
|
||||||
this.isFigure = isFigure;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder aiImage(String aiImage) {
|
|
||||||
this.aiImage = aiImage;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CreatePptRequest build() {
|
|
||||||
// 验证参数
|
|
||||||
if (query == null && file == null && fileUrl == null) {
|
|
||||||
throw new IllegalArgumentException("query、file、fileUrl必填其一");
|
|
||||||
}
|
|
||||||
if ((file != null || fileUrl != null) && fileName == null) {
|
|
||||||
throw new IllegalArgumentException("如果传file或者fileUrl,fileName必填");
|
|
||||||
}
|
|
||||||
return new CreatePptRequest(
|
|
||||||
query, file, fileUrl, fileName, templateId, businessId, author,
|
|
||||||
isCardNote, search, language, isFigure, aiImage
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,122 @@
|
||||||
|
package cn.iocoder.yudao.framework.ai.mcp;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.ai.core.model.doubao.DouBaoChatModel;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.ai.chat.client.ChatClient;
|
||||||
|
import org.springframework.ai.openai.OpenAiChatModel;
|
||||||
|
import org.springframework.ai.openai.OpenAiChatOptions;
|
||||||
|
import org.springframework.ai.openai.api.OpenAiApi;
|
||||||
|
import org.springframework.ai.tool.annotation.Tool;
|
||||||
|
import org.springframework.ai.tool.method.MethodToolCallbackProvider;
|
||||||
|
|
||||||
|
public class DouBaoMcpTests {
|
||||||
|
|
||||||
|
private final OpenAiChatModel openAiChatModel = OpenAiChatModel.builder()
|
||||||
|
.openAiApi(OpenAiApi.builder()
|
||||||
|
.baseUrl(DouBaoChatModel.BASE_URL)
|
||||||
|
.apiKey("5c1b5747-26d2-4ebd-a4e0-dd0e8d8b4272") // apiKey
|
||||||
|
.build())
|
||||||
|
.defaultOptions(OpenAiChatOptions.builder()
|
||||||
|
.model("doubao-1-5-lite-32k-250115") // 模型(doubao)
|
||||||
|
.temperature(0.7)
|
||||||
|
.build())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
private final DouBaoChatModel chatModel = new DouBaoChatModel(openAiChatModel);
|
||||||
|
|
||||||
|
private final MethodToolCallbackProvider provider = MethodToolCallbackProvider.builder()
|
||||||
|
.toolObjects(new UserService())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
private final ChatClient chatClient = ChatClient.builder(chatModel)
|
||||||
|
.defaultTools(provider)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMcpGetUserInfo() {
|
||||||
|
|
||||||
|
// 打印结果
|
||||||
|
System.out.println(chatClient.prompt()
|
||||||
|
.user("目前有哪些工具可以使用")
|
||||||
|
.call()
|
||||||
|
.content());
|
||||||
|
System.out.println("====================================");
|
||||||
|
// 打印结果
|
||||||
|
System.out.println(chatClient.prompt()
|
||||||
|
.user("小新的年龄是多少")
|
||||||
|
.call()
|
||||||
|
.content());
|
||||||
|
System.out.println("====================================");
|
||||||
|
// 打印结果
|
||||||
|
System.out.println(chatClient.prompt()
|
||||||
|
.user("获取小新的基本信息")
|
||||||
|
.call()
|
||||||
|
.content());
|
||||||
|
System.out.println("====================================");
|
||||||
|
// 打印结果
|
||||||
|
System.out.println(chatClient.prompt()
|
||||||
|
.user("小新是什么职业的")
|
||||||
|
.call()
|
||||||
|
.content());
|
||||||
|
System.out.println("====================================");
|
||||||
|
// 打印结果
|
||||||
|
System.out.println(chatClient.prompt()
|
||||||
|
.user("小新的教育背景")
|
||||||
|
.call()
|
||||||
|
.content());
|
||||||
|
System.out.println("====================================");
|
||||||
|
// 打印结果
|
||||||
|
System.out.println(chatClient.prompt()
|
||||||
|
.user("小新的兴趣爱好是什么")
|
||||||
|
.call()
|
||||||
|
.content());
|
||||||
|
System.out.println("====================================");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static class UserService {
|
||||||
|
|
||||||
|
@Tool(name = "getUserAge", description = "获取用户年龄")
|
||||||
|
public String getUserAge(String userName) {
|
||||||
|
return "《" + userName + "》的年龄为:18";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Tool(name = "getUserSex", description = "获取用户性别")
|
||||||
|
public String getUserSex(String userName) {
|
||||||
|
return "《" + userName + "》的性别为:男";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Tool(name = "getUserBasicInfo", description = "获取用户基本信息,包括姓名、年龄、性别等")
|
||||||
|
public String getUserBasicInfo(String userName) {
|
||||||
|
return "《" + userName + "》的基本信息:\n姓名:" + userName + "\n年龄:18\n性别:男\n身高:175cm\n体重:65kg";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Tool(name = "getUserContact", description = "获取用户联系方式,包括电话、邮箱等")
|
||||||
|
public String getUserContact(String userName) {
|
||||||
|
return "《" + userName + "》的联系方式:\n电话:138****1234\n邮箱:" + userName.toLowerCase() + "@example.com\nQQ:123456789";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Tool(name = "getUserAddress", description = "获取用户地址信息")
|
||||||
|
public String getUserAddress(String userName) {
|
||||||
|
return "《" + userName + "》的地址信息:北京市朝阳区科技园区88号";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Tool(name = "getUserJob", description = "获取用户职业信息")
|
||||||
|
public String getUserJob(String userName) {
|
||||||
|
return "《" + userName + "》的职业信息:软件工程师,就职于ABC科技有限公司,工作年限5年";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Tool(name = "getUserHobbies", description = "获取用户兴趣爱好")
|
||||||
|
public String getUserHobbies(String userName) {
|
||||||
|
return "《" + userName + "》的兴趣爱好:编程、阅读、旅游、摄影、打篮球";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Tool(name = "getUserEducation", description = "获取用户教育背景")
|
||||||
|
public String getUserEducation(String userName) {
|
||||||
|
return "《" + userName + "》的教育背景:\n本科:计算机科学与技术专业,北京大学\n硕士:软件工程专业,清华大学";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
package cn.iocoder.yudao.framework.ai.ppt.wdd;
|
package cn.iocoder.yudao.framework.ai.ppt.wdd;
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.ai.core.model.wenduoduo.api.WddPptApi;
|
import cn.iocoder.yudao.framework.ai.core.model.wenduoduo.api.WenDuoDuoPptApi;
|
||||||
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
||||||
import org.junit.jupiter.api.Disabled;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
@ -10,24 +10,23 @@ import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link WddPptApi} 集成测试
|
* {@link WenDuoDuoPptApi} 集成测试
|
||||||
*
|
*
|
||||||
* @author xiaoxin
|
* @author xiaoxin
|
||||||
*/
|
*/
|
||||||
public class WddPptApiTests {
|
public class WenDuoDuoPptApiTests {
|
||||||
|
|
||||||
private final WddPptApi wddPptApi = new WddPptApi("https://docmee.cn");
|
|
||||||
|
|
||||||
private final String token = ""; // API Token
|
private final String token = ""; // API Token
|
||||||
|
private final WenDuoDuoPptApi wenDuoDuoPptApi = new WenDuoDuoPptApi(token);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Disabled
|
@Disabled
|
||||||
public void testCreateApiToken() {
|
public void testCreateApiToken() {
|
||||||
// 准备参数
|
// 准备参数
|
||||||
String apiKey = "";
|
String apiKey = "";
|
||||||
WddPptApi.CreateTokenRequest request = new WddPptApi.CreateTokenRequest(apiKey);
|
WenDuoDuoPptApi.CreateTokenRequest request = new WenDuoDuoPptApi.CreateTokenRequest(apiKey);
|
||||||
// 调用方法
|
// 调用方法
|
||||||
String token = wddPptApi.createApiToken(request);
|
String token = wenDuoDuoPptApi.createApiToken(request);
|
||||||
// 打印结果
|
// 打印结果
|
||||||
System.out.println(token);
|
System.out.println(token);
|
||||||
}
|
}
|
||||||
|
@ -38,7 +37,7 @@ public class WddPptApiTests {
|
||||||
@Test
|
@Test
|
||||||
@Disabled
|
@Disabled
|
||||||
public void testCreateTask() {
|
public void testCreateTask() {
|
||||||
WddPptApi.ApiResponse apiResponse = wddPptApi.createTask(token, 1, "dify 介绍", null);
|
WenDuoDuoPptApi.ApiResponse apiResponse = wenDuoDuoPptApi.createTask(1, "dify 介绍", null);
|
||||||
System.out.println(apiResponse);
|
System.out.println(apiResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,10 +45,10 @@ public class WddPptApiTests {
|
||||||
@Test // 创建大纲
|
@Test // 创建大纲
|
||||||
@Disabled
|
@Disabled
|
||||||
public void testGenerateOutlineRequest() {
|
public void testGenerateOutlineRequest() {
|
||||||
WddPptApi.CreateOutlineRequest request = new WddPptApi.CreateOutlineRequest(
|
WenDuoDuoPptApi.CreateOutlineRequest request = new WenDuoDuoPptApi.CreateOutlineRequest(
|
||||||
"1901539019628613632", "medium", null, null, null, null);
|
"1901539019628613632", "medium", null, null, null, null);
|
||||||
// 调用
|
// 调用
|
||||||
Flux<Map<String, Object>> flux = wddPptApi.createOutline(token, request);
|
Flux<Map<String, Object>> flux = wenDuoDuoPptApi.createOutline(request);
|
||||||
StringBuffer contentBuffer = new StringBuffer();
|
StringBuffer contentBuffer = new StringBuffer();
|
||||||
flux.doOnNext(chunk -> {
|
flux.doOnNext(chunk -> {
|
||||||
contentBuffer.append(chunk.get("text"));
|
contentBuffer.append(chunk.get("text"));
|
||||||
|
@ -69,10 +68,10 @@ public class WddPptApiTests {
|
||||||
@Test
|
@Test
|
||||||
@Disabled
|
@Disabled
|
||||||
public void testUpdateOutlineRequest() {
|
public void testUpdateOutlineRequest() {
|
||||||
WddPptApi.UpdateOutlineRequest request = new WddPptApi.UpdateOutlineRequest(
|
WenDuoDuoPptApi.UpdateOutlineRequest request = new WenDuoDuoPptApi.UpdateOutlineRequest(
|
||||||
"1901539019628613632", TEST_OUT_LINE_CONTENT, "精简一点,三个章节即可");
|
"1901539019628613632", TEST_OUT_LINE_CONTENT, "精简一点,三个章节即可");
|
||||||
// 调用
|
// 调用
|
||||||
Flux<Map<String, Object>> flux = wddPptApi.updateOutline(token, request);
|
Flux<Map<String, Object>> flux = wenDuoDuoPptApi.updateOutline(request);
|
||||||
StringBuffer contentBuffer = new StringBuffer();
|
StringBuffer contentBuffer = new StringBuffer();
|
||||||
flux.doOnNext(chunk -> {
|
flux.doOnNext(chunk -> {
|
||||||
contentBuffer.append(chunk.get("text"));
|
contentBuffer.append(chunk.get("text"));
|
||||||
|
@ -94,11 +93,11 @@ public class WddPptApiTests {
|
||||||
@Disabled
|
@Disabled
|
||||||
public void testGetPptTemplatePage() {
|
public void testGetPptTemplatePage() {
|
||||||
// 准备参数
|
// 准备参数
|
||||||
WddPptApi.TemplateQueryRequest.Filter filter = new WddPptApi.TemplateQueryRequest.Filter(
|
WenDuoDuoPptApi.TemplateQueryRequest.Filter filter = new WenDuoDuoPptApi.TemplateQueryRequest.Filter(
|
||||||
1, null, null, null);
|
1, null, null, null);
|
||||||
WddPptApi.TemplateQueryRequest request = new WddPptApi.TemplateQueryRequest(1, 10, filter);
|
WenDuoDuoPptApi.TemplateQueryRequest request = new WenDuoDuoPptApi.TemplateQueryRequest(1, 10, filter);
|
||||||
// 调用
|
// 调用
|
||||||
WddPptApi.PagePptTemplateInfo pptTemplatePage = wddPptApi.getTemplatePage(token, request);
|
WenDuoDuoPptApi.PagePptTemplateInfo pptTemplatePage = wenDuoDuoPptApi.getTemplatePage(request);
|
||||||
// 打印结果
|
// 打印结果
|
||||||
System.out.println(pptTemplatePage);
|
System.out.println(pptTemplatePage);
|
||||||
}
|
}
|
||||||
|
@ -110,9 +109,9 @@ public class WddPptApiTests {
|
||||||
@Disabled
|
@Disabled
|
||||||
public void testGeneratePptx() {
|
public void testGeneratePptx() {
|
||||||
// 准备参数
|
// 准备参数
|
||||||
WddPptApi.CreatePptRequest request = new WddPptApi.CreatePptRequest("1901539019628613632", "1805081814809960448", TEST_OUT_LINE_CONTENT);
|
WenDuoDuoPptApi.PptCreateRequest request = new WenDuoDuoPptApi.PptCreateRequest("1901539019628613632", "1805081814809960448", TEST_OUT_LINE_CONTENT);
|
||||||
// 调用
|
// 调用
|
||||||
WddPptApi.PptInfo pptInfo = wddPptApi.create(token, request);
|
WenDuoDuoPptApi.PptInfo pptInfo = wenDuoDuoPptApi.create(request);
|
||||||
// 打印结果
|
// 打印结果
|
||||||
System.out.println(pptInfo);
|
System.out.println(pptInfo);
|
||||||
}
|
}
|
||||||
|
@ -309,6 +308,7 @@ public class WddPptApiTests {
|
||||||
#### 7.2.2 合作共赢
|
#### 7.2.2 合作共赢
|
||||||
期待与更多的企业和机构合作,共同推动AI技术的应用。
|
期待与更多的企业和机构合作,共同推动AI技术的应用。
|
||||||
#### 7.2.3 共创未来
|
#### 7.2.3 共创未来
|
||||||
让我们一起用AI技术改变世界,共创美好未来。""";
|
让我们一起用AI技术改变世界,共创美好未来。
|
||||||
|
""";
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
package cn.iocoder.yudao.framework.ai.ppt.xunfei;
|
package cn.iocoder.yudao.framework.ai.ppt.xunfei;
|
||||||
|
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
import cn.iocoder.yudao.framework.ai.core.model.xinghuo.api.XunfeiPptApi;
|
import cn.iocoder.yudao.framework.ai.core.model.xinghuo.api.XunFeiPptApi;
|
||||||
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
||||||
import org.junit.jupiter.api.Disabled;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
@ -11,17 +11,17 @@ import org.springframework.web.multipart.MultipartFile;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link XunfeiPptApi} 集成测试
|
* {@link XunFeiPptApi} 集成测试
|
||||||
*
|
*
|
||||||
* @author xiaoxin
|
* @author xiaoxin
|
||||||
*/
|
*/
|
||||||
public class XunfeiPptApiTests {
|
public class XunFeiPptApiTests {
|
||||||
|
|
||||||
// 讯飞 API 配置信息,实际使用时请替换为您的应用信息
|
// 讯飞 API 配置信息,实际使用时请替换为您的应用信息
|
||||||
private static final String APP_ID = "";
|
private static final String APP_ID = "6c8ac023";
|
||||||
private static final String API_SECRET = "";
|
private static final String API_SECRET = "Y2RjM2Q1MWJjZTdkYmFiODc0OGE5NmRk";
|
||||||
|
|
||||||
private final XunfeiPptApi xunfeiPptApi = new XunfeiPptApi(XunfeiPptApi.BASE_URL, APP_ID, API_SECRET);
|
private final XunFeiPptApi xunfeiPptApi = new XunFeiPptApi(APP_ID, API_SECRET);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取 PPT 模板列表
|
* 获取 PPT 模板列表
|
||||||
|
@ -30,7 +30,7 @@ public class XunfeiPptApiTests {
|
||||||
@Disabled
|
@Disabled
|
||||||
public void testGetTemplatePage() {
|
public void testGetTemplatePage() {
|
||||||
// 调用方法
|
// 调用方法
|
||||||
XunfeiPptApi.TemplatePageResponse response = xunfeiPptApi.getTemplatePage("商务", 10);
|
XunFeiPptApi.TemplatePageResponse response = xunfeiPptApi.getTemplatePage("商务", 10);
|
||||||
// 打印结果
|
// 打印结果
|
||||||
System.out.println("模板列表响应:" + JsonUtils.toJsonString(response));
|
System.out.println("模板列表响应:" + JsonUtils.toJsonString(response));
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ public class XunfeiPptApiTests {
|
||||||
|
|
||||||
// 打印第一个模板的信息(如果存在)
|
// 打印第一个模板的信息(如果存在)
|
||||||
if (!response.data().records().isEmpty()) {
|
if (!response.data().records().isEmpty()) {
|
||||||
XunfeiPptApi.TemplateInfo firstTemplate = response.data().records().get(0);
|
XunFeiPptApi.TemplateInfo firstTemplate = response.data().records().get(0);
|
||||||
System.out.println("模板ID:" + firstTemplate.templateIndexId());
|
System.out.println("模板ID:" + firstTemplate.templateIndexId());
|
||||||
System.out.println("模板风格:" + firstTemplate.style());
|
System.out.println("模板风格:" + firstTemplate.style());
|
||||||
System.out.println("模板颜色:" + firstTemplate.color());
|
System.out.println("模板颜色:" + firstTemplate.color());
|
||||||
|
@ -56,7 +56,7 @@ public class XunfeiPptApiTests {
|
||||||
@Test
|
@Test
|
||||||
@Disabled
|
@Disabled
|
||||||
public void testCreateOutline() {
|
public void testCreateOutline() {
|
||||||
XunfeiPptApi.CreateResponse response = getCreateResponse();
|
XunFeiPptApi.CreateResponse response = getCreateResponse();
|
||||||
// 打印结果
|
// 打印结果
|
||||||
System.out.println("创建大纲响应:" + JsonUtils.toJsonString(response));
|
System.out.println("创建大纲响应:" + JsonUtils.toJsonString(response));
|
||||||
|
|
||||||
|
@ -75,9 +75,10 @@ public class XunfeiPptApiTests {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建大纲(通过文本)
|
* 创建大纲(通过文本)
|
||||||
|
*
|
||||||
* @return 创建大纲响应
|
* @return 创建大纲响应
|
||||||
*/
|
*/
|
||||||
private XunfeiPptApi.CreateResponse getCreateResponse() {
|
private XunFeiPptApi.CreateResponse getCreateResponse() {
|
||||||
String param = "智能体平台 Dify 介绍";
|
String param = "智能体平台 Dify 介绍";
|
||||||
return xunfeiPptApi.createOutline(param);
|
return xunfeiPptApi.createOutline(param);
|
||||||
}
|
}
|
||||||
|
@ -89,9 +90,9 @@ public class XunfeiPptApiTests {
|
||||||
@Disabled
|
@Disabled
|
||||||
public void testCreatePptByOutlineWithFullParams() {
|
public void testCreatePptByOutlineWithFullParams() {
|
||||||
// 创建大纲对象
|
// 创建大纲对象
|
||||||
XunfeiPptApi.CreateResponse createResponse = getCreateResponse();
|
XunFeiPptApi.CreateResponse createResponse = getCreateResponse();
|
||||||
// 调用方法
|
// 调用方法
|
||||||
XunfeiPptApi.CreateResponse response = xunfeiPptApi.createPptByOutline(createResponse.data().outline(), "精简一些,不要超过6个章节");
|
XunFeiPptApi.CreateResponse response = xunfeiPptApi.createPptByOutline(createResponse.data().outline(), "精简一些,不要超过6个章节");
|
||||||
// 打印结果
|
// 打印结果
|
||||||
System.out.println("通过大纲创建 PPT 响应:" + JsonUtils.toJsonString(response));
|
System.out.println("通过大纲创建 PPT 响应:" + JsonUtils.toJsonString(response));
|
||||||
|
|
||||||
|
@ -114,13 +115,13 @@ public class XunfeiPptApiTests {
|
||||||
String sid = "e96dac09f2ec4ee289f029a5fb874ecd"; // 替换为实际的sid
|
String sid = "e96dac09f2ec4ee289f029a5fb874ecd"; // 替换为实际的sid
|
||||||
|
|
||||||
// 调用方法
|
// 调用方法
|
||||||
XunfeiPptApi.ProgressResponse response = xunfeiPptApi.checkProgress(sid);
|
XunFeiPptApi.ProgressResponse response = xunfeiPptApi.checkProgress(sid);
|
||||||
// 打印结果
|
// 打印结果
|
||||||
System.out.println("检查进度响应:" + JsonUtils.toJsonString(response));
|
System.out.println("检查进度响应:" + JsonUtils.toJsonString(response));
|
||||||
|
|
||||||
// 安全地访问响应数据
|
// 安全地访问响应数据
|
||||||
if (response != null && response.data() != null) {
|
if (response != null && response.data() != null) {
|
||||||
XunfeiPptApi.ProgressResponseData data = response.data();
|
XunFeiPptApi.ProgressResponseData data = response.data();
|
||||||
|
|
||||||
// 打印PPT生成状态
|
// 打印PPT生成状态
|
||||||
System.out.println("PPT 构建状态: " + data.pptStatus());
|
System.out.println("PPT 构建状态: " + data.pptStatus());
|
||||||
|
@ -160,7 +161,7 @@ public class XunfeiPptApiTests {
|
||||||
@Disabled
|
@Disabled
|
||||||
public void testPollCheckProgress() throws InterruptedException {
|
public void testPollCheckProgress() throws InterruptedException {
|
||||||
// 准备参数 - 使用之前创建 PP T时返回的 sid
|
// 准备参数 - 使用之前创建 PP T时返回的 sid
|
||||||
String sid = "fa36e926f2ed434987fcb4c1f0776ffb"; // 替换为实际的sid
|
String sid = "1690ef6ee0344e72b5c5434f403b8eaa"; // 替换为实际的sid
|
||||||
|
|
||||||
// 最大轮询次数
|
// 最大轮询次数
|
||||||
int maxPolls = 20;
|
int maxPolls = 20;
|
||||||
|
@ -171,11 +172,11 @@ public class XunfeiPptApiTests {
|
||||||
System.out.println("第" + (i + 1) + "次查询进度...");
|
System.out.println("第" + (i + 1) + "次查询进度...");
|
||||||
|
|
||||||
// 调用方法
|
// 调用方法
|
||||||
XunfeiPptApi.ProgressResponse response = xunfeiPptApi.checkProgress(sid);
|
XunFeiPptApi.ProgressResponse response = xunfeiPptApi.checkProgress(sid);
|
||||||
|
|
||||||
// 安全地访问响应数据
|
// 安全地访问响应数据
|
||||||
if (response != null && response.data() != null) {
|
if (response != null && response.data() != null) {
|
||||||
XunfeiPptApi.ProgressResponseData data = response.data();
|
XunFeiPptApi.ProgressResponseData data = response.data();
|
||||||
|
|
||||||
// 打印进度信息
|
// 打印进度信息
|
||||||
System.out.println("PPT 构建状态: " + data.pptStatus());
|
System.out.println("PPT 构建状态: " + data.pptStatus());
|
||||||
|
@ -218,7 +219,7 @@ public class XunfeiPptApiTests {
|
||||||
String query = "合肥天气趋势分析,包括近5年的气温变化、降水量变化、极端天气事件,以及对城市生活的影响";
|
String query = "合肥天气趋势分析,包括近5年的气温变化、降水量变化、极端天气事件,以及对城市生活的影响";
|
||||||
|
|
||||||
// 调用方法
|
// 调用方法
|
||||||
XunfeiPptApi.CreateResponse response = xunfeiPptApi.create(query);
|
XunFeiPptApi.CreateResponse response = xunfeiPptApi.create(query);
|
||||||
// 打印结果
|
// 打印结果
|
||||||
System.out.println("直接创建 PPT 响应:" + JsonUtils.toJsonString(response));
|
System.out.println("直接创建 PPT 响应:" + JsonUtils.toJsonString(response));
|
||||||
|
|
||||||
|
@ -244,7 +245,7 @@ public class XunfeiPptApiTests {
|
||||||
MultipartFile multipartFile = convertFileToMultipartFile(file);
|
MultipartFile multipartFile = convertFileToMultipartFile(file);
|
||||||
|
|
||||||
// 调用方法
|
// 调用方法
|
||||||
XunfeiPptApi.CreateResponse response = xunfeiPptApi.create(multipartFile, file.getName());
|
XunFeiPptApi.CreateResponse response = xunfeiPptApi.create(multipartFile, file.getName());
|
||||||
// 打印结果
|
// 打印结果
|
||||||
System.out.println("通过文件创建PPT响应:" + JsonUtils.toJsonString(response));
|
System.out.println("通过文件创建PPT响应:" + JsonUtils.toJsonString(response));
|
||||||
|
|
||||||
|
@ -269,7 +270,7 @@ public class XunfeiPptApiTests {
|
||||||
String query = "合肥天气趋势分析,包括近 5 年的气温变化、降水量变化、极端天气事件,以及对城市生活的影响";
|
String query = "合肥天气趋势分析,包括近 5 年的气温变化、降水量变化、极端天气事件,以及对城市生活的影响";
|
||||||
|
|
||||||
// 创建请求对象
|
// 创建请求对象
|
||||||
XunfeiPptApi.CreatePptRequest request = XunfeiPptApi.CreatePptRequest.builder()
|
XunFeiPptApi.CreatePptRequest request = XunFeiPptApi.CreatePptRequest.builder()
|
||||||
.query(query)
|
.query(query)
|
||||||
.language("cn")
|
.language("cn")
|
||||||
.isCardNote(true)
|
.isCardNote(true)
|
||||||
|
@ -280,7 +281,7 @@ public class XunfeiPptApiTests {
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// 调用方法
|
// 调用方法
|
||||||
XunfeiPptApi.CreateResponse response = xunfeiPptApi.create(request);
|
XunFeiPptApi.CreateResponse response = xunfeiPptApi.create(request);
|
||||||
// 打印结果
|
// 打印结果
|
||||||
System.out.println("使用完整参数创建 PPT 响应:" + JsonUtils.toJsonString(response));
|
System.out.println("使用完整参数创建 PPT 响应:" + JsonUtils.toJsonString(response));
|
||||||
|
|
||||||
|
@ -296,9 +297,9 @@ public class XunfeiPptApiTests {
|
||||||
|
|
||||||
// 立即查询一次进度
|
// 立即查询一次进度
|
||||||
System.out.println("立即查询进度...");
|
System.out.println("立即查询进度...");
|
||||||
XunfeiPptApi.ProgressResponse progressResponse = xunfeiPptApi.checkProgress(sid);
|
XunFeiPptApi.ProgressResponse progressResponse = xunfeiPptApi.checkProgress(sid);
|
||||||
if (progressResponse != null && progressResponse.data() != null) {
|
if (progressResponse != null && progressResponse.data() != null) {
|
||||||
XunfeiPptApi.ProgressResponseData progressData = progressResponse.data();
|
XunFeiPptApi.ProgressResponseData progressData = progressResponse.data();
|
||||||
System.out.println("PPT 构建状态: " + progressData.pptStatus());
|
System.out.println("PPT 构建状态: " + progressData.pptStatus());
|
||||||
if (progressData.totalPages() != null && progressData.donePages() != null) {
|
if (progressData.totalPages() != null && progressData.donePages() != null) {
|
||||||
System.out.println("完成进度: " + progressData.donePages() + "/" + progressData.totalPages()
|
System.out.println("完成进度: " + progressData.donePages() + "/" + progressData.totalPages()
|
Loading…
Reference in New Issue