Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ FROM eclipse-temurin:17-jdk-jammy
WORKDIR /app
COPY --from=build /app/app/target/tiny-engine-app-*.jar /app/tiny-engine-app.jar
COPY --from=build /app/base/target/tiny-engine-base-*.jar /app/tiny-engine-base.jar

# 设置环境变量
ENV ACCESS_KEY_ID=" "
ENV ACCESS_KEY_SECRET = " "
ENV INDEX_ID = " "
ENV WORK_SPACE_ID = ""
ENTRYPOINT ["java", "-jar", "tiny-engine-app.jar", "--spring.profiles.active=alpha"]
EXPOSE 9090

Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@

import com.tinyengine.it.common.base.Result;
import com.tinyengine.it.common.log.SystemControllerLog;
import com.tinyengine.it.model.dto.AiParam;
import com.tinyengine.it.model.dto.ChatRequest;
import com.tinyengine.it.service.app.AiChatService;
import com.tinyengine.it.model.dto.NodeDto;

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

import java.util.Map;
import java.util.List;

/**
* The type Ai chat controller.
Expand All @@ -49,12 +48,6 @@
@RequestMapping("/app-center/api")
@Tag(name = "AIChat")
public class AiChatController {
/**
* The Ai chat service.
*/
@Autowired
private AiChatService aiChatService;

/**
* The Ai chat v1 service.
*/
Expand All @@ -64,18 +57,34 @@ public class AiChatController {
/**
* AI api
*
* @param aiParam the AI param
* @param request the AI param
* @return ai回答信息 result
*/
@Operation(summary = "获取ai回答信息", description = "获取ai回答信息", parameters = {
@Parameter(name = "AiParam", description = "入参对象")}, responses = {
@Operation(summary = "获取ai回答信息", description = "获取ai回答信息",
parameters = {
@Parameter(name = "ChatRequest", description = "入参对象")
}, responses = {
@ApiResponse(responseCode = "200", description = "返回信息",
content = @Content(mediaType = "application/json", schema = @Schema())),
@ApiResponse(responseCode = "400", description = "请求失败")})
content = @Content(mediaType = "application/json", schema = @Schema())),
@ApiResponse(responseCode = "400", description = "请求失败")
})
@SystemControllerLog(description = "AI api")
@PostMapping("/ai/chat")
public Result<Map<String, Object>> aiChat(@RequestBody AiParam aiParam) {
return aiChatService.getAnswerFromAi(aiParam);
public ResponseEntity<?> aiChat(@RequestBody ChatRequest request) {
try {
Object response = aiChatV1Service.chatCompletion(request);

if (request.isStream()) {
return ResponseEntity.ok()
.contentType(MediaType.TEXT_EVENT_STREAM)
.body((StreamingResponseBody) response);
} else {
return ResponseEntity.ok(response);
}
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(e.getMessage());
}
}

/**
Expand All @@ -84,11 +93,14 @@ public Result<Map<String, Object>> aiChat(@RequestBody AiParam aiParam) {
* @param request the AI param
* @return ai回答信息 result
*/
@Operation(summary = "获取ai回答信息", description = "获取ai回答信息", parameters = {
@Parameter(name = "ChatRequest", description = "入参对象")}, responses = {
@Operation(summary = "获取ai回答信息", description = "获取ai回答信息",
parameters = {
@Parameter(name = "ChatRequest", description = "入参对象")
}, responses = {
@ApiResponse(responseCode = "200", description = "返回信息",
content = @Content(mediaType = "application/json", schema = @Schema())),
@ApiResponse(responseCode = "400", description = "请求失败")})
@ApiResponse(responseCode = "400", description = "请求失败")
})
@SystemControllerLog(description = "AI api v1")
@PostMapping("/chat/completions")
public ResponseEntity<?> chat(@RequestBody ChatRequest request) {
Expand All @@ -97,14 +109,34 @@ public ResponseEntity<?> chat(@RequestBody ChatRequest request) {

if (request.isStream()) {
return ResponseEntity.ok()
.contentType(MediaType.TEXT_EVENT_STREAM)
.body((StreamingResponseBody) response);
.contentType(MediaType.TEXT_EVENT_STREAM)
.body((StreamingResponseBody) response);
} else {
return ResponseEntity.ok(response);
}
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(e.getMessage());
.body(e.getMessage());
}
}

/**
* AI search api
*
* @param content the AI search param
* @return ai回答信息 result
*/
@Operation(summary = "搜索知识库", description = "搜索知识库",
parameters = {
@Parameter(name = "content", description = "入参对象")
}, responses = {
@ApiResponse(responseCode = "200", description = "返回信息",
content = @Content(mediaType = "application/json", schema = @Schema())),
@ApiResponse(responseCode = "400", description = "请求失败")
})
@SystemControllerLog(description = "AI serarch api")
@PostMapping("/ai/search")
public Result<List<NodeDto>> search(@RequestBody String content) throws Exception {
return aiChatV1Service.chatSearch(content);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ public class ChatRequest {
private Object messages;
private Object tools;
private Double temperature = 0.7;
private boolean stream = false; // 流式开关
private boolean stream = false;
private Integer maxTokens;
}
27 changes: 27 additions & 0 deletions base/src/main/java/com/tinyengine/it/model/dto/NodeDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright (c) 2023 - present TinyEngine Authors.
* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd.
*
* Use of this source code is governed by an MIT-style license.
*
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
*
*/

package com.tinyengine.it.model.dto;

import lombok.Data;

/**
* Node dto
*
* @since 2025-09-16
*/
@Data
public class NodeDto {
private Double score;
private String docName;
private String content;
}
Loading
Loading