Commit acf68b1cec62da862210dae1fd180c15c71fcc12
1 parent
1db3b867
【代码评审】AI:PPT API 的接入
Showing
4 changed files
with
171 additions
and
156 deletions
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/core/model/wenduoduo/api/WddPptApi.java
| @@ -24,11 +24,11 @@ import java.util.Objects; | @@ -24,11 +24,11 @@ import java.util.Objects; | ||
| 24 | import java.util.function.Function; | 24 | import java.util.function.Function; |
| 25 | import java.util.function.Predicate; | 25 | import java.util.function.Predicate; |
| 26 | 26 | ||
| 27 | +// TODO @新:要不改成 WenDuoDuoPptApi | ||
| 27 | /** | 28 | /** |
| 28 | * 文多多 API | 29 | * 文多多 API |
| 29 | - * <p> | ||
| 30 | - * <p> | ||
| 31 | - * * 对接文多多:<a href="https://docmee.cn/open-platform/api">PPT 生成 API</a> | 30 | + * |
| 31 | + * @see <a href="https://docmee.cn/open-platform/api">PPT 生成 API</a> | ||
| 32 | * | 32 | * |
| 33 | * @author xiaoxin | 33 | * @author xiaoxin |
| 34 | */ | 34 | */ |
| @@ -49,14 +49,15 @@ public class WddPptApi { | @@ -49,14 +49,15 @@ public class WddPptApi { | ||
| 49 | sink.error(new IllegalStateException("[wdd-api] 调用失败!")); | 49 | sink.error(new IllegalStateException("[wdd-api] 调用失败!")); |
| 50 | }); | 50 | }); |
| 51 | 51 | ||
| 52 | + // TODO @新:是不是不用 baseUrl 哈 | ||
| 52 | public WddPptApi(String baseUrl) { | 53 | public WddPptApi(String baseUrl) { |
| 53 | this.webClient = WebClient.builder() | 54 | this.webClient = WebClient.builder() |
| 54 | .baseUrl(baseUrl) | 55 | .baseUrl(baseUrl) |
| 56 | + // TODO @新:建议,token 作为 defaultHeader | ||
| 55 | .defaultHeaders((headers) -> headers.setContentType(MediaType.APPLICATION_JSON)) | 57 | .defaultHeaders((headers) -> headers.setContentType(MediaType.APPLICATION_JSON)) |
| 56 | .build(); | 58 | .build(); |
| 57 | } | 59 | } |
| 58 | 60 | ||
| 59 | - | ||
| 60 | /** | 61 | /** |
| 61 | * 创建 token | 62 | * 创建 token |
| 62 | * | 63 | * |
| @@ -81,7 +82,7 @@ public class WddPptApi { | @@ -81,7 +82,7 @@ public class WddPptApi { | ||
| 81 | .block(); | 82 | .block(); |
| 82 | } | 83 | } |
| 83 | 84 | ||
| 84 | - | 85 | + // TODO @xin:是不是给个 API 连接,这样 type、content、files 都不用写注释太细了 |
| 85 | /** | 86 | /** |
| 86 | * 创建任务 | 87 | * 创建任务 |
| 87 | * | 88 | * |
| @@ -122,7 +123,6 @@ public class WddPptApi { | @@ -122,7 +123,6 @@ public class WddPptApi { | ||
| 122 | formData.add("file", file.getResource()); | 123 | formData.add("file", file.getResource()); |
| 123 | } | 124 | } |
| 124 | } | 125 | } |
| 125 | - | ||
| 126 | return this.webClient.post() | 126 | return this.webClient.post() |
| 127 | .uri("/api/ppt/v2/createTask") | 127 | .uri("/api/ppt/v2/createTask") |
| 128 | .header("token", token) | 128 | .header("token", token) |
| @@ -162,7 +162,7 @@ public class WddPptApi { | @@ -162,7 +162,7 @@ public class WddPptApi { | ||
| 162 | } | 162 | } |
| 163 | 163 | ||
| 164 | /** | 164 | /** |
| 165 | - * 分页查询PPT模板 | 165 | + * 分页查询 PPT 模板 |
| 166 | * | 166 | * |
| 167 | * @param token 令牌 | 167 | * @param token 令牌 |
| 168 | * @param request 请求体 | 168 | * @param request 请求体 |
| @@ -214,7 +214,7 @@ public class WddPptApi { | @@ -214,7 +214,7 @@ public class WddPptApi { | ||
| 214 | } | 214 | } |
| 215 | 215 | ||
| 216 | /** | 216 | /** |
| 217 | - * 生成PPT | 217 | + * 生成 PPT |
| 218 | * | 218 | * |
| 219 | * @return PPT信息 | 219 | * @return PPT信息 |
| 220 | */ | 220 | */ |
| @@ -243,9 +243,11 @@ public class WddPptApi { | @@ -243,9 +243,11 @@ public class WddPptApi { | ||
| 243 | String uid, | 243 | String uid, |
| 244 | Integer limit | 244 | Integer limit |
| 245 | ) { | 245 | ) { |
| 246 | + | ||
| 246 | public CreateTokenRequest(String apiKey) { | 247 | public CreateTokenRequest(String apiKey) { |
| 247 | this(apiKey, null, null); | 248 | this(apiKey, null, null); |
| 248 | } | 249 | } |
| 250 | + | ||
| 249 | } | 251 | } |
| 250 | 252 | ||
| 251 | /** | 253 | /** |
| @@ -256,8 +258,7 @@ public class WddPptApi { | @@ -256,8 +258,7 @@ public class WddPptApi { | ||
| 256 | Integer code, | 258 | Integer code, |
| 257 | String message, | 259 | String message, |
| 258 | Map<String, Object> data | 260 | Map<String, Object> data |
| 259 | - ) { | ||
| 260 | - } | 261 | + ) { } |
| 261 | 262 | ||
| 262 | /** | 263 | /** |
| 263 | * 创建任务 | 264 | * 创建任务 |
| @@ -267,8 +268,7 @@ public class WddPptApi { | @@ -267,8 +268,7 @@ public class WddPptApi { | ||
| 267 | Integer type, | 268 | Integer type, |
| 268 | String content, | 269 | String content, |
| 269 | List<MultipartFile> files | 270 | List<MultipartFile> files |
| 270 | - ) { | ||
| 271 | - } | 271 | + ) { } |
| 272 | 272 | ||
| 273 | /** | 273 | /** |
| 274 | * 生成大纲内容请求 | 274 | * 生成大纲内容请求 |
| @@ -281,8 +281,7 @@ public class WddPptApi { | @@ -281,8 +281,7 @@ public class WddPptApi { | ||
| 281 | String audience, | 281 | String audience, |
| 282 | String lang, | 282 | String lang, |
| 283 | String prompt | 283 | String prompt |
| 284 | - ) { | ||
| 285 | - } | 284 | + ) { } |
| 286 | 285 | ||
| 287 | /** | 286 | /** |
| 288 | * 修改大纲内容请求 | 287 | * 修改大纲内容请求 |
| @@ -292,21 +291,20 @@ public class WddPptApi { | @@ -292,21 +291,20 @@ public class WddPptApi { | ||
| 292 | String id, | 291 | String id, |
| 293 | String markdown, | 292 | String markdown, |
| 294 | String question | 293 | String question |
| 295 | - ) { | ||
| 296 | - } | 294 | + ) { } |
| 297 | 295 | ||
| 298 | /** | 296 | /** |
| 299 | - * 生成PPT请求 | 297 | + * 生成 PPT 请求 |
| 300 | */ | 298 | */ |
| 299 | + // TODO @新:要不按照 PptCreateRequest 这样的风格 | ||
| 301 | @JsonInclude(value = JsonInclude.Include.NON_NULL) | 300 | @JsonInclude(value = JsonInclude.Include.NON_NULL) |
| 302 | public record CreatePptRequest( | 301 | public record CreatePptRequest( |
| 303 | String id, | 302 | String id, |
| 304 | String templateId, | 303 | String templateId, |
| 305 | String markdown | 304 | String markdown |
| 306 | - ) { | ||
| 307 | - } | ||
| 308 | - | 305 | + ) { } |
| 309 | 306 | ||
| 307 | + // TODO @新:要不写下类注释 | ||
| 310 | @JsonInclude(value = JsonInclude.Include.NON_NULL) | 308 | @JsonInclude(value = JsonInclude.Include.NON_NULL) |
| 311 | public record PptInfo( | 309 | public record PptInfo( |
| 312 | String id, | 310 | String id, |
| @@ -325,36 +323,35 @@ public class WddPptApi { | @@ -325,36 +323,35 @@ public class WddPptApi { | ||
| 325 | LocalDateTime createTime, | 323 | LocalDateTime createTime, |
| 326 | String createUser, | 324 | String createUser, |
| 327 | String updateUser | 325 | String updateUser |
| 328 | - ) { | ||
| 329 | - } | ||
| 330 | - | 326 | + ) { } |
| 331 | 327 | ||
| 328 | + // TODO @新:要不写下类注释 | ||
| 332 | @JsonInclude(value = JsonInclude.Include.NON_NULL) | 329 | @JsonInclude(value = JsonInclude.Include.NON_NULL) |
| 333 | public record TemplateQueryRequest( | 330 | public record TemplateQueryRequest( |
| 334 | int page, | 331 | int page, |
| 335 | int size, | 332 | int size, |
| 336 | Filter filters | 333 | Filter filters |
| 337 | ) { | 334 | ) { |
| 335 | + | ||
| 338 | @JsonInclude(value = JsonInclude.Include.NON_NULL) | 336 | @JsonInclude(value = JsonInclude.Include.NON_NULL) |
| 339 | public record Filter( | 337 | public record Filter( |
| 340 | int type, | 338 | int type, |
| 341 | String category, | 339 | String category, |
| 342 | String style, | 340 | String style, |
| 343 | String themeColor | 341 | String themeColor |
| 344 | - ) { | ||
| 345 | - } | ||
| 346 | - } | 342 | + ) { } |
| 347 | 343 | ||
| 344 | + } | ||
| 348 | 345 | ||
| 346 | + // TODO @新:要不写下类注释 | ||
| 349 | @JsonInclude(value = JsonInclude.Include.NON_NULL) | 347 | @JsonInclude(value = JsonInclude.Include.NON_NULL) |
| 350 | public record PagePptTemplateInfo( | 348 | public record PagePptTemplateInfo( |
| 351 | List<PptTemplateInfo> data, | 349 | List<PptTemplateInfo> data, |
| 352 | String total | 350 | String total |
| 353 | - ) { | ||
| 354 | - | ||
| 355 | - } | 351 | + ) {} |
| 356 | 352 | ||
| 357 | 353 | ||
| 354 | + // TODO @新:要不写下类注释 | ||
| 358 | @JsonInclude(value = JsonInclude.Include.NON_NULL) | 355 | @JsonInclude(value = JsonInclude.Include.NON_NULL) |
| 359 | public record PptTemplateInfo( | 356 | public record PptTemplateInfo( |
| 360 | String id, | 357 | String id, |
| @@ -383,7 +380,6 @@ public class WddPptApi { | @@ -383,7 +380,6 @@ public class WddPptApi { | ||
| 383 | LocalDateTime createTime, | 380 | LocalDateTime createTime, |
| 384 | String createUser, | 381 | String createUser, |
| 385 | String updateUser | 382 | String updateUser |
| 386 | - ) { | ||
| 387 | - } | 383 | + ) { } |
| 388 | 384 | ||
| 389 | } | 385 | } |
| 390 | \ No newline at end of file | 386 | \ No newline at end of file |
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/core/model/xunfei/api/XunfeiPptApi.java renamed to yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/core/model/xinghuo/api/XunfeiPptApi.java
| 1 | -package cn.iocoder.yudao.framework.ai.core.model.xunfei.api; | 1 | +package cn.iocoder.yudao.framework.ai.core.model.xinghuo.api; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | 3 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; |
| 4 | import com.fasterxml.jackson.annotation.JsonInclude; | 4 | import com.fasterxml.jackson.annotation.JsonInclude; |
| @@ -28,10 +28,11 @@ import java.util.Map; | @@ -28,10 +28,11 @@ import java.util.Map; | ||
| 28 | import java.util.function.Function; | 28 | import java.util.function.Function; |
| 29 | import java.util.function.Predicate; | 29 | import java.util.function.Predicate; |
| 30 | 30 | ||
| 31 | +// TODO @新:要不改成 XunFeiPptApi | ||
| 31 | /** | 32 | /** |
| 32 | - * 讯飞智能PPT生成 API | ||
| 33 | - * <p> | ||
| 34 | - * 对接讯飞:<a href="https://www.xfyun.cn/doc/spark/PPTv2.html">智能 PPT 生成 API</a> | 33 | + * 讯飞智能 PPT 生成 API |
| 34 | + * | ||
| 35 | + * @see <a href="https://www.xfyun.cn/doc/spark/PPTv2.html">智能 PPT 生成 API</a> | ||
| 35 | * | 36 | * |
| 36 | * @author xiaoxin | 37 | * @author xiaoxin |
| 37 | */ | 38 | */ |
| @@ -52,7 +53,9 @@ public class XunfeiPptApi { | @@ -52,7 +53,9 @@ public class XunfeiPptApi { | ||
| 52 | sink.error(new IllegalStateException("[xunfei-ppt-api] 调用失败!")); | 53 | sink.error(new IllegalStateException("[xunfei-ppt-api] 调用失败!")); |
| 53 | }); | 54 | }); |
| 54 | 55 | ||
| 56 | + // TODO @新:是不是不用 baseUrl 哈 | ||
| 55 | public XunfeiPptApi(String baseUrl, String appId, String apiSecret) { | 57 | public XunfeiPptApi(String baseUrl, String appId, String apiSecret) { |
| 58 | + // TODO @新:建议,增加 defaultheaders,例如说 appid 之类的;或者每个请求,通过 headers customer 处理。 | ||
| 56 | this.webClient = WebClient.builder() | 59 | this.webClient = WebClient.builder() |
| 57 | .baseUrl(baseUrl) | 60 | .baseUrl(baseUrl) |
| 58 | .build(); | 61 | .build(); |
| @@ -82,6 +85,7 @@ public class XunfeiPptApi { | @@ -82,6 +85,7 @@ public class XunfeiPptApi { | ||
| 82 | */ | 85 | */ |
| 83 | private String generateSignature(String appId, String apiSecret, long timestamp) { | 86 | private String generateSignature(String appId, String apiSecret, long timestamp) { |
| 84 | try { | 87 | try { |
| 88 | + // TODO @新:使用 hutool 简化 | ||
| 85 | String auth = md5(appId + timestamp); | 89 | String auth = md5(appId + timestamp); |
| 86 | return hmacSHA1Encrypt(auth, apiSecret); | 90 | return hmacSHA1Encrypt(auth, apiSecret); |
| 87 | } catch (NoSuchAlgorithmException | InvalidKeyException e) { | 91 | } catch (NoSuchAlgorithmException | InvalidKeyException e) { |
| @@ -120,7 +124,7 @@ public class XunfeiPptApi { | @@ -120,7 +124,7 @@ public class XunfeiPptApi { | ||
| 120 | } | 124 | } |
| 121 | 125 | ||
| 122 | /** | 126 | /** |
| 123 | - * 获取PPT模板列表 | 127 | + * 获取 PPT 模板列表 |
| 124 | * | 128 | * |
| 125 | * @param style 风格,如"商务" | 129 | * @param style 风格,如"商务" |
| 126 | * @param pageSize 每页数量 | 130 | * @param pageSize 每页数量 |
| @@ -130,8 +134,8 @@ public class XunfeiPptApi { | @@ -130,8 +134,8 @@ public class XunfeiPptApi { | ||
| 130 | SignatureInfo signInfo = getSignature(); | 134 | SignatureInfo signInfo = getSignature(); |
| 131 | Map<String, Object> requestBody = new HashMap<>(); | 135 | Map<String, Object> requestBody = new HashMap<>(); |
| 132 | requestBody.put("style", style); | 136 | requestBody.put("style", style); |
| 133 | - requestBody.put("pageSize", pageSize != null ? pageSize.toString() : "10"); | ||
| 134 | - | 137 | + // TODO @新:可以使用 ObjUtil.defaultIfNull |
| 138 | + requestBody.put("pageSize", pageSize != null ? pageSize : 10); | ||
| 135 | return this.webClient.post() | 139 | return this.webClient.post() |
| 136 | .uri("/template/list") | 140 | .uri("/template/list") |
| 137 | .header("appId", signInfo.appId) | 141 | .header("appId", signInfo.appId) |
| @@ -155,7 +159,6 @@ public class XunfeiPptApi { | @@ -155,7 +159,6 @@ public class XunfeiPptApi { | ||
| 155 | SignatureInfo signInfo = getSignature(); | 159 | SignatureInfo signInfo = getSignature(); |
| 156 | MultiValueMap<String, Object> formData = new LinkedMultiValueMap<>(); | 160 | MultiValueMap<String, Object> formData = new LinkedMultiValueMap<>(); |
| 157 | formData.add("query", query); | 161 | formData.add("query", query); |
| 158 | - | ||
| 159 | return this.webClient.post() | 162 | return this.webClient.post() |
| 160 | .uri("/createOutline") | 163 | .uri("/createOutline") |
| 161 | .header("appId", signInfo.appId) | 164 | .header("appId", signInfo.appId) |
| @@ -171,7 +174,7 @@ public class XunfeiPptApi { | @@ -171,7 +174,7 @@ public class XunfeiPptApi { | ||
| 171 | 174 | ||
| 172 | 175 | ||
| 173 | /** | 176 | /** |
| 174 | - * 直接创建PPT(简化版 - 通过文本) | 177 | + * 直接创建 PPT(简化版 - 通过文本) |
| 175 | * | 178 | * |
| 176 | * @param query 查询文本 | 179 | * @param query 查询文本 |
| 177 | * @return 创建响应 | 180 | * @return 创建响应 |
| @@ -184,7 +187,7 @@ public class XunfeiPptApi { | @@ -184,7 +187,7 @@ public class XunfeiPptApi { | ||
| 184 | } | 187 | } |
| 185 | 188 | ||
| 186 | /** | 189 | /** |
| 187 | - * 直接创建PPT(简化版 - 通过文件) | 190 | + * 直接创建 PPT(简化版 - 通过文件) |
| 188 | * | 191 | * |
| 189 | * @param file 文件 | 192 | * @param file 文件 |
| 190 | * @param fileName 文件名 | 193 | * @param fileName 文件名 |
| @@ -192,14 +195,12 @@ public class XunfeiPptApi { | @@ -192,14 +195,12 @@ public class XunfeiPptApi { | ||
| 192 | */ | 195 | */ |
| 193 | public CreateResponse create(MultipartFile file, String fileName) { | 196 | public CreateResponse create(MultipartFile file, String fileName) { |
| 194 | CreatePptRequest request = CreatePptRequest.builder() | 197 | CreatePptRequest request = CreatePptRequest.builder() |
| 195 | - .file(file) | ||
| 196 | - .fileName(fileName) | ||
| 197 | - .build(); | 198 | + .file(file).fileName(fileName).build(); |
| 198 | return create(request); | 199 | return create(request); |
| 199 | } | 200 | } |
| 200 | 201 | ||
| 201 | /** | 202 | /** |
| 202 | - * 直接创建PPT(完整版) | 203 | + * 直接创建 PPT(完整版) |
| 203 | * | 204 | * |
| 204 | * @param request 请求参数 | 205 | * @param request 请求参数 |
| 205 | * @return 创建响应 | 206 | * @return 创建响应 |
| @@ -207,7 +208,6 @@ public class XunfeiPptApi { | @@ -207,7 +208,6 @@ public class XunfeiPptApi { | ||
| 207 | public CreateResponse create(CreatePptRequest request) { | 208 | public CreateResponse create(CreatePptRequest request) { |
| 208 | SignatureInfo signInfo = getSignature(); | 209 | SignatureInfo signInfo = getSignature(); |
| 209 | MultiValueMap<String, Object> formData = buildCreateFormData(request); | 210 | MultiValueMap<String, Object> formData = buildCreateFormData(request); |
| 210 | - | ||
| 211 | return this.webClient.post() | 211 | return this.webClient.post() |
| 212 | .uri("/create") | 212 | .uri("/create") |
| 213 | .header("appId", signInfo.appId) | 213 | .header("appId", signInfo.appId) |
| @@ -223,7 +223,7 @@ public class XunfeiPptApi { | @@ -223,7 +223,7 @@ public class XunfeiPptApi { | ||
| 223 | 223 | ||
| 224 | 224 | ||
| 225 | /** | 225 | /** |
| 226 | - * 通过大纲创建PPT(简化版) | 226 | + * 通过大纲创建 PPT(简化版) |
| 227 | * | 227 | * |
| 228 | * @param outline 大纲内容 | 228 | * @param outline 大纲内容 |
| 229 | * @param query 查询文本 | 229 | * @param query 查询文本 |
| @@ -238,14 +238,13 @@ public class XunfeiPptApi { | @@ -238,14 +238,13 @@ public class XunfeiPptApi { | ||
| 238 | } | 238 | } |
| 239 | 239 | ||
| 240 | /** | 240 | /** |
| 241 | - * 通过大纲创建PPT(完整版) | 241 | + * 通过大纲创建 PPT(完整版) |
| 242 | * | 242 | * |
| 243 | * @param request 请求参数 | 243 | * @param request 请求参数 |
| 244 | * @return 创建响应 | 244 | * @return 创建响应 |
| 245 | */ | 245 | */ |
| 246 | public CreateResponse createPptByOutline(CreatePptByOutlineRequest request) { | 246 | public CreateResponse createPptByOutline(CreatePptByOutlineRequest request) { |
| 247 | SignatureInfo signInfo = getSignature(); | 247 | SignatureInfo signInfo = getSignature(); |
| 248 | - | ||
| 249 | return this.webClient.post() | 248 | return this.webClient.post() |
| 250 | .uri("/createPptByOutline") | 249 | .uri("/createPptByOutline") |
| 251 | .header("appId", signInfo.appId) | 250 | .header("appId", signInfo.appId) |
| @@ -260,14 +259,13 @@ public class XunfeiPptApi { | @@ -260,14 +259,13 @@ public class XunfeiPptApi { | ||
| 260 | } | 259 | } |
| 261 | 260 | ||
| 262 | /** | 261 | /** |
| 263 | - * 检查PPT生成进度 | 262 | + * 检查 PPT 生成进度 |
| 264 | * | 263 | * |
| 265 | - * @param sid 任务ID | 264 | + * @param sid 任务 ID |
| 266 | * @return 进度响应 | 265 | * @return 进度响应 |
| 267 | */ | 266 | */ |
| 268 | public ProgressResponse checkProgress(String sid) { | 267 | public ProgressResponse checkProgress(String sid) { |
| 269 | SignatureInfo signInfo = getSignature(); | 268 | SignatureInfo signInfo = getSignature(); |
| 270 | - | ||
| 271 | return this.webClient.get() | 269 | return this.webClient.get() |
| 272 | .uri(uriBuilder -> uriBuilder | 270 | .uri(uriBuilder -> uriBuilder |
| 273 | .path("/progress") | 271 | .path("/progress") |
| @@ -290,8 +288,7 @@ public class XunfeiPptApi { | @@ -290,8 +288,7 @@ public class XunfeiPptApi { | ||
| 290 | String appId, | 288 | String appId, |
| 291 | String timestamp, | 289 | String timestamp, |
| 292 | String signature | 290 | String signature |
| 293 | - ) { | ||
| 294 | - } | 291 | + ) { } |
| 295 | 292 | ||
| 296 | /** | 293 | /** |
| 297 | * 模板列表响应 | 294 | * 模板列表响应 |
| @@ -303,8 +300,7 @@ public class XunfeiPptApi { | @@ -303,8 +300,7 @@ public class XunfeiPptApi { | ||
| 303 | String desc, | 300 | String desc, |
| 304 | Integer count, | 301 | Integer count, |
| 305 | TemplatePageData data | 302 | TemplatePageData data |
| 306 | - ) { | ||
| 307 | - } | 303 | + ) { } |
| 308 | 304 | ||
| 309 | /** | 305 | /** |
| 310 | * 模板列表数据 | 306 | * 模板列表数据 |
| @@ -314,8 +310,7 @@ public class XunfeiPptApi { | @@ -314,8 +310,7 @@ public class XunfeiPptApi { | ||
| 314 | String total, | 310 | String total, |
| 315 | List<TemplateInfo> records, | 311 | List<TemplateInfo> records, |
| 316 | Integer pageNum | 312 | Integer pageNum |
| 317 | - ) { | ||
| 318 | - } | 313 | + ) { } |
| 319 | 314 | ||
| 320 | /** | 315 | /** |
| 321 | * 模板信息 | 316 | * 模板信息 |
| @@ -329,8 +324,7 @@ public class XunfeiPptApi { | @@ -329,8 +324,7 @@ public class XunfeiPptApi { | ||
| 329 | String industry, | 324 | String industry, |
| 330 | String style, | 325 | String style, |
| 331 | String detailImage | 326 | String detailImage |
| 332 | - ) { | ||
| 333 | - } | 327 | + ) { } |
| 334 | 328 | ||
| 335 | /** | 329 | /** |
| 336 | * 创建响应 | 330 | * 创建响应 |
| @@ -342,8 +336,7 @@ public class XunfeiPptApi { | @@ -342,8 +336,7 @@ public class XunfeiPptApi { | ||
| 342 | String desc, | 336 | String desc, |
| 343 | Integer count, | 337 | Integer count, |
| 344 | CreateResponseData data | 338 | CreateResponseData data |
| 345 | - ) { | ||
| 346 | - } | 339 | + ) { } |
| 347 | 340 | ||
| 348 | /** | 341 | /** |
| 349 | * 创建响应数据 | 342 | * 创建响应数据 |
| @@ -355,8 +348,7 @@ public class XunfeiPptApi { | @@ -355,8 +348,7 @@ public class XunfeiPptApi { | ||
| 355 | String title, | 348 | String title, |
| 356 | String subTitle, | 349 | String subTitle, |
| 357 | OutlineData outline | 350 | OutlineData outline |
| 358 | - ) { | ||
| 359 | - } | 351 | + ) { } |
| 360 | 352 | ||
| 361 | /** | 353 | /** |
| 362 | * 大纲数据结构 | 354 | * 大纲数据结构 |
| @@ -367,6 +359,7 @@ public class XunfeiPptApi { | @@ -367,6 +359,7 @@ public class XunfeiPptApi { | ||
| 367 | String subTitle, | 359 | String subTitle, |
| 368 | List<Chapter> chapters | 360 | List<Chapter> chapters |
| 369 | ) { | 361 | ) { |
| 362 | + | ||
| 370 | /** | 363 | /** |
| 371 | * 章节结构 | 364 | * 章节结构 |
| 372 | */ | 365 | */ |
| @@ -375,14 +368,15 @@ public class XunfeiPptApi { | @@ -375,14 +368,15 @@ public class XunfeiPptApi { | ||
| 375 | String chapterTitle, | 368 | String chapterTitle, |
| 376 | List<ChapterContent> chapterContents | 369 | List<ChapterContent> chapterContents |
| 377 | ) { | 370 | ) { |
| 371 | + | ||
| 378 | /** | 372 | /** |
| 379 | * 章节内容 | 373 | * 章节内容 |
| 380 | */ | 374 | */ |
| 381 | @JsonInclude(value = JsonInclude.Include.NON_NULL) | 375 | @JsonInclude(value = JsonInclude.Include.NON_NULL) |
| 382 | public record ChapterContent( | 376 | public record ChapterContent( |
| 383 | String chapterTitle | 377 | String chapterTitle |
| 384 | - ) { | ||
| 385 | - } | 378 | + ) { } |
| 379 | + | ||
| 386 | } | 380 | } |
| 387 | 381 | ||
| 388 | /** | 382 | /** |
| @@ -403,8 +397,7 @@ public class XunfeiPptApi { | @@ -403,8 +397,7 @@ public class XunfeiPptApi { | ||
| 403 | int code, | 397 | int code, |
| 404 | String desc, | 398 | String desc, |
| 405 | ProgressResponseData data | 399 | ProgressResponseData data |
| 406 | - ) { | ||
| 407 | - } | 400 | + ) { } |
| 408 | 401 | ||
| 409 | /** | 402 | /** |
| 410 | * 进度响应数据 | 403 | * 进度响应数据 |
| @@ -414,6 +407,7 @@ public class XunfeiPptApi { | @@ -414,6 +407,7 @@ public class XunfeiPptApi { | ||
| 414 | int process, | 407 | int process, |
| 415 | String pptId, | 408 | String pptId, |
| 416 | String pptUrl, | 409 | String pptUrl, |
| 410 | + // TODO @新:字段注释,去掉 | ||
| 417 | String pptStatus, // PPT构建状态:building(构建中),done(已完成),build_failed(生成失败) | 411 | String pptStatus, // PPT构建状态:building(构建中),done(已完成),build_failed(生成失败) |
| 418 | String aiImageStatus, // ai配图状态:building(构建中),done(已完成) | 412 | String aiImageStatus, // ai配图状态:building(构建中),done(已完成) |
| 419 | String cardNoteStatus, // 演讲备注状态:building(构建中),done(已完成) | 413 | String cardNoteStatus, // 演讲备注状态:building(构建中),done(已完成) |
| @@ -421,6 +415,7 @@ public class XunfeiPptApi { | @@ -421,6 +415,7 @@ public class XunfeiPptApi { | ||
| 421 | Integer totalPages, // 生成PPT的总页数 | 415 | Integer totalPages, // 生成PPT的总页数 |
| 422 | Integer donePages // 生成PPT的完成页数 | 416 | Integer donePages // 生成PPT的完成页数 |
| 423 | ) { | 417 | ) { |
| 418 | + | ||
| 424 | /** | 419 | /** |
| 425 | * 是否全部完成 | 420 | * 是否全部完成 |
| 426 | * | 421 | * |
| @@ -452,10 +447,11 @@ public class XunfeiPptApi { | @@ -452,10 +447,11 @@ public class XunfeiPptApi { | ||
| 452 | } | 447 | } |
| 453 | return (int) (donePages * 100.0 / totalPages); | 448 | return (int) (donePages * 100.0 / totalPages); |
| 454 | } | 449 | } |
| 450 | + | ||
| 455 | } | 451 | } |
| 456 | 452 | ||
| 457 | /** | 453 | /** |
| 458 | - * 通过大纲创建PPT请求参数 | 454 | + * 通过大纲创建 PPT 请求参数 |
| 459 | */ | 455 | */ |
| 460 | @JsonInclude(value = JsonInclude.Include.NON_NULL) | 456 | @JsonInclude(value = JsonInclude.Include.NON_NULL) |
| 461 | public record CreatePptByOutlineRequest( | 457 | public record CreatePptByOutlineRequest( |
| @@ -473,6 +469,7 @@ public class XunfeiPptApi { | @@ -473,6 +469,7 @@ public class XunfeiPptApi { | ||
| 473 | Boolean isFigure, // 是否自动配图 | 469 | Boolean isFigure, // 是否自动配图 |
| 474 | String aiImage // ai配图类型:normal、advanced | 470 | String aiImage // ai配图类型:normal、advanced |
| 475 | ) { | 471 | ) { |
| 472 | + | ||
| 476 | /** | 473 | /** |
| 477 | * 创建构建器 | 474 | * 创建构建器 |
| 478 | * | 475 | * |
| @@ -482,10 +479,12 @@ public class XunfeiPptApi { | @@ -482,10 +479,12 @@ public class XunfeiPptApi { | ||
| 482 | return new Builder(); | 479 | return new Builder(); |
| 483 | } | 480 | } |
| 484 | 481 | ||
| 482 | + // TODO @新:这个可以用 lombok 简化么? | ||
| 485 | /** | 483 | /** |
| 486 | * 构建器类 | 484 | * 构建器类 |
| 487 | */ | 485 | */ |
| 488 | public static class Builder { | 486 | public static class Builder { |
| 487 | + | ||
| 489 | private String query; | 488 | private String query; |
| 490 | private String outlineSid; | 489 | private String outlineSid; |
| 491 | private OutlineData outline; | 490 | private OutlineData outline; |
| @@ -575,7 +574,7 @@ public class XunfeiPptApi { | @@ -575,7 +574,7 @@ public class XunfeiPptApi { | ||
| 575 | } | 574 | } |
| 576 | 575 | ||
| 577 | /** | 576 | /** |
| 578 | - * 构建创建PPT的表单数据 | 577 | + * 构建创建 PPT 的表单数据 |
| 579 | * | 578 | * |
| 580 | * @param request 请求参数 | 579 | * @param request 请求参数 |
| 581 | * @return 表单数据 | 580 | * @return 表单数据 |
| @@ -586,7 +585,6 @@ public class XunfeiPptApi { | @@ -586,7 +585,6 @@ public class XunfeiPptApi { | ||
| 586 | if (request.query() != null) { | 585 | if (request.query() != null) { |
| 587 | formData.add("query", request.query()); | 586 | formData.add("query", request.query()); |
| 588 | } | 587 | } |
| 589 | - | ||
| 590 | if (request.file() != null) { | 588 | if (request.file() != null) { |
| 591 | try { | 589 | try { |
| 592 | formData.add("file", new ByteArrayResource(request.file().getBytes()) { | 590 | formData.add("file", new ByteArrayResource(request.file().getBytes()) { |
| @@ -600,47 +598,37 @@ public class XunfeiPptApi { | @@ -600,47 +598,37 @@ public class XunfeiPptApi { | ||
| 600 | throw new IllegalStateException("[xunfei-ppt-api] 文件处理失败", e); | 598 | throw new IllegalStateException("[xunfei-ppt-api] 文件处理失败", e); |
| 601 | } | 599 | } |
| 602 | } | 600 | } |
| 603 | - | 601 | + // TODO @新:要不搞个 MapUtil.addIfPresent 方法? |
| 604 | if (request.fileUrl() != null) { | 602 | if (request.fileUrl() != null) { |
| 605 | formData.add("fileUrl", request.fileUrl()); | 603 | formData.add("fileUrl", request.fileUrl()); |
| 606 | } | 604 | } |
| 607 | - | ||
| 608 | if (request.fileName() != null) { | 605 | if (request.fileName() != null) { |
| 609 | formData.add("fileName", request.fileName()); | 606 | formData.add("fileName", request.fileName()); |
| 610 | } | 607 | } |
| 611 | - | ||
| 612 | if (request.templateId() != null) { | 608 | if (request.templateId() != null) { |
| 613 | formData.add("templateId", request.templateId()); | 609 | formData.add("templateId", request.templateId()); |
| 614 | } | 610 | } |
| 615 | - | ||
| 616 | if (request.businessId() != null) { | 611 | if (request.businessId() != null) { |
| 617 | formData.add("businessId", request.businessId()); | 612 | formData.add("businessId", request.businessId()); |
| 618 | } | 613 | } |
| 619 | - | ||
| 620 | if (request.author() != null) { | 614 | if (request.author() != null) { |
| 621 | formData.add("author", request.author()); | 615 | formData.add("author", request.author()); |
| 622 | } | 616 | } |
| 623 | - | ||
| 624 | if (request.isCardNote() != null) { | 617 | if (request.isCardNote() != null) { |
| 625 | formData.add("isCardNote", request.isCardNote().toString()); | 618 | formData.add("isCardNote", request.isCardNote().toString()); |
| 626 | } | 619 | } |
| 627 | - | ||
| 628 | if (request.search() != null) { | 620 | if (request.search() != null) { |
| 629 | formData.add("search", request.search().toString()); | 621 | formData.add("search", request.search().toString()); |
| 630 | } | 622 | } |
| 631 | - | ||
| 632 | if (request.language() != null) { | 623 | if (request.language() != null) { |
| 633 | formData.add("language", request.language()); | 624 | formData.add("language", request.language()); |
| 634 | } | 625 | } |
| 635 | - | ||
| 636 | if (request.isFigure() != null) { | 626 | if (request.isFigure() != null) { |
| 637 | formData.add("isFigure", request.isFigure().toString()); | 627 | formData.add("isFigure", request.isFigure().toString()); |
| 638 | } | 628 | } |
| 639 | - | ||
| 640 | if (request.aiImage() != null) { | 629 | if (request.aiImage() != null) { |
| 641 | formData.add("aiImage", request.aiImage()); | 630 | formData.add("aiImage", request.aiImage()); |
| 642 | } | 631 | } |
| 643 | - | ||
| 644 | return formData; | 632 | return formData; |
| 645 | } | 633 | } |
| 646 | 634 | ||
| @@ -662,6 +650,7 @@ public class XunfeiPptApi { | @@ -662,6 +650,7 @@ public class XunfeiPptApi { | ||
| 662 | Boolean isFigure, // 是否自动配图 | 650 | Boolean isFigure, // 是否自动配图 |
| 663 | String aiImage // ai配图类型:normal、advanced | 651 | String aiImage // ai配图类型:normal、advanced |
| 664 | ) { | 652 | ) { |
| 653 | + | ||
| 665 | /** | 654 | /** |
| 666 | * 创建构建器 | 655 | * 创建构建器 |
| 667 | * | 656 | * |
| @@ -675,6 +664,7 @@ public class XunfeiPptApi { | @@ -675,6 +664,7 @@ public class XunfeiPptApi { | ||
| 675 | * 构建器类 | 664 | * 构建器类 |
| 676 | */ | 665 | */ |
| 677 | public static class Builder { | 666 | public static class Builder { |
| 667 | + | ||
| 678 | private String query; | 668 | private String query; |
| 679 | private MultipartFile file; | 669 | private MultipartFile file; |
| 680 | private String fileUrl; | 670 | private String fileUrl; |
| @@ -688,6 +678,8 @@ public class XunfeiPptApi { | @@ -688,6 +678,8 @@ public class XunfeiPptApi { | ||
| 688 | private Boolean isFigure; | 678 | private Boolean isFigure; |
| 689 | private String aiImage; | 679 | private String aiImage; |
| 690 | 680 | ||
| 681 | + // TODO @新:这个可以用 lombok 简化么? | ||
| 682 | + | ||
| 691 | public Builder query(String query) { | 683 | public Builder query(String query) { |
| 692 | this.query = query; | 684 | this.query = query; |
| 693 | return this; | 685 | return this; |
| @@ -763,4 +755,5 @@ public class XunfeiPptApi { | @@ -763,4 +755,5 @@ public class XunfeiPptApi { | ||
| 763 | } | 755 | } |
| 764 | } | 756 | } |
| 765 | } | 757 | } |
| 766 | -} | ||
| 767 | \ No newline at end of file | 758 | \ No newline at end of file |
| 759 | + | ||
| 760 | +} | ||
| 768 | \ No newline at end of file | 761 | \ No newline at end of file |
yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/ppt/wdd/WddPptApiTests.java
| @@ -9,7 +9,6 @@ import reactor.core.publisher.Flux; | @@ -9,7 +9,6 @@ import reactor.core.publisher.Flux; | ||
| 9 | import java.util.Map; | 9 | import java.util.Map; |
| 10 | import java.util.Objects; | 10 | import java.util.Objects; |
| 11 | 11 | ||
| 12 | - | ||
| 13 | /** | 12 | /** |
| 14 | * {@link WddPptApi} 集成测试 | 13 | * {@link WddPptApi} 集成测试 |
| 15 | * | 14 | * |
| @@ -19,11 +18,9 @@ public class WddPptApiTests { | @@ -19,11 +18,9 @@ public class WddPptApiTests { | ||
| 19 | 18 | ||
| 20 | private final WddPptApi wddPptApi = new WddPptApi("https://docmee.cn"); | 19 | private final WddPptApi wddPptApi = new WddPptApi("https://docmee.cn"); |
| 21 | 20 | ||
| 21 | + private final String token = ""; // API Token | ||
| 22 | 22 | ||
| 23 | - private final String token = ""; | ||
| 24 | - | ||
| 25 | - | ||
| 26 | - @Test //获取token | 23 | + @Test |
| 27 | @Disabled | 24 | @Disabled |
| 28 | public void testCreateApiToken() { | 25 | public void testCreateApiToken() { |
| 29 | // 准备参数 | 26 | // 准备参数 |
| @@ -35,8 +32,10 @@ public class WddPptApiTests { | @@ -35,8 +32,10 @@ public class WddPptApiTests { | ||
| 35 | System.out.println(token); | 32 | System.out.println(token); |
| 36 | } | 33 | } |
| 37 | 34 | ||
| 38 | - | ||
| 39 | - @Test // 创建任务 | 35 | + /** |
| 36 | + * 创建任务 | ||
| 37 | + */ | ||
| 38 | + @Test | ||
| 40 | @Disabled | 39 | @Disabled |
| 41 | public void testCreateTask() { | 40 | public void testCreateTask() { |
| 42 | WddPptApi.ApiResponse apiResponse = wddPptApi.createTask(token, 1, "dify 介绍", null); | 41 | WddPptApi.ApiResponse apiResponse = wddPptApi.createTask(token, 1, "dify 介绍", null); |
| @@ -47,8 +46,9 @@ public class WddPptApiTests { | @@ -47,8 +46,9 @@ public class WddPptApiTests { | ||
| 47 | @Test // 创建大纲 | 46 | @Test // 创建大纲 |
| 48 | @Disabled | 47 | @Disabled |
| 49 | public void testGenerateOutlineRequest() { | 48 | public void testGenerateOutlineRequest() { |
| 50 | - WddPptApi.CreateOutlineRequest request = new WddPptApi.CreateOutlineRequest("1901539019628613632", "medium", null, null, null, null); | ||
| 51 | - //调用 | 49 | + WddPptApi.CreateOutlineRequest request = new WddPptApi.CreateOutlineRequest( |
| 50 | + "1901539019628613632", "medium", null, null, null, null); | ||
| 51 | + // 调用 | ||
| 52 | Flux<Map<String, Object>> flux = wddPptApi.createOutline(token, request); | 52 | Flux<Map<String, Object>> flux = wddPptApi.createOutline(token, request); |
| 53 | StringBuffer contentBuffer = new StringBuffer(); | 53 | StringBuffer contentBuffer = new StringBuffer(); |
| 54 | flux.doOnNext(chunk -> { | 54 | flux.doOnNext(chunk -> { |
| @@ -61,14 +61,17 @@ public class WddPptApiTests { | @@ -61,14 +61,17 @@ public class WddPptApiTests { | ||
| 61 | }).then().block(); | 61 | }).then().block(); |
| 62 | // 打印结果 | 62 | // 打印结果 |
| 63 | System.out.println(contentBuffer); | 63 | System.out.println(contentBuffer); |
| 64 | - | ||
| 65 | } | 64 | } |
| 66 | 65 | ||
| 67 | - @Test // 修改大纲 | 66 | + /** |
| 67 | + * 修改大纲 | ||
| 68 | + */ | ||
| 69 | + @Test | ||
| 68 | @Disabled | 70 | @Disabled |
| 69 | public void testUpdateOutlineRequest() { | 71 | public void testUpdateOutlineRequest() { |
| 70 | - WddPptApi.UpdateOutlineRequest request = new WddPptApi.UpdateOutlineRequest("1901539019628613632", TEST_OUT_LINE_CONTENT, "精简一点,三个章节即可"); | ||
| 71 | - //调用 | 72 | + WddPptApi.UpdateOutlineRequest request = new WddPptApi.UpdateOutlineRequest( |
| 73 | + "1901539019628613632", TEST_OUT_LINE_CONTENT, "精简一点,三个章节即可"); | ||
| 74 | + // 调用 | ||
| 72 | Flux<Map<String, Object>> flux = wddPptApi.updateOutline(token, request); | 75 | Flux<Map<String, Object>> flux = wddPptApi.updateOutline(token, request); |
| 73 | StringBuffer contentBuffer = new StringBuffer(); | 76 | StringBuffer contentBuffer = new StringBuffer(); |
| 74 | flux.doOnNext(chunk -> { | 77 | flux.doOnNext(chunk -> { |
| @@ -84,31 +87,36 @@ public class WddPptApiTests { | @@ -84,31 +87,36 @@ public class WddPptApiTests { | ||
| 84 | 87 | ||
| 85 | } | 88 | } |
| 86 | 89 | ||
| 87 | - @Test // 获取 PPT 模版分页 | 90 | + /** |
| 91 | + * 获取 PPT 模版分页 | ||
| 92 | + */ | ||
| 93 | + @Test | ||
| 88 | @Disabled | 94 | @Disabled |
| 89 | public void testGetPptTemplatePage() { | 95 | public void testGetPptTemplatePage() { |
| 90 | // 准备参数 | 96 | // 准备参数 |
| 91 | - WddPptApi.TemplateQueryRequest.Filter filter = new WddPptApi.TemplateQueryRequest.Filter(1, null, null, null); | 97 | + WddPptApi.TemplateQueryRequest.Filter filter = new WddPptApi.TemplateQueryRequest.Filter( |
| 98 | + 1, null, null, null); | ||
| 92 | WddPptApi.TemplateQueryRequest request = new WddPptApi.TemplateQueryRequest(1, 10, filter); | 99 | WddPptApi.TemplateQueryRequest request = new WddPptApi.TemplateQueryRequest(1, 10, filter); |
| 93 | - //调用 | 100 | + // 调用 |
| 94 | WddPptApi.PagePptTemplateInfo pptTemplatePage = wddPptApi.getTemplatePage(token, request); | 101 | WddPptApi.PagePptTemplateInfo pptTemplatePage = wddPptApi.getTemplatePage(token, request); |
| 95 | // 打印结果 | 102 | // 打印结果 |
| 96 | System.out.println(pptTemplatePage); | 103 | System.out.println(pptTemplatePage); |
| 97 | } | 104 | } |
| 98 | 105 | ||
| 99 | - | ||
| 100 | - @Test // 生成 PPT | 106 | + /** |
| 107 | + * 生成 PPT | ||
| 108 | + */ | ||
| 109 | + @Test | ||
| 101 | @Disabled | 110 | @Disabled |
| 102 | public void testGeneratePptx() { | 111 | public void testGeneratePptx() { |
| 103 | // 准备参数 | 112 | // 准备参数 |
| 104 | WddPptApi.CreatePptRequest request = new WddPptApi.CreatePptRequest("1901539019628613632", "1805081814809960448", TEST_OUT_LINE_CONTENT); | 113 | WddPptApi.CreatePptRequest request = new WddPptApi.CreatePptRequest("1901539019628613632", "1805081814809960448", TEST_OUT_LINE_CONTENT); |
| 105 | - //调用 | 114 | + // 调用 |
| 106 | WddPptApi.PptInfo pptInfo = wddPptApi.create(token, request); | 115 | WddPptApi.PptInfo pptInfo = wddPptApi.create(token, request); |
| 107 | // 打印结果 | 116 | // 打印结果 |
| 108 | System.out.println(pptInfo); | 117 | System.out.println(pptInfo); |
| 109 | } | 118 | } |
| 110 | 119 | ||
| 111 | - | ||
| 112 | private final String TEST_OUT_LINE_CONTENT = """ | 120 | private final String TEST_OUT_LINE_CONTENT = """ |
| 113 | # Dify:新一代AI应用开发平台 | 121 | # Dify:新一代AI应用开发平台 |
| 114 | 122 |
yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/ppt/xunfei/XunfeiPptApiTests.java
| 1 | package cn.iocoder.yudao.framework.ai.ppt.xunfei; | 1 | package cn.iocoder.yudao.framework.ai.ppt.xunfei; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.framework.ai.core.model.xunfei.api.XunfeiPptApi; | 3 | +import cn.hutool.core.io.FileUtil; |
| 4 | +import cn.iocoder.yudao.framework.ai.core.model.xinghuo.api.XunfeiPptApi; | ||
| 4 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | 5 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; |
| 5 | import org.junit.jupiter.api.Disabled; | 6 | import org.junit.jupiter.api.Disabled; |
| 6 | import org.junit.jupiter.api.Test; | 7 | import org.junit.jupiter.api.Test; |
| @@ -8,8 +9,6 @@ import org.springframework.mock.web.MockMultipartFile; | @@ -8,8 +9,6 @@ import org.springframework.mock.web.MockMultipartFile; | ||
| 8 | import org.springframework.web.multipart.MultipartFile; | 9 | import org.springframework.web.multipart.MultipartFile; |
| 9 | 10 | ||
| 10 | import java.io.File; | 11 | import java.io.File; |
| 11 | -import java.io.FileInputStream; | ||
| 12 | -import java.io.IOException; | ||
| 13 | 12 | ||
| 14 | /** | 13 | /** |
| 15 | * {@link XunfeiPptApi} 集成测试 | 14 | * {@link XunfeiPptApi} 集成测试 |
| @@ -18,13 +17,16 @@ import java.io.IOException; | @@ -18,13 +17,16 @@ import java.io.IOException; | ||
| 18 | */ | 17 | */ |
| 19 | public class XunfeiPptApiTests { | 18 | public class XunfeiPptApiTests { |
| 20 | 19 | ||
| 21 | - // 讯飞API配置信息,实际使用时请替换为您的应用信息 | 20 | + // 讯飞 API 配置信息,实际使用时请替换为您的应用信息 |
| 22 | private static final String APP_ID = ""; | 21 | private static final String APP_ID = ""; |
| 23 | private static final String API_SECRET = ""; | 22 | private static final String API_SECRET = ""; |
| 24 | 23 | ||
| 25 | private final XunfeiPptApi xunfeiPptApi = new XunfeiPptApi(XunfeiPptApi.BASE_URL, APP_ID, API_SECRET); | 24 | private final XunfeiPptApi xunfeiPptApi = new XunfeiPptApi(XunfeiPptApi.BASE_URL, APP_ID, API_SECRET); |
| 26 | 25 | ||
| 27 | - @Test // 获取PPT模板列表 | 26 | + /** |
| 27 | + * 获取 PPT 模板列表 | ||
| 28 | + */ | ||
| 29 | + @Test | ||
| 28 | @Disabled | 30 | @Disabled |
| 29 | public void testGetTemplatePage() { | 31 | public void testGetTemplatePage() { |
| 30 | // 调用方法 | 32 | // 调用方法 |
| @@ -48,35 +50,42 @@ public class XunfeiPptApiTests { | @@ -48,35 +50,42 @@ public class XunfeiPptApiTests { | ||
| 48 | } | 50 | } |
| 49 | } | 51 | } |
| 50 | 52 | ||
| 51 | - @Test // 创建大纲(通过文本) | 53 | + /** |
| 54 | + * 创建大纲(通过文本) | ||
| 55 | + */ | ||
| 56 | + @Test | ||
| 52 | @Disabled | 57 | @Disabled |
| 53 | public void testCreateOutline() { | 58 | public void testCreateOutline() { |
| 54 | XunfeiPptApi.CreateResponse response = getCreateResponse(); | 59 | XunfeiPptApi.CreateResponse response = getCreateResponse(); |
| 55 | // 打印结果 | 60 | // 打印结果 |
| 56 | System.out.println("创建大纲响应:" + JsonUtils.toJsonString(response)); | 61 | System.out.println("创建大纲响应:" + JsonUtils.toJsonString(response)); |
| 57 | 62 | ||
| 58 | - // 保存sid和outline用于后续测试 | 63 | + // 保存 sid 和 outline 用于后续测试 |
| 59 | if (response != null && response.data() != null) { | 64 | if (response != null && response.data() != null) { |
| 60 | System.out.println("sid: " + response.data().sid()); | 65 | System.out.println("sid: " + response.data().sid()); |
| 61 | if (response.data().outline() != null) { | 66 | if (response.data().outline() != null) { |
| 62 | - // 使用OutlineData的toJsonString方法 | 67 | + // 使用 OutlineData 的 toJsonString 方法 |
| 63 | System.out.println("outline: " + response.data().outline().toJsonString()); | 68 | System.out.println("outline: " + response.data().outline().toJsonString()); |
| 64 | - // 将outline对象转换为JSON字符串,用于后续createPptByOutline测试 | 69 | + // 将 outline 对象转换为 JSON 字符串,用于后续 createPptByOutline 测试 |
| 65 | String outlineJson = response.data().outline().toJsonString(); | 70 | String outlineJson = response.data().outline().toJsonString(); |
| 66 | - System.out.println("可用于createPptByOutline的outline字符串: " + outlineJson); | 71 | + System.out.println("可用于 createPptByOutline 的 outline 字符串: " + outlineJson); |
| 67 | } | 72 | } |
| 68 | } | 73 | } |
| 69 | } | 74 | } |
| 70 | 75 | ||
| 71 | - // 创建大纲(通过文本) | 76 | + /** |
| 77 | + * 创建大纲(通过文本) | ||
| 78 | + * @return 创建大纲响应 | ||
| 79 | + */ | ||
| 72 | private XunfeiPptApi.CreateResponse getCreateResponse() { | 80 | private XunfeiPptApi.CreateResponse getCreateResponse() { |
| 73 | - // 准备参数 | ||
| 74 | String param = "智能体平台 Dify 介绍"; | 81 | String param = "智能体平台 Dify 介绍"; |
| 75 | - // 调用方法 | ||
| 76 | return xunfeiPptApi.createOutline(param); | 82 | return xunfeiPptApi.createOutline(param); |
| 77 | } | 83 | } |
| 78 | 84 | ||
| 79 | - @Test // 通过大纲创建PPT(完整参数) | 85 | + /** |
| 86 | + * 通过大纲创建 PPT(完整参数) | ||
| 87 | + */ | ||
| 88 | + @Test | ||
| 80 | @Disabled | 89 | @Disabled |
| 81 | public void testCreatePptByOutlineWithFullParams() { | 90 | public void testCreatePptByOutlineWithFullParams() { |
| 82 | // 创建大纲对象 | 91 | // 创建大纲对象 |
| @@ -84,7 +93,7 @@ public class XunfeiPptApiTests { | @@ -84,7 +93,7 @@ public class XunfeiPptApiTests { | ||
| 84 | // 调用方法 | 93 | // 调用方法 |
| 85 | XunfeiPptApi.CreateResponse response = xunfeiPptApi.createPptByOutline(createResponse.data().outline(), "精简一些,不要超过6个章节"); | 94 | XunfeiPptApi.CreateResponse response = xunfeiPptApi.createPptByOutline(createResponse.data().outline(), "精简一些,不要超过6个章节"); |
| 86 | // 打印结果 | 95 | // 打印结果 |
| 87 | - System.out.println("通过大纲创建PPT响应:" + JsonUtils.toJsonString(response)); | 96 | + System.out.println("通过大纲创建 PPT 响应:" + JsonUtils.toJsonString(response)); |
| 88 | 97 | ||
| 89 | // 保存sid用于后续进度查询 | 98 | // 保存sid用于后续进度查询 |
| 90 | if (response != null && response.data() != null) { | 99 | if (response != null && response.data() != null) { |
| @@ -95,10 +104,13 @@ public class XunfeiPptApiTests { | @@ -95,10 +104,13 @@ public class XunfeiPptApiTests { | ||
| 95 | } | 104 | } |
| 96 | } | 105 | } |
| 97 | 106 | ||
| 98 | - @Test // 检查PPT生成进度 | 107 | + /** |
| 108 | + * 检查 PPT 生成进度 | ||
| 109 | + */ | ||
| 110 | + @Test | ||
| 99 | @Disabled | 111 | @Disabled |
| 100 | public void testCheckProgress() { | 112 | public void testCheckProgress() { |
| 101 | - // 准备参数 - 使用之前创建PPT时返回的sid | 113 | + // 准备参数 - 使用之前创建 PPT 时返回的 sid |
| 102 | String sid = "e96dac09f2ec4ee289f029a5fb874ecd"; // 替换为实际的sid | 114 | String sid = "e96dac09f2ec4ee289f029a5fb874ecd"; // 替换为实际的sid |
| 103 | 115 | ||
| 104 | // 调用方法 | 116 | // 调用方法 |
| @@ -111,8 +123,8 @@ public class XunfeiPptApiTests { | @@ -111,8 +123,8 @@ public class XunfeiPptApiTests { | ||
| 111 | XunfeiPptApi.ProgressResponseData data = response.data(); | 123 | XunfeiPptApi.ProgressResponseData data = response.data(); |
| 112 | 124 | ||
| 113 | // 打印PPT生成状态 | 125 | // 打印PPT生成状态 |
| 114 | - System.out.println("PPT构建状态: " + data.pptStatus()); | ||
| 115 | - System.out.println("AI配图状态: " + data.aiImageStatus()); | 126 | + System.out.println("PPT 构建状态: " + data.pptStatus()); |
| 127 | + System.out.println("AI 配图状态: " + data.aiImageStatus()); | ||
| 116 | System.out.println("演讲备注状态: " + data.cardNoteStatus()); | 128 | System.out.println("演讲备注状态: " + data.cardNoteStatus()); |
| 117 | 129 | ||
| 118 | // 打印进度信息 | 130 | // 打印进度信息 |
| @@ -126,30 +138,33 @@ public class XunfeiPptApiTests { | @@ -126,30 +138,33 @@ public class XunfeiPptApiTests { | ||
| 126 | 138 | ||
| 127 | // 检查是否完成 | 139 | // 检查是否完成 |
| 128 | if (data.isAllDone()) { | 140 | if (data.isAllDone()) { |
| 129 | - System.out.println("PPT生成已完成!"); | ||
| 130 | - System.out.println("PPT下载链接: " + data.pptUrl()); | 141 | + System.out.println("PPT 生成已完成!"); |
| 142 | + System.out.println("PPT 下载链接: " + data.pptUrl()); | ||
| 131 | } | 143 | } |
| 132 | // 检查是否失败 | 144 | // 检查是否失败 |
| 133 | else if (data.isFailed()) { | 145 | else if (data.isFailed()) { |
| 134 | - System.out.println("PPT生成失败!"); | 146 | + System.out.println("PPT 生成失败!"); |
| 135 | System.out.println("错误信息: " + data.errMsg()); | 147 | System.out.println("错误信息: " + data.errMsg()); |
| 136 | } | 148 | } |
| 137 | // 正在进行中 | 149 | // 正在进行中 |
| 138 | else { | 150 | else { |
| 139 | - System.out.println("PPT生成中,请稍后再查询..."); | 151 | + System.out.println("PPT 生成中,请稍后再查询..."); |
| 140 | } | 152 | } |
| 141 | } | 153 | } |
| 142 | } | 154 | } |
| 143 | 155 | ||
| 144 | - @Test // 轮询检查PPT生成进度直到完成 | 156 | + /** |
| 157 | + * 轮询检查 PPT 生成进度直到完成 | ||
| 158 | + */ | ||
| 159 | + @Test | ||
| 145 | @Disabled | 160 | @Disabled |
| 146 | public void testPollCheckProgress() throws InterruptedException { | 161 | public void testPollCheckProgress() throws InterruptedException { |
| 147 | - // 准备参数 - 使用之前创建PPT时返回的sid | 162 | + // 准备参数 - 使用之前创建 PP T时返回的 sid |
| 148 | String sid = "fa36e926f2ed434987fcb4c1f0776ffb"; // 替换为实际的sid | 163 | String sid = "fa36e926f2ed434987fcb4c1f0776ffb"; // 替换为实际的sid |
| 149 | 164 | ||
| 150 | // 最大轮询次数 | 165 | // 最大轮询次数 |
| 151 | int maxPolls = 20; | 166 | int maxPolls = 20; |
| 152 | - // 轮询间隔(毫秒)- 讯飞API限流为3秒一次 | 167 | + // 轮询间隔(毫秒)- 讯飞 API 限流为 3 秒一次 |
| 153 | long pollInterval = 3500; | 168 | long pollInterval = 3500; |
| 154 | 169 | ||
| 155 | for (int i = 0; i < maxPolls; i++) { | 170 | for (int i = 0; i < maxPolls; i++) { |
| @@ -163,7 +178,7 @@ public class XunfeiPptApiTests { | @@ -163,7 +178,7 @@ public class XunfeiPptApiTests { | ||
| 163 | XunfeiPptApi.ProgressResponseData data = response.data(); | 178 | XunfeiPptApi.ProgressResponseData data = response.data(); |
| 164 | 179 | ||
| 165 | // 打印进度信息 | 180 | // 打印进度信息 |
| 166 | - System.out.println("PPT构建状态: " + data.pptStatus()); | 181 | + System.out.println("PPT 构建状态: " + data.pptStatus()); |
| 167 | if (data.totalPages() != null && data.donePages() != null) { | 182 | if (data.totalPages() != null && data.donePages() != null) { |
| 168 | System.out.println("完成进度: " + data.donePages() + "/" + data.totalPages() | 183 | System.out.println("完成进度: " + data.donePages() + "/" + data.totalPages() |
| 169 | + " (" + data.getProgressPercent() + "%)"); | 184 | + " (" + data.getProgressPercent() + "%)"); |
| @@ -171,19 +186,19 @@ public class XunfeiPptApiTests { | @@ -171,19 +186,19 @@ public class XunfeiPptApiTests { | ||
| 171 | 186 | ||
| 172 | // 检查是否完成 | 187 | // 检查是否完成 |
| 173 | if (data.isAllDone()) { | 188 | if (data.isAllDone()) { |
| 174 | - System.out.println("PPT生成已完成!"); | ||
| 175 | - System.out.println("PPT下载链接: " + data.pptUrl()); | 189 | + System.out.println("PPT 生成已完成!"); |
| 190 | + System.out.println("PPT 下载链接: " + data.pptUrl()); | ||
| 176 | break; | 191 | break; |
| 177 | } | 192 | } |
| 178 | // 检查是否失败 | 193 | // 检查是否失败 |
| 179 | else if (data.isFailed()) { | 194 | else if (data.isFailed()) { |
| 180 | - System.out.println("PPT生成失败!"); | 195 | + System.out.println("PPT 生成失败!"); |
| 181 | System.out.println("错误信息: " + data.errMsg()); | 196 | System.out.println("错误信息: " + data.errMsg()); |
| 182 | break; | 197 | break; |
| 183 | } | 198 | } |
| 184 | // 正在进行中,继续轮询 | 199 | // 正在进行中,继续轮询 |
| 185 | else { | 200 | else { |
| 186 | - System.out.println("PPT生成中,等待" + (pollInterval / 1000) + "秒后继续查询..."); | 201 | + System.out.println("PPT 生成中,等待" + (pollInterval / 1000) + "秒后继续查询..."); |
| 187 | Thread.sleep(pollInterval); | 202 | Thread.sleep(pollInterval); |
| 188 | } | 203 | } |
| 189 | } else { | 204 | } else { |
| @@ -193,7 +208,10 @@ public class XunfeiPptApiTests { | @@ -193,7 +208,10 @@ public class XunfeiPptApiTests { | ||
| 193 | } | 208 | } |
| 194 | } | 209 | } |
| 195 | 210 | ||
| 196 | - @Test // 直接创建PPT(通过文本) | 211 | + /** |
| 212 | + * 直接创建 PPT(通过文本) | ||
| 213 | + */ | ||
| 214 | + @Test | ||
| 197 | @Disabled | 215 | @Disabled |
| 198 | public void testCreatePptByText() { | 216 | public void testCreatePptByText() { |
| 199 | // 准备参数 | 217 | // 准备参数 |
| @@ -202,9 +220,9 @@ public class XunfeiPptApiTests { | @@ -202,9 +220,9 @@ public class XunfeiPptApiTests { | ||
| 202 | // 调用方法 | 220 | // 调用方法 |
| 203 | XunfeiPptApi.CreateResponse response = xunfeiPptApi.create(query); | 221 | XunfeiPptApi.CreateResponse response = xunfeiPptApi.create(query); |
| 204 | // 打印结果 | 222 | // 打印结果 |
| 205 | - System.out.println("直接创建PPT响应:" + JsonUtils.toJsonString(response)); | 223 | + System.out.println("直接创建 PPT 响应:" + JsonUtils.toJsonString(response)); |
| 206 | 224 | ||
| 207 | - // 保存sid用于后续进度查询 | 225 | + // 保存 sid 用于后续进度查询 |
| 208 | if (response != null && response.data() != null) { | 226 | if (response != null && response.data() != null) { |
| 209 | System.out.println("sid: " + response.data().sid()); | 227 | System.out.println("sid: " + response.data().sid()); |
| 210 | if (response.data().coverImgSrc() != null) { | 228 | if (response.data().coverImgSrc() != null) { |
| @@ -215,9 +233,12 @@ public class XunfeiPptApiTests { | @@ -215,9 +233,12 @@ public class XunfeiPptApiTests { | ||
| 215 | } | 233 | } |
| 216 | } | 234 | } |
| 217 | 235 | ||
| 218 | - @Test // 直接创建PPT(通过文件) | 236 | + /** |
| 237 | + * 直接创建 PPT(通过文件) | ||
| 238 | + */ | ||
| 239 | + @Test | ||
| 219 | @Disabled | 240 | @Disabled |
| 220 | - public void testCreatePptByFile() throws IOException { | 241 | + public void testCreatePptByFile() { |
| 221 | // 准备参数 | 242 | // 准备参数 |
| 222 | File file = new File("src/test/resources/test.txt"); // 请确保此文件存在 | 243 | File file = new File("src/test/resources/test.txt"); // 请确保此文件存在 |
| 223 | MultipartFile multipartFile = convertFileToMultipartFile(file); | 244 | MultipartFile multipartFile = convertFileToMultipartFile(file); |
| @@ -227,7 +248,7 @@ public class XunfeiPptApiTests { | @@ -227,7 +248,7 @@ public class XunfeiPptApiTests { | ||
| 227 | // 打印结果 | 248 | // 打印结果 |
| 228 | System.out.println("通过文件创建PPT响应:" + JsonUtils.toJsonString(response)); | 249 | System.out.println("通过文件创建PPT响应:" + JsonUtils.toJsonString(response)); |
| 229 | 250 | ||
| 230 | - // 保存sid用于后续进度查询 | 251 | + // 保存 sid 用于后续进度查询 |
| 231 | if (response != null && response.data() != null) { | 252 | if (response != null && response.data() != null) { |
| 232 | System.out.println("sid: " + response.data().sid()); | 253 | System.out.println("sid: " + response.data().sid()); |
| 233 | if (response.data().coverImgSrc() != null) { | 254 | if (response.data().coverImgSrc() != null) { |
| @@ -238,11 +259,14 @@ public class XunfeiPptApiTests { | @@ -238,11 +259,14 @@ public class XunfeiPptApiTests { | ||
| 238 | } | 259 | } |
| 239 | } | 260 | } |
| 240 | 261 | ||
| 241 | - @Test // 直接创建PPT(完整参数) | 262 | + /** |
| 263 | + * 直接创建 PPT(完整参数) | ||
| 264 | + */ | ||
| 265 | + @Test | ||
| 242 | @Disabled | 266 | @Disabled |
| 243 | - public void testCreatePptWithFullParams() throws IOException { | 267 | + public void testCreatePptWithFullParams() { |
| 244 | // 准备参数 | 268 | // 准备参数 |
| 245 | - String query = "合肥天气趋势分析,包括近5年的气温变化、降水量变化、极端天气事件,以及对城市生活的影响"; | 269 | + String query = "合肥天气趋势分析,包括近 5 年的气温变化、降水量变化、极端天气事件,以及对城市生活的影响"; |
| 246 | 270 | ||
| 247 | // 创建请求对象 | 271 | // 创建请求对象 |
| 248 | XunfeiPptApi.CreatePptRequest request = XunfeiPptApi.CreatePptRequest.builder() | 272 | XunfeiPptApi.CreatePptRequest request = XunfeiPptApi.CreatePptRequest.builder() |
| @@ -258,9 +282,9 @@ public class XunfeiPptApiTests { | @@ -258,9 +282,9 @@ public class XunfeiPptApiTests { | ||
| 258 | // 调用方法 | 282 | // 调用方法 |
| 259 | XunfeiPptApi.CreateResponse response = xunfeiPptApi.create(request); | 283 | XunfeiPptApi.CreateResponse response = xunfeiPptApi.create(request); |
| 260 | // 打印结果 | 284 | // 打印结果 |
| 261 | - System.out.println("使用完整参数创建PPT响应:" + JsonUtils.toJsonString(response)); | 285 | + System.out.println("使用完整参数创建 PPT 响应:" + JsonUtils.toJsonString(response)); |
| 262 | 286 | ||
| 263 | - // 保存sid用于后续进度查询 | 287 | + // 保存 sid 用于后续进度查询 |
| 264 | if (response != null && response.data() != null) { | 288 | if (response != null && response.data() != null) { |
| 265 | String sid = response.data().sid(); | 289 | String sid = response.data().sid(); |
| 266 | System.out.println("sid: " + sid); | 290 | System.out.println("sid: " + sid); |
| @@ -275,7 +299,7 @@ public class XunfeiPptApiTests { | @@ -275,7 +299,7 @@ public class XunfeiPptApiTests { | ||
| 275 | XunfeiPptApi.ProgressResponse progressResponse = xunfeiPptApi.checkProgress(sid); | 299 | XunfeiPptApi.ProgressResponse progressResponse = xunfeiPptApi.checkProgress(sid); |
| 276 | if (progressResponse != null && progressResponse.data() != null) { | 300 | if (progressResponse != null && progressResponse.data() != null) { |
| 277 | XunfeiPptApi.ProgressResponseData progressData = progressResponse.data(); | 301 | XunfeiPptApi.ProgressResponseData progressData = progressResponse.data(); |
| 278 | - System.out.println("PPT构建状态: " + progressData.pptStatus()); | 302 | + System.out.println("PPT 构建状态: " + progressData.pptStatus()); |
| 279 | if (progressData.totalPages() != null && progressData.donePages() != null) { | 303 | if (progressData.totalPages() != null && progressData.donePages() != null) { |
| 280 | System.out.println("完成进度: " + progressData.donePages() + "/" + progressData.totalPages() | 304 | System.out.println("完成进度: " + progressData.donePages() + "/" + progressData.totalPages() |
| 281 | + " (" + progressData.getProgressPercent() + "%)"); | 305 | + " (" + progressData.getProgressPercent() + "%)"); |
| @@ -285,16 +309,10 @@ public class XunfeiPptApiTests { | @@ -285,16 +309,10 @@ public class XunfeiPptApiTests { | ||
| 285 | } | 309 | } |
| 286 | 310 | ||
| 287 | /** | 311 | /** |
| 288 | - * 将File转换为MultipartFile | 312 | + * 将 File 转换为 MultipartFile |
| 289 | */ | 313 | */ |
| 290 | - private MultipartFile convertFileToMultipartFile(File file) throws IOException { | ||
| 291 | - FileInputStream input = new FileInputStream(file); | ||
| 292 | - return new MockMultipartFile( | ||
| 293 | - "file", | ||
| 294 | - file.getName(), | ||
| 295 | - "text/plain", | ||
| 296 | - input.readAllBytes() | ||
| 297 | - ); | 314 | + private MultipartFile convertFileToMultipartFile(File file) { |
| 315 | + return new MockMultipartFile("file", file.getName(), "text/plain", FileUtil.readBytes(file)); | ||
| 298 | } | 316 | } |
| 299 | 317 | ||
| 300 | -} | ||
| 301 | \ No newline at end of file | 318 | \ No newline at end of file |
| 319 | +} | ||
| 302 | \ No newline at end of file | 320 | \ No newline at end of file |