feat(ai): 完成基础版本功能
This commit is contained in:
@@ -32,13 +32,19 @@ public class ChatController {
|
||||
private final ChatClient chatClient;
|
||||
|
||||
public ChatController(ChatClient.Builder builder) {
|
||||
this.chatClient = builder
|
||||
.defaultSystem("始终在中文语境下进行对话")
|
||||
.build();
|
||||
this.chatClient = builder.build();
|
||||
}
|
||||
|
||||
private ChatClient.ChatClientRequestSpec buildRequest(ImmutableList<MessageVO> messages) {
|
||||
return chatClient.prompt()
|
||||
.system("""
|
||||
你是一名专业的AI运维助手,负责“Hudi数据同步服务平台”的运维工作;
|
||||
你将会友好地帮助用户解答关于该平台运维工作的问题,你会尽可能通过各种方式获取知识和数据来解答;
|
||||
对于无法通过已有知识回答的问题,你会提示用户你无法解答该问题,而不是虚构不存在的数据或答案;
|
||||
对于与该平台无关的问题,你会委婉地拒绝用户,并提示无法回答;
|
||||
你将始终在中文语境下进行对话。
|
||||
""")
|
||||
.tools(new DatetimeTools())
|
||||
.messages(
|
||||
messages
|
||||
.collect(message -> StrUtil.equals(message.getRole(), "assistant")
|
||||
@@ -52,9 +58,10 @@ public class ChatController {
|
||||
@PostMapping("sync")
|
||||
@ResponseBody
|
||||
public String chatSync(@RequestBody ImmutableList<MessageVO> messages) {
|
||||
return buildRequest(messages)
|
||||
String content = buildRequest(messages)
|
||||
.call()
|
||||
.content();
|
||||
return StrUtil.trimToEmpty(content);
|
||||
}
|
||||
|
||||
@PostMapping("async")
|
||||
|
||||
@@ -11,8 +11,8 @@ import org.springframework.ai.tool.annotation.Tool;
|
||||
public class DatetimeTools {
|
||||
private final static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
@Tool(description = "获取当前时间")
|
||||
public String getCurrentTime() {
|
||||
@Tool(description = "获取当前日期和时间")
|
||||
public String getCurrentDateTime() {
|
||||
return LocalDateTime.now().format(formatter);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,14 +2,14 @@ spring:
|
||||
application:
|
||||
name: service-ai-chat
|
||||
profiles:
|
||||
include: random-port,common,metrics,forest
|
||||
include: random-port,common,discovery,metrics,forest
|
||||
ai:
|
||||
openai:
|
||||
base-url: http://132.121.206.65:10086
|
||||
api-key: ENC(K+Hff9QGC+fcyi510VIDd9CaeK/IN5WBJ9rlkUsHEdDgIidW+stHHJlsK0lLPUXXREha+ToQZqqDXJrqSE+GUKCXklFhelD8bRHFXBIeP/ZzT2cxhzgKUXgjw3S0Qw2R)
|
||||
chat:
|
||||
options:
|
||||
model: 'Qwen3-1.7'
|
||||
model: 'Qwen3-1.7-vllm'
|
||||
mvc:
|
||||
async:
|
||||
request-timeout: 300000
|
||||
|
||||
@@ -29,6 +29,6 @@
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="Console"/>
|
||||
<!-- <appender-ref ref="RollingFile"/>-->
|
||||
<appender-ref ref="RollingFile"/>
|
||||
</root>
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user