ソースを参照

kimi失败内容进行重试

wangyunpeng 8 ヶ月 前
コミット
c0a02e0f0b

+ 3 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/model/entity/longArticle/ArticleCategory.java

@@ -44,6 +44,9 @@ public class ArticleCategory {
     @Column(name = "fail_reason")
     private String failReason;
 
+    @Column(name = "retry_times")
+    private Integer retryTimes;
+
     @Column(name = "create_timestamp")
     private Long createTimestamp;
 

+ 2 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/repository/longArticle/ArticleCategoryRepository.java

@@ -14,4 +14,6 @@ public interface ArticleCategoryRepository extends JpaRepository<ArticleCategory
     List<ArticleCategory> getByStatus(Integer status);
 
     List<ArticleCategory> getAllByChannelContentIdIn(List<String> channelContentIds);
+
+    List<ArticleCategory> getByStatusAndRetryTimesLessThan(Integer status, Integer retryTimes);
 }

+ 6 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/XxlJobService.java

@@ -397,4 +397,10 @@ public class XxlJobService {
         articleService.articleCategory();
         return ReturnT.SUCCESS;
     }
+
+    @XxlJob("articleCategoryJobRetry")
+    public ReturnT<String> articleCategoryJobRetry(String param) {
+        articleService.articleCategoryJobRetry();
+        return ReturnT.SUCCESS;
+    }
 }

+ 31 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/ArticleService.java

@@ -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);
+        }
+    }
 }

+ 5 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/web/XxlJobController.java

@@ -54,4 +54,9 @@ public class XxlJobController {
         service.articleCategoryJob(null);
     }
 
+    @GetMapping("/articleCategoryJobRetry")
+    public void articleCategoryJobRetry() {
+        service.articleCategoryJobRetry(null);
+    }
+
 }