|
|
@@ -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) {
|