1414
1515import com .tinyengine .it .common .base .Result ;
1616import com .tinyengine .it .common .log .SystemControllerLog ;
17- import com .tinyengine .it .model .dto .AiParam ;
1817import com .tinyengine .it .model .dto .ChatRequest ;
19- import com .tinyengine .it .service . app . AiChatService ;
18+ import com .tinyengine .it .model . dto . NodeDto ;
2019
2120import com .tinyengine .it .service .app .v1 .AiChatV1Service ;
2221import io .swagger .v3 .oas .annotations .Operation ;
3736import org .springframework .web .bind .annotation .RestController ;
3837import 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.
4948@ RequestMapping ("/app-center/api" )
5049@ Tag (name = "AIChat" )
5150public 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}
0 commit comments