|
@@ -430,4 +430,35 @@ public class ArticleService {
|
|
|
}
|
|
|
return prompt.toString();
|
|
|
}
|
|
|
+
|
|
|
+ public void articleCategoryJobRetry() {
|
|
|
+ List<ArticleCategory> dealList = articleCategoryRepository.getByStatusAndRetryTimesLessThan(ArticleCategoryStatusEnum.FAIL.getCode(), 3);
|
|
|
+ for (ArticleCategory articleCategory : dealList) {
|
|
|
+ List<String> partitionTitles = Collections.singletonList(articleCategory.getTitle());
|
|
|
+ String prompt = buildKimiPrompt(partitionTitles);
|
|
|
+ KimiResult kimiResult = kimiApiService.requestOfficialApi(prompt, null, null);
|
|
|
+ long now = System.currentTimeMillis();
|
|
|
+ JSONObject obj = null;
|
|
|
+ if (kimiResult.isSuccess()) {
|
|
|
+ try {
|
|
|
+ obj = JSONObject.parseObject(kimiResult.getResponse().getChoices().get(0).getMessage().getContent());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(kimiResult.getResponse().getChoices().get(0).getMessage().getContent());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ articleCategory.setKimiResult(kimiResult.getResponseStr());
|
|
|
+ articleCategory.setUpdateTimestamp(now);
|
|
|
+ articleCategory.setRetryTimes(articleCategory.getRetryTimes() + 1);
|
|
|
+ if (kimiResult.isSuccess() && Objects.nonNull(obj)) {
|
|
|
+ articleCategory.setCategory(obj.getString(articleCategory.getTitle()));
|
|
|
+ articleCategory.setStatus(ArticleCategoryStatusEnum.SUCCESS.getCode());
|
|
|
+ articleCategory.setFailReason(null);
|
|
|
+ } else {
|
|
|
+ articleCategory.setStatus(ArticleCategoryStatusEnum.FAIL.getCode());
|
|
|
+ articleCategory.setFailReason(kimiResult.getFailReason());
|
|
|
+ }
|
|
|
+ articleCategoryRepository.save(articleCategory);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|