package org.jeecg.modules.ai; import org.jeecg.JeecgSystemApplication; import org.jeecg.modules.ai.service.IFilePdfInfoService; import org.jeecg.modules.ai.service.IWebSocketAiService; import org.jeecg.modules.ai.vo.FilePdfSelectVo; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import java.io.File; /** * @author clown * * @date 2024/7/16 */ @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,classes = JeecgSystemApplication.class) public class AiTest { @Autowired private IFilePdfInfoService filePdfInfoService; @Autowired private IWebSocketAiService webSocketAiService; @Test public void selectChatIA() { webSocketAiService.selectChatIA(); } @Test public void filePdf() { // 指定文件夹路径 String directoryPath = "F:\\file"; // 创建File对象表示文件夹 File directory = new File(directoryPath); // 获取文件夹中所有文件和文件夹 File[] files = directory.listFiles(); // 检查文件数组是否为空以及是否存在文件 if (files != null && files.length > 0) { // 遍历文件数组,打印每个文件的名字 for (File file : files) { if (file.isFile()) { // 确保是文件而非文件夹 System.out.println(file.getName()); filePdfInfoService.uploadFilePdf (new File(directoryPath + "\\" + file.getName())); } } } else { System.out.println("文件夹为空或不存在。"); } } @Test public void filePdfImg() { FilePdfSelectVo vo = new FilePdfSelectVo(); vo.setPdfContent("刀长"); vo.setPdfFileId("1821103772084142082"); filePdfInfoService.findImgPathList(vo); } @Test public void sendJsonToHttpsPost() { /* String name = "{\"id\":\"683a65fd-8feb-4446-ad32-714c4785f667\",\"messages\":[{\"role\":\"user\",\"content\":\"给我讲个故事?\"}],\"stream\":true,\"max_tokens\":500}"; // JSON数据 String url = "https://836u458t54.vicp.fun/chat/test_chat"; String aiPost = AiTestUils.sendJsonToHttpsPost(url, name); System.out.println(aiPost);*/ String s = "\"data\": {\"id\": \"683a65fd-8feb-4446-ad32-714c4785f667\", \"created\": 1723105518, \"model\": \"YxCareer0.7\", \"choices\": [{\"index\": 0, \"delta\": {\"role\": \"assistant\", \"content\": \"\"}, \"finish_reason\": null}]}"; System.out.println(s); } }