|
@@ -1,19 +1,31 @@
|
|
|
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.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.remote.WxAccessTokenRemoteService;
|
|
|
import com.tzld.longarticle.recommend.server.remote.WxArticleDeleteService;
|
|
|
import com.tzld.longarticle.recommend.server.repository.aigc.PublishAccountRepository;
|
|
|
-import com.tzld.longarticle.recommend.server.service.recommend.ArticleAuditService;
|
|
|
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.springframework.boot.test.context.SpringBootTest;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
@SpringBootTest(classes = Application.class)
|
|
|
@Slf4j
|
|
@@ -30,7 +42,7 @@ public class WxApiTest {
|
|
|
@Resource
|
|
|
private PublishContentMapper publishContentMapper;
|
|
|
@Resource
|
|
|
- private ArticleAuditService articleAuditService;
|
|
|
+ private AigcBaseMapper aigcBaseMapper;
|
|
|
|
|
|
@Test
|
|
|
public void clearQuotaTest() {
|
|
@@ -38,11 +50,92 @@ public class WxApiTest {
|
|
|
List<PublishAccount> publishAccountList = publishAccountRepository.getAllByGhIdIn(ghIds);
|
|
|
for (PublishAccount publishAccount : publishAccountList) {
|
|
|
String token = wxAccessTokenRemoteService.loadAccessToken(publishAccount.getGhId());
|
|
|
- if(StringUtils.isEmpty(token)) {
|
|
|
+ if (StringUtils.isEmpty(token)) {
|
|
|
log.error("token is null ghId:{}", publishAccount.getGhId());
|
|
|
continue;
|
|
|
}
|
|
|
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();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|