- 添加Ollama配置参数,包括基础URL、模型设置、超时配置等 - 创建AI知识库相关数据库表(文档表和分段表) - 实现AI数据分析服务,支持订单数据查询和分析 - 开发AI聊天控制器,提供模型列表、对话和流式对话功能 - 构建知识库RAG服务,支持文档上传、CMS同步和问答功能 - 添加多种AI相关的DTO类和实体类 - 实现AI嵌入向量计算和相似度匹配算法 - 集成Tika用于文档内容提取和解析
55 lines
1.9 KiB
Java
55 lines
1.9 KiB
Java
package com.gxwebsoft.ai.controller;
|
||
|
||
import com.gxwebsoft.ai.dto.*;
|
||
import com.gxwebsoft.ai.service.AiKbRagService;
|
||
import com.gxwebsoft.common.core.web.ApiResult;
|
||
import com.gxwebsoft.common.core.web.BaseController;
|
||
import io.swagger.v3.oas.annotations.Operation;
|
||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||
import org.springframework.security.access.prepost.PreAuthorize;
|
||
import org.springframework.web.bind.annotation.*;
|
||
import org.springframework.web.multipart.MultipartFile;
|
||
|
||
import javax.annotation.Resource;
|
||
|
||
@Tag(name = "AI - 知识库(RAG)")
|
||
@RestController
|
||
@RequestMapping("/api/ai/kb")
|
||
public class AiKbController extends BaseController {
|
||
@Resource
|
||
private AiKbRagService ragService;
|
||
|
||
@PreAuthorize("isAuthenticated()")
|
||
@Operation(summary = "上传文档入库(txt/md/html 优先)")
|
||
@PostMapping("/upload")
|
||
public ApiResult<AiKbIngestResult> upload(@RequestParam("file") MultipartFile file) {
|
||
Integer tenantId = getTenantId();
|
||
return success(ragService.ingestUpload(tenantId, file));
|
||
}
|
||
|
||
@PreAuthorize("isAuthenticated()")
|
||
@Operation(summary = "同步 CMS 文章到知识库(当前租户)")
|
||
@PostMapping("/sync/cms")
|
||
public ApiResult<AiKbIngestResult> syncCms() {
|
||
Integer tenantId = getTenantId();
|
||
return success(ragService.syncCms(tenantId));
|
||
}
|
||
|
||
@PreAuthorize("isAuthenticated()")
|
||
@Operation(summary = "仅检索(返回 topK 命中)")
|
||
@PostMapping("/query")
|
||
public ApiResult<AiKbQueryResult> query(@RequestBody AiKbQueryRequest request) {
|
||
Integer tenantId = getTenantId();
|
||
return success(ragService.query(tenantId, request));
|
||
}
|
||
|
||
@PreAuthorize("isAuthenticated()")
|
||
@Operation(summary = "知识库问答(RAG 生成 + 返回检索结果)")
|
||
@PostMapping("/ask")
|
||
public ApiResult<AiKbAskResult> ask(@RequestBody AiKbAskRequest request) {
|
||
Integer tenantId = getTenantId();
|
||
return success(ragService.ask(tenantId, request));
|
||
}
|
||
}
|
||
|