Skip to content

Commit 380d954

Browse files
authored
fix: modify block group (opentiny#259)
* fix: modify AI chat
1 parent 0eabdf8 commit 380d954

File tree

10 files changed

+362
-109
lines changed

10 files changed

+362
-109
lines changed

Dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ FROM eclipse-temurin:17-jdk-jammy
1414
WORKDIR /app
1515
COPY --from=build /app/app/target/tiny-engine-app-*.jar /app/tiny-engine-app.jar
1616
COPY --from=build /app/base/target/tiny-engine-base-*.jar /app/tiny-engine-base.jar
17-
17+
# 设置环境变量
18+
ENV ACCESS_KEY_ID=" "
19+
ENV ACCESS_KEY_SECRET = " "
20+
ENV INDEX_ID = " "
21+
ENV WORK_SPACE_ID = ""
1822
ENTRYPOINT ["java", "-jar", "tiny-engine-app.jar", "--spring.profiles.active=alpha"]
1923
EXPOSE 9090
2024

base/src/main/java/com/tinyengine/it/controller/AiChatController.java

Lines changed: 54 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414

1515
import com.tinyengine.it.common.base.Result;
1616
import com.tinyengine.it.common.log.SystemControllerLog;
17-
import com.tinyengine.it.model.dto.AiParam;
1817
import com.tinyengine.it.model.dto.ChatRequest;
19-
import com.tinyengine.it.service.app.AiChatService;
18+
import com.tinyengine.it.model.dto.NodeDto;
2019

2120
import com.tinyengine.it.service.app.v1.AiChatV1Service;
2221
import io.swagger.v3.oas.annotations.Operation;
@@ -37,7 +36,7 @@
3736
import org.springframework.web.bind.annotation.RestController;
3837
import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody;
3938

40-
import java.util.Map;
39+
import java.util.List;
4140

4241
/**
4342
* The type Ai chat controller.
@@ -49,12 +48,6 @@
4948
@RequestMapping("/app-center/api")
5049
@Tag(name = "AIChat")
5150
public class AiChatController {
52-
/**
53-
* The Ai chat service.
54-
*/
55-
@Autowired
56-
private AiChatService aiChatService;
57-
5851
/**
5952
* The Ai chat v1 service.
6053
*/
@@ -64,18 +57,34 @@ public class AiChatController {
6457
/**
6558
* AI api
6659
*
67-
* @param aiParam the AI param
60+
* @param request the AI param
6861
* @return ai回答信息 result
6962
*/
70-
@Operation(summary = "获取ai回答信息", description = "获取ai回答信息", parameters = {
71-
@Parameter(name = "AiParam", description = "入参对象")}, responses = {
63+
@Operation(summary = "获取ai回答信息", description = "获取ai回答信息",
64+
parameters = {
65+
@Parameter(name = "ChatRequest", description = "入参对象")
66+
}, responses = {
7267
@ApiResponse(responseCode = "200", description = "返回信息",
73-
content = @Content(mediaType = "application/json", schema = @Schema())),
74-
@ApiResponse(responseCode = "400", description = "请求失败")})
68+
content = @Content(mediaType = "application/json", schema = @Schema())),
69+
@ApiResponse(responseCode = "400", description = "请求失败")
70+
})
7571
@SystemControllerLog(description = "AI api")
7672
@PostMapping("/ai/chat")
77-
public Result<Map<String, Object>> aiChat(@RequestBody AiParam aiParam) {
78-
return aiChatService.getAnswerFromAi(aiParam);
73+
public ResponseEntity<?> aiChat(@RequestBody ChatRequest request) {
74+
try {
75+
Object response = aiChatV1Service.chatCompletion(request);
76+
77+
if (request.isStream()) {
78+
return ResponseEntity.ok()
79+
.contentType(MediaType.TEXT_EVENT_STREAM)
80+
.body((StreamingResponseBody) response);
81+
} else {
82+
return ResponseEntity.ok(response);
83+
}
84+
} catch (Exception e) {
85+
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
86+
.body(e.getMessage());
87+
}
7988
}
8089

8190
/**
@@ -84,11 +93,14 @@ public Result<Map<String, Object>> aiChat(@RequestBody AiParam aiParam) {
8493
* @param request the AI param
8594
* @return ai回答信息 result
8695
*/
87-
@Operation(summary = "获取ai回答信息", description = "获取ai回答信息", parameters = {
88-
@Parameter(name = "ChatRequest", description = "入参对象")}, responses = {
96+
@Operation(summary = "获取ai回答信息", description = "获取ai回答信息",
97+
parameters = {
98+
@Parameter(name = "ChatRequest", description = "入参对象")
99+
}, responses = {
89100
@ApiResponse(responseCode = "200", description = "返回信息",
90101
content = @Content(mediaType = "application/json", schema = @Schema())),
91-
@ApiResponse(responseCode = "400", description = "请求失败")})
102+
@ApiResponse(responseCode = "400", description = "请求失败")
103+
})
92104
@SystemControllerLog(description = "AI api v1")
93105
@PostMapping("/chat/completions")
94106
public ResponseEntity<?> chat(@RequestBody ChatRequest request) {
@@ -97,14 +109,34 @@ public ResponseEntity<?> chat(@RequestBody ChatRequest request) {
97109

98110
if (request.isStream()) {
99111
return ResponseEntity.ok()
100-
.contentType(MediaType.TEXT_EVENT_STREAM)
101-
.body((StreamingResponseBody) response);
112+
.contentType(MediaType.TEXT_EVENT_STREAM)
113+
.body((StreamingResponseBody) response);
102114
} else {
103115
return ResponseEntity.ok(response);
104116
}
105117
} catch (Exception e) {
106118
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
107-
.body(e.getMessage());
119+
.body(e.getMessage());
108120
}
109121
}
122+
123+
/**
124+
* AI search api
125+
*
126+
* @param content the AI search param
127+
* @return ai回答信息 result
128+
*/
129+
@Operation(summary = "搜索知识库", description = "搜索知识库",
130+
parameters = {
131+
@Parameter(name = "content", description = "入参对象")
132+
}, responses = {
133+
@ApiResponse(responseCode = "200", description = "返回信息",
134+
content = @Content(mediaType = "application/json", schema = @Schema())),
135+
@ApiResponse(responseCode = "400", description = "请求失败")
136+
})
137+
@SystemControllerLog(description = "AI serarch api")
138+
@PostMapping("/ai/search")
139+
public Result<List<NodeDto>> search(@RequestBody String content) throws Exception {
140+
return aiChatV1Service.chatSearch(content);
141+
}
110142
}

base/src/main/java/com/tinyengine/it/model/dto/ChatRequest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@ public class ChatRequest {
2727
private Object messages;
2828
private Object tools;
2929
private Double temperature = 0.7;
30-
private boolean stream = false; // 流式开关
30+
private boolean stream = false;
31+
private Integer maxTokens;
3132
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Copyright (c) 2023 - present TinyEngine Authors.
3+
* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd.
4+
*
5+
* Use of this source code is governed by an MIT-style license.
6+
*
7+
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
8+
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
9+
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
10+
*
11+
*/
12+
13+
package com.tinyengine.it.model.dto;
14+
15+
import lombok.Data;
16+
17+
/**
18+
* Node dto
19+
*
20+
* @since 2025-09-16
21+
*/
22+
@Data
23+
public class NodeDto {
24+
private Double score;
25+
private String docName;
26+
private String content;
27+
}

0 commit comments

Comments
 (0)