2025-05-18 12:46:12 +08:00
|
|
|
package com.ai.da.controller;
|
|
|
|
|
|
|
|
|
|
import com.ai.da.common.config.exception.BusinessException;
|
|
|
|
|
import com.ai.da.common.response.PageBaseResponse;
|
|
|
|
|
import com.ai.da.common.response.Response;
|
|
|
|
|
import com.ai.da.mapper.primary.entity.Account;
|
|
|
|
|
import com.ai.da.mapper.primary.entity.AccountExtend;
|
|
|
|
|
import com.ai.da.mapper.primary.entity.ChatMessage;
|
|
|
|
|
import com.ai.da.mapper.primary.entity.TrialOrder;
|
|
|
|
|
import com.ai.da.model.dto.*;
|
|
|
|
|
import com.ai.da.model.vo.AccountLoginVO;
|
|
|
|
|
import com.ai.da.model.vo.AccountPreLoginVO;
|
|
|
|
|
import com.ai.da.model.vo.BindEmailVO;
|
|
|
|
|
import com.ai.da.model.vo.PersonalHomepageVO;
|
|
|
|
|
import com.ai.da.service.AccountService;
|
|
|
|
|
import com.ai.da.service.LLMService;
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
|
import org.springframework.http.MediaType;
|
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import javax.validation.Valid;
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
|
import java.io.OutputStream;
|
|
|
|
|
import java.net.HttpURLConnection;
|
|
|
|
|
import java.net.URL;
|
|
|
|
|
import java.net.URLEncoder;
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Api(tags = "llm模块")
|
|
|
|
|
@Slf4j
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/api/llm")
|
|
|
|
|
public class LLMController {
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private LLMService llmService;
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "对话")
|
|
|
|
|
@CrossOrigin
|
|
|
|
|
@GetMapping(value = "/stream", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
|
|
|
|
|
public SseEmitter streamPrompt(@RequestParam String prompt,
|
|
|
|
|
@RequestParam Long projectId,
|
|
|
|
|
@RequestParam(required = false) String fileUrl,
|
2025-05-19 10:47:02 +08:00
|
|
|
@RequestParam(required = false) List<String> imageUrlList,
|
2025-05-18 12:46:12 +08:00
|
|
|
@RequestParam String token) {
|
2025-05-19 10:47:02 +08:00
|
|
|
return llmService.stream(prompt, projectId, fileUrl, imageUrlList, token);
|
2025-05-18 12:46:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "对话创建项目")
|
2025-05-19 10:23:53 +08:00
|
|
|
@GetMapping(value = "/chatCreateProject")
|
2025-05-19 10:47:02 +08:00
|
|
|
public Response<Long> chatCreateProject(@RequestParam String prompt, @RequestParam String process) {
|
|
|
|
|
return Response.success(llmService.chatCreateProject(prompt, process));
|
2025-05-18 12:46:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "上传文件")
|
2025-05-19 10:23:53 +08:00
|
|
|
@PostMapping(value = "/uploadFile")
|
2025-05-19 10:15:16 +08:00
|
|
|
public Response<List<String>> uploadFile(@RequestParam("file") MultipartFile file) {
|
2025-05-18 12:46:12 +08:00
|
|
|
return Response.success(llmService.uploadFile(file));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "获取历史聊天记录")
|
2025-05-19 10:00:19 +08:00
|
|
|
@PostMapping(value = "/getChatHistory")
|
|
|
|
|
public Response<PageBaseResponse<ChatMessage>> getChatHistory(@RequestBody ChatHistoryDTO chatHistoryDTO) {
|
|
|
|
|
return Response.success(llmService.getChatHistory(chatHistoryDTO));
|
2025-05-18 12:46:12 +08:00
|
|
|
}
|
|
|
|
|
}
|