Selaa lähdekoodia

Merge branch 'wyp/0212-testCode' of Server/long-article-recommend into master

wangyunpeng 4 kuukautta sitten
vanhempi
commit
8a576e60f6

+ 2 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/mapper/aigc/AigcBaseMapper.java

@@ -58,4 +58,6 @@ public interface AigcBaseMapper {
     List<BadCrawlerAccountDTO> getBadAccountList(List<String> producePlanIds);
     List<BadCrawlerAccountDTO> getBadAccountList(List<String> producePlanIds);
 
 
     void setCrawlerContentDisuseByAccountName(List<String> accountNames);
     void setCrawlerContentDisuseByAccountName(List<String> accountNames);
+
+    List<ProduceContentDTO> getProduceContentById(List<String> planExeIds);
 }
 }

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

@@ -81,4 +81,6 @@ public interface LongArticleBaseMapper {
     Long countMatchCount(Date start, Date end);
     Long countMatchCount(Date start, Date end);
 
 
     void batchInsertLongArticleAuditDelete(List<LongArticleAuditDelete> deleteList);
     void batchInsertLongArticleAuditDelete(List<LongArticleAuditDelete> deleteList);
+
+    List<String> getPassContentIds();
 }
 }

+ 1 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/model/dto/ProduceContentDTO.java

@@ -9,6 +9,7 @@ public class ProduceContentDTO {
 
 
     private String contentId;
     private String contentId;
     private String title;
     private String title;
+    private String bodyText;
     private Long produceTimestamp;
     private Long produceTimestamp;
     private String producePlanId;
     private String producePlanId;
 
 

+ 12 - 0
long-article-recommend-service/src/main/resources/mapper/aigc/AigcBaseMapper.xml

@@ -256,4 +256,16 @@
         and cc.status = 1
         and cc.status = 1
     </update>
     </update>
 
 
+    <select id="getProduceContentById" resultType="com.tzld.longarticle.recommend.server.model.dto.ProduceContentDTO">
+        select distinct record.plan_exe_id as contentId,
+                        output.output             as bodyText
+        from produce_plan_exe_record record
+         join produce_plan_module_output output
+        on record.plan_exe_id = output.plan_exe_id and output.produce_module_type = 4
+        where record.plan_exe_id in
+        <foreach collection="planExeIds" item="item" open="(" close=")" separator=",">
+            #{item}
+        </foreach>
+    </select>
+
 </mapper>
 </mapper>

+ 4 - 0
long-article-recommend-service/src/main/resources/mapper/longArticle/LongArticleBaseMapper.xml

@@ -283,6 +283,10 @@
         where start_processing_time between #{start} and #{end}
         where start_processing_time between #{start} and #{end}
     </select>
     </select>
 
 
+    <select id="getPassContentIds" resultType="java.lang.String">
+        select content_id from long_articles_title_audit where status = 1 limit 100
+    </select>
+
     <insert id="batchInsertLongArticleAuditDelete">
     <insert id="batchInsertLongArticleAuditDelete">
         insert into long_article_audit_delete
         insert into long_article_audit_delete
         (gh_id, msg_id, `index`, push_id, push_type, publish_content_id, status, delete_reason, create_timestamp)
         (gh_id, msg_id, `index`, push_id, push_type, publish_content_id, status, delete_reason, create_timestamp)

+ 15 - 0
long-article-recommend-service/src/test/java/com/tzld/longarticle/recommend/server/RecommendTest.java

@@ -3,6 +3,7 @@ package com.tzld.longarticle.recommend.server;
 import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.collection.CollectionUtil;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
+import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Lists;
 import com.tzld.longarticle.recommend.server.common.enums.recommend.ArticleTypeEnum;
 import com.tzld.longarticle.recommend.server.common.enums.recommend.ArticleTypeEnum;
 import com.tzld.longarticle.recommend.server.mapper.aigc.AigcBaseMapper;
 import com.tzld.longarticle.recommend.server.mapper.aigc.AigcBaseMapper;
@@ -69,6 +70,9 @@ public class RecommendTest {
     @Autowired
     @Autowired
     private PublishContentMapper publishContentMapper;
     private PublishContentMapper publishContentMapper;
 
 
+    @ApolloJsonValue("${accountStrategyConfig:{}}")
+    private Map<String, String> accountStrategyConfigMap;
+
 //    @Test
 //    @Test
 //    void recall() {
 //    void recall() {
 //        RecallParam param = new RecallParam();
 //        RecallParam param = new RecallParam();
@@ -862,4 +866,15 @@ public class RecommendTest {
             publishContentMapper.updatePublishContentSingleMiniProgram(partition);
             publishContentMapper.updatePublishContentSingleMiniProgram(partition);
         }
         }
     }
     }
+
+
+    @Test
+    public void testAccountStrategy() {
+        List<String> ghIds = Arrays.asList("gh_9f8dc5b0c74e", "gh_6d9f36e3a7be", "gh_183d80deffb8", "gh_4568b5a7e2fe", "gh_5ff48e9fb9ef", "gh_084a485e859a", "gh_970460d9ccec", "gh_e24da99dc899", "gh_adca24a8f429", "gh_e0eb490115f5", "gh_0e4fd9e88386", "gh_03d32e83122f", "gh_95ed5ecf9363", "gh_749271f1ccd5", "gh_7c66e0dbd2cf", "gh_660afe87b6fd", "gh_03d45c260115", "gh_1686250f15b6", "gh_57c9e8babea7", "gh_bfea052b5baa", "gh_98ec0ffe69b3", "gh_6d3aa9d13402", "gh_2e615fa75ffb", "gh_5d18ac6e3118", "gh_c9b664360ce6", "gh_486568379bf8", "gh_325188c9ea8b", "gh_f93af770fb55", "gh_18c6258ec8f7", "gh_26c906592150", "gh_9bd3ec87db86", "gh_4f34eb52e641", "gh_be0aa7c09379", "gh_fe6ef3a65a48", "gh_631fb48b83a5", "gh_86cb64d57a1d", "gh_74827e516740", "gh_008ef23062ee", "gh_30816d8adb52", "gh_3e91f0624545", "gh_51e4ad40466d", "gh_57573f01b2ee", "gh_744cb16f6e16", "gh_789a40fe7935", "gh_969f5ea5fee1", "gh_ac43eb24376d", "gh_be8c29139989", "gh_c91b42649690", "gh_d5f935d0d1f2", "gh_b1553fe3ef26", "gh_1a2bb3fef76a", "gh_c952bc10dfad", "gh_871c78fca0fa", "gh_c19a94a3fcc1", "gh_a51201bcff28", "gh_292aa2577527", "gh_8355128f7787", "gh_aca0f00404ec", "gh_447df8696a6b", "gh_784083e6713c", "gh_64cff9328215", "gh_a42807f192dc", "gh_2f80ba39f996", "gh_290e053f7b90", "gh_09f0b4c51279");
+        List<PublishAccount> publishAccountList = publishAccountRepository.getAllByGhIdIn(ghIds);
+        for (PublishAccount publishAccount : publishAccountList) {
+            accountStrategyConfigMap.put(publishAccount.getName(), "ArticleRankV15");
+        }
+        System.out.println(JSONObject.toJSONString(accountStrategyConfigMap));
+    }
 }
 }

+ 96 - 3
long-article-recommend-service/src/test/java/com/tzld/longarticle/recommend/server/WxApiTest.java

@@ -1,19 +1,31 @@
 package com.tzld.longarticle.recommend.server;
 package com.tzld.longarticle.recommend.server;
 
 
+import com.alibaba.fastjson.JSONObject;
+import com.tzld.longarticle.recommend.server.mapper.aigc.AigcBaseMapper;
 import com.tzld.longarticle.recommend.server.mapper.aigc.PublishContentMapper;
 import com.tzld.longarticle.recommend.server.mapper.aigc.PublishContentMapper;
 import com.tzld.longarticle.recommend.server.mapper.longArticle.LongArticleBaseMapper;
 import com.tzld.longarticle.recommend.server.mapper.longArticle.LongArticleBaseMapper;
+import com.tzld.longarticle.recommend.server.model.dto.ProduceContentDTO;
 import com.tzld.longarticle.recommend.server.model.entity.aigc.PublishAccount;
 import com.tzld.longarticle.recommend.server.model.entity.aigc.PublishAccount;
 import com.tzld.longarticle.recommend.server.remote.WxAccessTokenRemoteService;
 import com.tzld.longarticle.recommend.server.remote.WxAccessTokenRemoteService;
 import com.tzld.longarticle.recommend.server.remote.WxArticleDeleteService;
 import com.tzld.longarticle.recommend.server.remote.WxArticleDeleteService;
 import com.tzld.longarticle.recommend.server.repository.aigc.PublishAccountRepository;
 import com.tzld.longarticle.recommend.server.repository.aigc.PublishAccountRepository;
-import com.tzld.longarticle.recommend.server.service.recommend.ArticleAuditService;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
+import okhttp3.*;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.Test;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.util.StringUtils;
 import org.springframework.util.StringUtils;
 
 
 import javax.annotation.Resource;
 import javax.annotation.Resource;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.List;
+import java.util.concurrent.TimeUnit;
 
 
 @SpringBootTest(classes = Application.class)
 @SpringBootTest(classes = Application.class)
 @Slf4j
 @Slf4j
@@ -30,7 +42,7 @@ public class WxApiTest {
     @Resource
     @Resource
     private PublishContentMapper publishContentMapper;
     private PublishContentMapper publishContentMapper;
     @Resource
     @Resource
-    private ArticleAuditService articleAuditService;
+    private AigcBaseMapper aigcBaseMapper;
 
 
     @Test
     @Test
     public void clearQuotaTest() {
     public void clearQuotaTest() {
@@ -38,11 +50,92 @@ public class WxApiTest {
         List<PublishAccount> publishAccountList = publishAccountRepository.getAllByGhIdIn(ghIds);
         List<PublishAccount> publishAccountList = publishAccountRepository.getAllByGhIdIn(ghIds);
         for (PublishAccount publishAccount : publishAccountList) {
         for (PublishAccount publishAccount : publishAccountList) {
             String token = wxAccessTokenRemoteService.loadAccessToken(publishAccount.getGhId());
             String token = wxAccessTokenRemoteService.loadAccessToken(publishAccount.getGhId());
-            if(StringUtils.isEmpty(token)) {
+            if (StringUtils.isEmpty(token)) {
                 log.error("token is null ghId:{}", publishAccount.getGhId());
                 log.error("token is null ghId:{}", publishAccount.getGhId());
                 continue;
                 continue;
             }
             }
             wxArticleDeleteService.clearQuota(token, publishAccount.getAppId());
             wxArticleDeleteService.clearQuota(token, publishAccount.getAppId());
         }
         }
     }
     }
+
+    @Test
+    public void testDeepSeekR1Synopsis() {
+        List<String> contentIds = longArticleBaseMapper.getPassContentIds();
+        List<ProduceContentDTO> contentList = aigcBaseMapper.getProduceContentById(contentIds);
+        List<JSONObject> result = new ArrayList<>();
+        for (ProduceContentDTO item : contentList) {
+            String prompt = "你是1个优秀的公众号文章写作大师,我对你有以下要求\n" +
+                    "文章:{text}" +
+                    "1.请仔细阅读以上公众号文章,挑选文章中最吸引人的情节或话题,总结为100字左右文章精彩总结(字数计算包括标点符号)。\n" +
+                    "句子段落之间以悬念承接,可以吸引读者往下读第二句。\n" +
+                    "2.在这100字内容的结尾处,增加1-2句话的引导,引导大家去观看上面的视频了解详情。注意是点击上面的视频,不是下面的视频。\n" +
+                    "\n" +
+                    "你最终输出一段总结内容,不用加标题或者主题,也不用写第几段、多少字这样的话。整体的语言风格要口语化、直接点,要让60岁以上的老年人能看懂、能共情。人的名字尽量用全名,不用简称。";
+            prompt = prompt.replace("{text}", item.getBodyText());
+            JSONObject param = JSONObject.parseObject("{\"model\":\"ep-20250210155214-v55rk\",\"messages\":[{\"role\":\"user\",\"content\":\"Hello!\"}]}");
+            param.getJSONArray("messages").getJSONObject(0).put("content", prompt);
+            OkHttpClient client = new OkHttpClient().newBuilder()
+                    .connectTimeout(15, TimeUnit.MINUTES)
+                    .readTimeout(15, TimeUnit.MINUTES)
+                    .writeTimeout(15, TimeUnit.MINUTES)
+                    .build();
+            MediaType mediaType = MediaType.parse("application/json");
+            RequestBody body = RequestBody.create(mediaType, param.toJSONString());
+            Request request = new Request.Builder()
+                    .url("https://ark.cn-beijing.volces.com/api/v3/chat/completions")
+                    .method("POST", body)
+                    .addHeader("Content-Type", "application/json")
+                    .addHeader("Authorization", "Bearer f88181af-f2ea-4af4-b935-8100b630e0ee")
+                    .build();
+
+            try {
+                Response response = client.newCall(request).execute();
+                String responseContent = response.body().string();
+                log.info("deepseek api responseContent = {}", responseContent);
+                JSONObject responseObj = JSONObject.parseObject(responseContent);
+
+                JSONObject res = new JSONObject();
+                res.put("id", item.getContentId());
+                res.put("bodyText", item.getBodyText());
+                res.put("synopsis", responseObj.getJSONArray("choices").getJSONObject(0).getJSONObject("message").getString("content"));
+                result.add(res);
+            } catch (IOException e) {
+                log.error(e.getMessage());
+            }
+        }
+
+
+        Workbook workbook = new XSSFWorkbook();
+        Sheet sheet = workbook.createSheet("ExampleSheet");
+        int rowNum = 0;
+        // 创建标题行
+        Row titleRow = sheet.createRow(rowNum);
+        Cell titleCell = titleRow.createCell(0);
+        titleCell.setCellValue("id");
+        titleCell = titleRow.createCell(1);
+        titleCell.setCellValue("正文");
+        titleCell = titleRow.createCell(2);
+        titleCell.setCellValue("总结");
+        for (JSONObject item : result) {
+            rowNum++;
+            Row row = sheet.createRow(rowNum);
+            Cell cell = row.createCell(0);
+            cell.setCellValue(item.getString("id"));
+            cell = row.createCell(1);
+            cell.setCellValue(item.getString("bodyText"));
+            cell = row.createCell(2);
+            cell.setCellValue(item.getString("synopsis"));
+        }
+        try (FileOutputStream outputStream = new FileOutputStream("/Users/wangyunpeng/Downloads/synopsis.xlsx")) {
+            workbook.write(outputStream);
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                workbook.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+    }
 }
 }