ソースを参照

增加与ai大模型对话

wwh 3 週間 前
コミット
0d00a016c0

+ 6 - 6
huimv-employment/fe-api/src/main/java/com/huimv/employment/controller/mp/AiProxyController.java

@@ -37,17 +37,17 @@ public class AiProxyController {
37 37
     }
38 38
 
39 39
     @GetMapping("/models")
40
-    @Operation(summary = "获取可用模型列表", description = "OpenAI 兼容 GET /v1/models,透传上游 KB 服务响应。")
41
-    public ResponseEntity<byte[]> models() {
42
-        return kbOpenAiProxyService.listModels();
40
+    @Operation(summary = "获取版本信息", description = "OpenAI 兼容 GET /api/version,透传上游 KB 服务响应。")
41
+    public ResponseEntity<byte[]> getVersion() {
42
+        return kbOpenAiProxyService.getVersion();
43 43
     }
44 44
 
45
-    @PostMapping(value = "/chat/completions", consumes = MediaType.APPLICATION_JSON_VALUE)
45
+    @PostMapping(value = "/console/chat", consumes = MediaType.APPLICATION_JSON_VALUE)
46 46
     @Operation(summary = "对话补全(OpenAI 兼容)",
47 47
             description = "请求/响应体与 OpenAI Chat Completions 规范一致,透传上游 KB 服务。"
48 48
                     + "请求体示例:{\"model\":\"gpt-4\",\"messages\":[{\"role\":\"user\",\"content\":\"你好\"}],\"stream\":false}"
49 49
                     + ";stream=true 时返回 text/event-stream SSE 流式响应。")
50
-    public void chatCompletions(HttpServletRequest request, HttpServletResponse response) throws IOException {
50
+    public void consoleChat(HttpServletRequest request, HttpServletResponse response) throws IOException {
51 51
         byte[] body = StreamUtils.copyToByteArray(request.getInputStream());
52 52
         if (kbOpenAiProxyService.isStreamRequest(body)) {
53 53
             SseStreamSupport.prepareSseResponse(response);
@@ -55,7 +55,7 @@ public class AiProxyController {
55 55
             response.flushBuffer();
56 56
             return;
57 57
         }
58
-        ResponseEntity<byte[]> upstream = kbOpenAiProxyService.chatCompletions(body);
58
+        ResponseEntity<byte[]> upstream = kbOpenAiProxyService.consoleChat(body);
59 59
         response.setStatus(upstream.getStatusCodeValue());
60 60
         MediaType contentType = upstream.getHeaders().getContentType();
61 61
         if (contentType != null) {

+ 1 - 1
huimv-employment/fe-api/src/main/resources/application.yml

@@ -56,7 +56,7 @@ fe:
56 56
     enabled: true
57 57
     scheme: http
58 58
     host: harrison1.iask.in
59
-    port: 9107
59
+    port: 9188
60 60
     api-key: ${FE_KB_API_KEY:}
61 61
     default-model: default
62 62
     default-knowledge-base: default

+ 3 - 3
huimv-employment/fe-integration/src/main/java/com/huimv/employment/integration/kb/KbOpenAiProxyService.java

@@ -6,13 +6,13 @@ import java.io.IOException;
6 6
 import java.io.OutputStream;
7 7
 
8 8
 /**
9
- * 大模型 OpenAI 兼容接口转发({@code /v1/models}、{@code /v1/chat/completions})。
9
+ * 大模型 OpenAI 兼容接口转发({@code /api/version}、{@code /api/console/chat})。
10 10
  */
11 11
 public interface KbOpenAiProxyService {
12 12
 
13
-    ResponseEntity<byte[]> listModels();
13
+    ResponseEntity<byte[]> getVersion();
14 14
 
15
-    ResponseEntity<byte[]> chatCompletions(byte[] requestBody);
15
+    ResponseEntity<byte[]> consoleChat(byte[] requestBody);
16 16
 
17 17
     boolean isStreamRequest(byte[] requestBody);
18 18
 

+ 4 - 4
huimv-employment/fe-integration/src/main/java/com/huimv/employment/integration/kb/KbOpenAiProxyServiceImpl.java

@@ -29,8 +29,8 @@ import java.nio.charset.StandardCharsets;
29 29
 @Service
30 30
 public class KbOpenAiProxyServiceImpl implements KbOpenAiProxyService {
31 31
 
32
-    private static final String PATH_MODELS = "/v1/models";
33
-    private static final String PATH_CHAT = "/v1/chat/completions";
32
+    private static final String PATH_MODELS = "/api/version";
33
+    private static final String PATH_CHAT = "/api/console/chat";
34 34
 
35 35
     private final KbApiProperties properties;
36 36
     private final RestTemplate restTemplate;
@@ -45,7 +45,7 @@ public class KbOpenAiProxyServiceImpl implements KbOpenAiProxyService {
45 45
     }
46 46
 
47 47
     @Override
48
-    public ResponseEntity<byte[]> listModels() {
48
+    public ResponseEntity<byte[]> getVersion() {
49 49
         ensureReady();
50 50
         try {
51 51
             ResponseEntity<byte[]> upstream = restTemplate.exchange(
@@ -60,7 +60,7 @@ public class KbOpenAiProxyServiceImpl implements KbOpenAiProxyService {
60 60
     }
61 61
 
62 62
     @Override
63
-    public ResponseEntity<byte[]> chatCompletions(byte[] requestBody) {
63
+    public ResponseEntity<byte[]> consoleChat(byte[] requestBody) {
64 64
         ensureReady();
65 65
         if (requestBody == null || requestBody.length == 0) {
66 66
             throw new BizException(ErrorCode.BAD_REQUEST, "请求体不能为空");

+ 1 - 1
huimv-employment/fe-service/src/main/java/com/huimv/employment/service/agent/AgentChatService.java

@@ -45,7 +45,7 @@ public class AgentChatService {
45 45
                 : UUID.randomUUID().toString().replace("-", "");
46 46
 
47 47
         byte[] body = buildChatRequest(request.getMessage());
48
-        ResponseEntity<byte[]> upstream = kbOpenAiProxyService.chatCompletions(body);
48
+        ResponseEntity<byte[]> upstream = kbOpenAiProxyService.consoleChat(body);
49 49
         if (!upstream.getStatusCode().is2xxSuccessful()) {
50 50
             throw new BizException(ErrorCode.AI_SERVICE_FAILED, extractUpstreamError(upstream));
51 51
         }