mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-11 13:19:01 +08:00
feat(ai-chat): 添加 AI 聊天功能及相关 DTO 和控制器
- 新增 `AiChatMessageDTO` 用于处理 AI 聊天消息 - 新增 `AiChatController` 提供 AI 聊天接口,支持普通聊天和网络搜索模式 - 在 `pom.xml` 中添加大模型相关依赖
This commit is contained in:
1 parent
4978ab23f6
commit
69d0589222
3 files changed
+82
No files matched your search
+23
@@ -0,0 +1,23 @@
|
||||
package com.pig4cloud.pigx.admin.api.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* AI 聊天消息 DTO
|
||||
*
|
||||
* @author lengleng
|
||||
* @date 2025/02/20
|
||||
*/
|
||||
@Data
|
||||
public class AiChatMessageDTO {
|
||||
|
||||
/**
|
||||
* 消息
|
||||
*/
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* 网络搜索
|
||||
*/
|
||||
private boolean webSearch;
|
||||
}
|
||||
@@ -174,6 +174,15 @@
|
||||
<groupId>org.dromara.sms4j</groupId>
|
||||
<artifactId>sms4j-oa-core</artifactId>
|
||||
</dependency>
|
||||
<!-- 大模型相关的配置 -->
|
||||
<dependency>
|
||||
<groupId>io.github.pig-mesh.ai</groupId>
|
||||
<artifactId>deepseek-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pigx-common-sse</artifactId>
|
||||
</dependency>
|
||||
<!-- 模板引擎-->
|
||||
<dependency>
|
||||
<groupId>org.apache.velocity</groupId>
|
||||
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
package com.pig4cloud.pigx.admin.controller;
|
||||
|
||||
import com.pig4cloud.pigx.admin.api.dto.AiChatMessageDTO;
|
||||
import io.github.pigmesh.ai.deepseek.core.DeepSeekClient;
|
||||
import io.github.pigmesh.ai.deepseek.core.chat.ChatCompletionResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* AI 聊天控制器
|
||||
*
|
||||
* @author lengleng
|
||||
* @date 2025/02/20
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/ai")
|
||||
@RequiredArgsConstructor
|
||||
public class AiChatController {
|
||||
|
||||
private final Optional<DeepSeekClient> deepSeekClientOptional;
|
||||
|
||||
|
||||
/**
|
||||
* 聊天
|
||||
*
|
||||
* @param message 消息
|
||||
* @return {@link Flux }<{@link ChatCompletionResponse }>
|
||||
*/
|
||||
@PostMapping("/chat")
|
||||
public Flux<ChatCompletionResponse> chat(@RequestBody AiChatMessageDTO message) {
|
||||
|
||||
if (deepSeekClientOptional.isEmpty()) {
|
||||
log.warn("DeepSeek 大模型聊天未开启,请检查配置");
|
||||
return Flux.empty();
|
||||
}
|
||||
|
||||
if (message.isWebSearch()) {
|
||||
return deepSeekClientOptional.get().chatSearchCompletion(message.getMessage());
|
||||
}
|
||||
return deepSeekClientOptional.get().chatFluxCompletion(message.getMessage());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user