Files
aida_back/src/main/java/com/ai/da/controller/LLMController.java

75 lines
3.3 KiB
Java
Raw Normal View History

2025-05-18 12:46:12 +08:00
package com.ai.da.controller;
import com.ai.da.common.response.PageBaseResponse;
import com.ai.da.common.response.Response;
import com.ai.da.mapper.primary.entity.ChatMessage;
import com.ai.da.model.dto.*;
import com.ai.da.service.LLMService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
2025-11-25 16:46:05 +08:00
import jakarta.annotation.Resource;
2025-05-18 12:46:12 +08:00
import java.util.*;
@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,
2025-05-22 10:11:21 +08:00
@RequestParam(required = false) Long projectId,
2025-05-18 12:46:12 +08:00
@RequestParam(required = false) String fileUrl,
2025-05-19 10:47:02 +08:00
@RequestParam(required = false) List<String> imageUrlList,
2025-05-21 21:03:15 +08:00
@RequestParam(required = false) String process,
2025-05-20 16:47:43 +08:00
@RequestParam String token,
@RequestParam Boolean enableThinking) {
2025-05-21 21:03:15 +08:00
return llmService.stream(prompt, projectId, fileUrl, imageUrlList, token, enableThinking, process);
2025-05-18 12:46:12 +08:00
}
2025-06-02 16:19:41 +08:00
@ApiOperation(value = "对话")
@CrossOrigin
@GetMapping(value = "/streamNew", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public SseEmitter streamNew(@RequestParam String prompt,
@RequestParam(required = false) Long projectId,
@RequestParam(required = false) String fileUrl,
@RequestParam(required = false) List<String> imageUrlList,
@RequestParam(required = false) String process,
@RequestParam String token,
@RequestParam Boolean enableThinking) {
return llmService.streamNew(prompt, projectId, fileUrl, imageUrlList, token, enableThinking, process);
}
2025-05-18 12:46:12 +08:00
@ApiOperation(value = "对话创建项目")
2025-05-19 10:23:53 +08:00
@GetMapping(value = "/chatCreateProject")
2025-05-20 16:54:20 +08:00
public Response<Long> chatCreateProject(@RequestParam String prompt, @RequestParam String process,
@RequestParam(required = false) String fileUrl,
@RequestParam(required = false) List<String> imageUrlList) {
return Response.success(llmService.chatCreateProject(prompt, process, fileUrl, imageUrlList));
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
}
}