默认系统提示词,放到 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

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

View File

@@ -7,6 +7,8 @@ public class CmsAiProperties {
private Boolean toolCalls = false;
private String defaultSystem = "";
public Boolean getToolCalls() {
return toolCalls;
}
@@ -14,4 +16,12 @@ public class CmsAiProperties {
public void setToolCalls(Boolean 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 {
private static final String CMS_CHAT_CACHE = "cmsChatCache";
private static final String[] USER_MESSAGE_SEARCH = new String[]{"{", "}", "$", "%"};
private static final String[] USER_MESSAGE_REPLACE = new String[]{"\\{", "\\}", "\\$", "\\%"};
private static final String[] USER_MESSAGE_SEARCH = new String[]{"{", "}"};
private static final String[] USER_MESSAGE_REPLACE = new String[]{"\\{", "\\}"};
@Autowired
private ChatClient chatClient;

View File

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