默认系统提示词,放到 yml 中配置,并完善注释

This commit is contained in:
thinkgem
2025-04-21 16:46:22 +08:00
parent 4c5c0e63d5
commit d03ed31483
6 changed files with 60 additions and 44 deletions

View File

@@ -9,7 +9,7 @@
能获得最新且准确的结果。这种检索与生成相结合的方式,不仅提高了信息检索的准确性,还增强了回答的上下文关联性, 能获得最新且准确的结果。这种检索与生成相结合的方式,不仅提高了信息检索的准确性,还增强了回答的上下文关联性,
特别适合处理复杂的企业知识库。 特别适合处理复杂的企业知识库。
此外该模块,支持云上大模型和本地部署的大模型Ollama、DeepSeek、通义千问理论上支持所有 OpenAPI 标准接口的 AI 提供商。 此外该模块,支持在线大模型和本地部署的大模型Ollama、DeepSeek、通义千问理论上支持所有 OpenAPI 标准接口的 AI 提供商。
并能无缝集成多种嵌入式 AI 模型的向量数据库,如 Chroma、PGVector、Elasticsearch、Milvus 等,实现高效的数据存储、检索及分析。 并能无缝集成多种嵌入式 AI 模型的向量数据库,如 Chroma、PGVector、Elasticsearch、Milvus 等,实现高效的数据存储、检索及分析。
无论是大规模数据集还是高度专业化的领域知识JeeSite CMS + RAG + AI 都能提供定制化解决方案,满足企业多样化的业务需求和技术要求。 无论是大规模数据集还是高度专业化的领域知识JeeSite CMS + RAG + AI 都能提供定制化解决方案,满足企业多样化的业务需求和技术要求。
企业可以轻松管理和访问复杂的信息资源,促进内部知识共享和创新,从而在竞争激烈的市场环境中保持领先地位。 企业可以轻松管理和访问复杂的信息资源,促进内部知识共享和创新,从而在竞争激烈的市场环境中保持领先地位。

View File

@@ -37,7 +37,7 @@
<version>${project.parent.version}</version> <version>${project.parent.version}</version>
</dependency> </dependency>
<!-- 云上大模型 --> <!-- 在线大模型 -->
<dependency> <dependency>
<groupId>org.springframework.ai</groupId> <groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-model-openai</artifactId> <artifactId>spring-ai-starter-model-openai</artifactId>

View File

@@ -5,6 +5,7 @@
package com.jeesite.modules.cms.ai.config; package com.jeesite.modules.cms.ai.config;
import com.jeesite.common.datasource.DataSourceHolder; import com.jeesite.common.datasource.DataSourceHolder;
import com.jeesite.common.lang.StringUtils;
import com.jeesite.modules.cms.ai.properties.CmsAiProperties; import com.jeesite.modules.cms.ai.properties.CmsAiProperties;
import com.jeesite.modules.cms.ai.tools.CmsAiTools; import com.jeesite.modules.cms.ai.tools.CmsAiTools;
import org.springframework.ai.chat.client.ChatClient; import org.springframework.ai.chat.client.ChatClient;
@@ -29,17 +30,9 @@ public class CmsAiChatConfig {
*/ */
@Bean @Bean
public ChatClient chatClient(ChatClient.Builder builder, CmsAiProperties properties) { public ChatClient chatClient(ChatClient.Builder builder, CmsAiProperties properties) {
builder.defaultSystem(""" if (StringUtils.isNotBlank(properties.getDefaultSystem())) {
## 人物设定 builder.defaultSystem(properties.getDefaultSystem());
你是我的知识库AI助手你把我当作朋友耐心真诚地回复我提出的相关问题。 }
你需要遵循以下原则,与关注者进行友善而有价值的沟通。
## 表达方式:
1. 使用简体中文回答我的问题。
2. 使用幽默有趣的方式与我沟通。
3. 增加互动,如 “您的看法如何?”
4. 可以用表情,避免过多表情。
5. KaTeX 公式使用 $ 包裹。
""");
if (properties.getToolCalls()) { if (properties.getToolCalls()) {
builder.defaultTools(new CmsAiTools()); builder.defaultTools(new CmsAiTools());
} }

View File

@@ -7,6 +7,8 @@ public class CmsAiProperties {
private Boolean toolCalls = false; private Boolean toolCalls = false;
private String defaultSystem = "";
public Boolean getToolCalls() { public Boolean getToolCalls() {
return toolCalls; return toolCalls;
} }
@@ -14,4 +16,12 @@ public class CmsAiProperties {
public void setToolCalls(Boolean toolCalls) { public void setToolCalls(Boolean toolCalls) {
this.toolCalls = toolCalls; this.toolCalls = toolCalls;
} }
public String getDefaultSystem() {
return defaultSystem;
}
public void setDefaultSystem(String defaultSystem) {
this.defaultSystem = defaultSystem;
}
} }

View File

@@ -40,8 +40,8 @@ import java.util.Map;
public class CmsAiChatService extends BaseService { public class CmsAiChatService extends BaseService {
private static final String CMS_CHAT_CACHE = "cmsChatCache"; private static final String CMS_CHAT_CACHE = "cmsChatCache";
private static final String[] USER_MESSAGE_SEARCH = new String[]{"{", "}", "$", "%"}; private static final String[] USER_MESSAGE_SEARCH = new String[]{"{", "}"};
private static final String[] USER_MESSAGE_REPLACE = new String[]{"\\{", "\\}", "\\$", "\\%"}; private static final String[] USER_MESSAGE_REPLACE = new String[]{"\\{", "\\}"};
@Autowired @Autowired
private ChatClient chatClient; private ChatClient chatClient;

View File

@@ -3,7 +3,7 @@
spring: spring:
ai: ai:
# 云上大模型(使用该模型,请开启 enabled 参数) # 在线大模型【请在 pom.xml 中打开 openai 的注释,并注释上其它模型】
openai: openai:
base-url: https://api.siliconflow.cn base-url: https://api.siliconflow.cn
api-key: ${SFLOW_APP_KEY} api-key: ${SFLOW_APP_KEY}
@@ -31,10 +31,7 @@ spring:
#model: text-embedding-v3 #model: text-embedding-v3
#dimensions: 1024 #dimensions: 1024
# 是否启用工具调用 # 本地大模型配置【请在 pom.xml 中打开 ollama 的注释,并注释上其它模型】
tool-calls: false
# 本地大模型配置(使用该模型,请开启 enabled 参数)
ollama: ollama:
base-url: http://localhost:11434 base-url: http://localhost:11434
# 聊天对话模型 # 聊天对话模型
@@ -58,16 +55,16 @@ spring:
# 向量数据库配置 # 向量数据库配置
vectorstore: vectorstore:
# Chroma 向量数据库 # Chroma 向量数据库【请在 pom.xml 中打开 chroma 的注释,并注释上其它向量库】
chroma: chroma:
client: client:
host: http://testserver host: http://testserver
port: 8000 port: 8000
initialize-schema: true initialize-schema: true
#collection-name: vector_store collection-name: vector_store
collection-name: vector_store_1024 #collection-name: vector_store_1024
# Postgresql 向量数据库PG 连接配置,见下文,需要手动建表) # Postgresql 向量数据库PG 连接配置,见下文,需要手动建表)【请在 pom.xml 中打开 pgvector 的注释,并注释上其它向量库】
pgvector: pgvector:
id-type: TEXT id-type: TEXT
index-type: HNSW index-type: HNSW
@@ -81,14 +78,14 @@ spring:
dimensions: 1024 dimensions: 1024
max-document-batch-size: 10000 max-document-batch-size: 10000
# ES 向量数据库ES 连接配置,见下文) # ES 向量数据库ES 连接配置,见下文)【请在 pom.xml 中打开 elasticsearch 的注释,并注释上其它向量库】
elasticsearch: elasticsearch:
index-name: vector-index index-name: vector-index
initialize-schema: true initialize-schema: true
dimensions: 1024 dimensions: 1024
similarity: cosine similarity: cosine
# Milvus 向量数据库 # Milvus 向量数据库【请在 pom.xml 中打开 milvus 的注释,并注释上其它向量库】
milvus: milvus:
client: client:
host: "localhost" host: "localhost"
@@ -102,29 +99,45 @@ spring:
index-type: HNSW index-type: HNSW
metric-type: COSINE metric-type: COSINE
# 是否启用工具调用【例子详见 CmsAiTools.java 】
tool-calls: false
# 默认系统提示词
default-system: |
## 人物设定
你是我的知识库AI助手你把我当作朋友耐心真诚地回复我提出的相关问题。
你需要遵循以下原则,与关注者进行友善而有价值的沟通。
## 表达方式:
1. 使用简体中文回答我的问题。
2. 使用幽默有趣的方式与我沟通。
3. 可以用少量表情,避免过多表情。
4. 增加互动,如 “您的看法如何?”
# ========= Postgresql 向量数据库数据源 ========= # ========= Postgresql 向量数据库数据源 =========
jdbc: #jdbc:
ds_pgvector: # ds_pgvector:
type: postgresql # type: postgresql
driver: org.postgresql.Driver # driver: org.postgresql.Driver
url: jdbc:postgresql://127.0.0.1:5433/jeesite-ai # url: jdbc:postgresql://127.0.0.1:5433/jeesite-ai
username: postgres # username: postgres
password: postgres # password: postgres
testSql: SELECT 1 # testSql: SELECT 1
pool: # pool:
init: 0 # init: 0
minIdle: 0 # minIdle: 0
breakAfterAcquireFailure: true # breakAfterAcquireFailure: true
# ========= ES 向量数据库连接配置 ========= # ========= ES 向量数据库连接配置 =========
spring.elasticsearch: #spring.elasticsearch:
socket-timeout: 120s # socket-timeout: 120s
connection-timeout: 120s # connection-timeout: 120s
uris: http://127.0.0.1:9200 # uris: http://127.0.0.1:9200
username: elastic # username: elastic
password: elastic # password: elastic
# 对话消息存缓存,可自定义存数据库 # 对话消息存缓存,可自定义存数据库
j2cache: j2cache: