feat:测试代码

law-v2025-01
wangxy 2 months ago
parent ed92b92573
commit 21afeb22b8

@ -7,6 +7,7 @@ import com.github.pagehelper.page.PageMethod;
import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.domain.R;
import com.ruoyi.framework.web.service.DeepSeekApiService; import com.ruoyi.framework.web.service.DeepSeekApiService;
import com.ruoyi.framework.web.service.DeepSeekLocalService;
import com.ruoyi.system.domain.SysColumn; import com.ruoyi.system.domain.SysColumn;
import com.ruoyi.system.domain.SysColumnVO; import com.ruoyi.system.domain.SysColumnVO;
import com.ruoyi.system.domain.SysSpecial; import com.ruoyi.system.domain.SysSpecial;
@ -95,6 +96,15 @@ public class LawController extends BaseController {
} }
@Autowired
private DeepSeekLocalService deepSeekLocalService;
@GetMapping("/call-local-deepseek")
public R callLocalDeepSeek(@RequestParam(required = false) String content) {
return R.ok(deepSeekLocalService.callLocalDeepSeek(content));
}
} }

@ -0,0 +1,63 @@
package com.ruoyi.framework.web.service;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import java.util.Arrays;
/**
* ClassName: DeepSeekLocalService
* Package: com.ruoyi.framework.web.service
* Description:
*
* @Author wangxy
* @Create 2025/2/14 14:50
* @Version 1.0
*/
@Service
public class DeepSeekLocalService {
private static final String LOCAL_API_URL = "http://localhost:8081/chat/completions";
private final RestTemplate restTemplate;
public DeepSeekLocalService(RestTemplate restTemplate) {
this.restTemplate = restTemplate;
}
public String callLocalDeepSeek(String content) {
// 设置请求头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
// 构建请求体
DeepSeekRequest.Message systemMessage = new DeepSeekRequest.Message();
systemMessage.setRole("system");
systemMessage.setContent("You are a helpful assistant.");
DeepSeekRequest.Message userMessage = new DeepSeekRequest.Message();
userMessage.setRole("user");
userMessage.setContent(content);
DeepSeekRequest requestBody = new DeepSeekRequest();
requestBody.setModel("deepseek-chat");
requestBody.setMessages(Arrays.asList(systemMessage, userMessage));
requestBody.setStream(false);
// 创建 HttpEntity
HttpEntity<DeepSeekRequest> requestEntity = new HttpEntity<>(requestBody, headers);
// 发送 POST 请求
ResponseEntity<String> response = restTemplate.exchange(
LOCAL_API_URL,
HttpMethod.POST,
requestEntity,
String.class
);
// 处理响应
if (response.getStatusCode() == HttpStatus.OK) {
return response.getBody();
} else {
throw new RuntimeException("Request failed with status code: " + response.getStatusCode());
}
}
}
Loading…
Cancel
Save