commit configuration files

This commit is contained in:
weiweiw 2024-12-29 15:59:16 +08:00
parent 1ea399bec7
commit e50a06fd00
9 changed files with 527 additions and 1 deletions

View File

@ -0,0 +1,43 @@
# 服务器基本配置信息
# 除 log_verbose/HTTPX_DEFAULT_TIMEOUT 修改后即时生效
# 其它配置项修改后都需要重启服务器才能生效,服务运行期间请勿修改
# 生成该配置模板的项目代码版本,如这里的值与程序实际版本不一致,建议重建配置文件模板
version: 0.3.1.3
# 是否开启日志详细信息
log_verbose: false
# httpx 请求默认超时时间(秒)。如果加载模型或对话较慢,出现超时错误,可以适当加大该值。
HTTPX_DEFAULT_TIMEOUT: 300.0
# 知识库默认存储路径
KB_ROOT_PATH: /home/bns001/Langchain-Chatchat-latest-dev/chatchat_data/data/knowledge_base
# 数据库默认存储路径。如果使用sqlite可以直接修改DB_ROOT_PATH如果使用其它数据库请直接修改SQLALCHEMY_DATABASE_URI。
DB_ROOT_PATH:
/home/bns001/Langchain-Chatchat-latest-dev/chatchat_data/data/knowledge_base/info.db
# 知识库信息数据库连接URI
SQLALCHEMY_DATABASE_URI:
sqlite:////home/bns001/Langchain-Chatchat-latest-dev/chatchat_data/data/knowledge_base/info.db
# API 是否开启跨域
OPEN_CROSS_DOMAIN: false
# 各服务器默认绑定host。如改为"0.0.0.0"需要修改下方所有XX_SERVER的host
# Windows 下 WEBUI 自动弹出浏览器时,如果地址为 "0.0.0.0" 是无法访问的,需要手动修改地址栏
DEFAULT_BIND_HOST: 0.0.0.0
# API 服务器地址。其中 public_host 用于生成云服务公网访问链接(如知识库文档链接)
API_SERVER:
host: 0.0.0.0
port: 7861
public_host: 127.0.0.1
public_port: 7861
# WEBUI 服务器地址
WEBUI_SERVER:
host: 0.0.0.0
port: 8501

View File

@ -0,0 +1,114 @@
# 知识库相关配置
# 默认使用的知识库
DEFAULT_KNOWLEDGE_BASE: samples
# 默认向量库/全文检索引擎类型
# 可选值:['faiss', 'milvus', 'zilliz', 'pg', 'es', 'relyt', 'chromadb']
DEFAULT_VS_TYPE: faiss
# 缓存向量库数量针对FAISS
CACHED_VS_NUM: 1
# 缓存临时向量库数量针对FAISS用于文件对话
CACHED_MEMO_VS_NUM: 10
# 知识库中单段文本长度(不适用MarkdownHeaderTextSplitter)
CHUNK_SIZE: 750
# 知识库中相邻文本重合长度(不适用MarkdownHeaderTextSplitter)
OVERLAP_SIZE: 150
# 知识库匹配向量数量
VECTOR_SEARCH_TOP_K: 3
# 知识库匹配相关度阈值取值范围在0-2之间SCORE越小相关度越高取到2相当于不筛选建议设置在0.5左右
SCORE_THRESHOLD: 2.0
# 默认搜索引擎
# 可选值:['bing', 'duckduckgo', 'metaphor', 'searx']
DEFAULT_SEARCH_ENGINE: duckduckgo
# 搜索引擎匹配结题数量
SEARCH_ENGINE_TOP_K: 3
# 是否开启中文标题加强,以及标题增强的相关配置
ZH_TITLE_ENHANCE: false
# PDF OCR 控制:只对宽高超过页面一定比例(图片宽/页面宽,图片高/页面高)的图片进行 OCR。
# 这样可以避免 PDF 中一些小图片的干扰,提高非扫描版 PDF 处理速度
PDF_OCR_THRESHOLD:
- 0.6
- 0.6
# 每个知识库的初始化介绍用于在初始化知识库时显示和Agent调用没写则没有介绍不会被Agent调用。
KB_INFO:
samples: 关于本项目issue的解答
# 可选向量库类型及对应配置
kbs_config:
faiss: {}
milvus:
host: 127.0.0.1
port: '19530'
user: ''
password: ''
secure: false
zilliz:
host: in01-a7ce524e41e3935.ali-cn-hangzhou.vectordb.zilliz.com.cn
port: '19530'
user: ''
password: ''
secure: true
pg:
connection_uri: postgresql://postgres:postgres@127.0.0.1:5432/langchain_chatchat
relyt:
connection_uri: postgresql+psycopg2://postgres:postgres@127.0.0.1:7000/langchain_chatchat
es:
scheme: http
host: 127.0.0.1
port: '9200'
index_name: test_index
user: ''
password: ''
verify_certs: true
ca_certs:
client_cert:
client_key:
milvus_kwargs:
search_params:
metric_type: L2
index_params:
metric_type: L2
index_type: HNSW
chromadb: {}
# TextSplitter配置项如果你不明白其中的含义就不要修改。
# source 如果选择tiktoken则使用openai的方法 "huggingface"
text_splitter_dict:
ChineseRecursiveTextSplitter:
source: ''
tokenizer_name_or_path: ''
SpacyTextSplitter:
source: huggingface
tokenizer_name_or_path: gpt2
RecursiveCharacterTextSplitter:
source: tiktoken
tokenizer_name_or_path: cl100k_base
MarkdownHeaderTextSplitter:
headers_to_split_on:
- - '#'
- head1
- - '##'
- head2
- - '###'
- head3
- - '####'
- head4
# TEXT_SPLITTER 名称
TEXT_SPLITTER_NAME: ChineseRecursiveTextSplitter
# Embedding模型定制词语的词表文件
EMBEDDING_KEYWORD_FILE: embedding_keywords.txt

View File

@ -0,0 +1,189 @@
# 模型配置项
# 默认选用的 LLM 名称
DEFAULT_LLM_MODEL: qwen2-instruct
# 默认选用的 Embedding 名称
DEFAULT_EMBEDDING_MODEL: bge-large-zh-v1.5
# AgentLM模型的名称 (可以不指定指定之后就锁定进入Agent之后的Chain的模型不指定就是 DEFAULT_LLM_MODEL)
Agent_MODEL: ''
# 默认历史对话轮数
HISTORY_LEN: 3
# 大模型最长支持的长度,如果不填写,则使用模型默认的最大长度,如果填写,则为用户设定的最大长度
MAX_TOKENS:
# LLM通用对话参数
TEMPERATURE: 0.7
# 支持的Agent模型
SUPPORT_AGENT_MODELS:
- chatglm3-6b
- glm-4
- openai-api
- Qwen-2
- qwen2-instruct
- gpt-3.5-turbo
- gpt-4o
# LLM模型配置包括了不同模态初始化参数。
# `model` 如果留空则自动使用 DEFAULT_LLM_MODEL
LLM_MODEL_CONFIG:
preprocess_model:
model: ''
temperature: 0.05
max_tokens: 4096
history_len: 10
prompt_name: default
callbacks: false
llm_model:
model: ''
temperature: 0.9
max_tokens: 4096
history_len: 10
prompt_name: default
callbacks: true
action_model:
model: ''
temperature: 0.01
max_tokens: 4096
history_len: 10
prompt_name: ChatGLM3
callbacks: true
postprocess_model:
model: ''
temperature: 0.01
max_tokens: 4096
history_len: 10
prompt_name: default
callbacks: true
image_model:
model: sd-turbo
size: 256*256
# # 模型加载平台配置
# # 平台名称
# platform_name: xinference
# # 平台类型
# # 可选值:['xinference', 'ollama', 'oneapi', 'fastchat', 'openai', 'custom openai']
# platform_type: xinference
# # openai api url
# api_base_url: http://127.0.0.1:9997/v1
# # api key if available
# api_key: EMPTY
# # API 代理
# api_proxy: ''
# # 该平台单模型最大并发数
# api_concurrencies: 5
# # 是否自动获取平台可用模型列表。设为 True 时下方不同模型类型可自动检测
# auto_detect_model: false
# # 该平台支持的大语言模型列表auto_detect_model 设为 True 时自动检测
# llm_models: []
# # 该平台支持的嵌入模型列表auto_detect_model 设为 True 时自动检测
# embed_models: []
# # 该平台支持的图像生成模型列表auto_detect_model 设为 True 时自动检测
# text2image_models: []
# # 该平台支持的多模态模型列表auto_detect_model 设为 True 时自动检测
# image2text_models: []
# # 该平台支持的重排模型列表auto_detect_model 设为 True 时自动检测
# rerank_models: []
# # 该平台支持的 STT 模型列表auto_detect_model 设为 True 时自动检测
# speech2text_models: []
# # 该平台支持的 TTS 模型列表auto_detect_model 设为 True 时自动检测
# text2speech_models: []
MODEL_PLATFORMS:
- platform_name: xinference
platform_type: xinference
api_base_url: http://127.0.0.1:9997/v1
api_key: EMPTY
api_proxy: ''
api_concurrencies: 5
auto_detect_model: true
llm_models: []
embed_models: []
text2image_models: []
image2text_models: []
rerank_models: []
speech2text_models: []
text2speech_models: []
- platform_name: ollama
platform_type: ollama
api_base_url: http://127.0.0.1:11434/v1
api_key: EMPTY
api_proxy: ''
api_concurrencies: 5
auto_detect_model: false
llm_models:
- qwen:7b
- qwen2:7b
embed_models:
- quentinz/bge-large-zh-v1.5
text2image_models: []
image2text_models: []
rerank_models: []
speech2text_models: []
text2speech_models: []
- platform_name: oneapi
platform_type: oneapi
api_base_url: http://127.0.0.1:3000/v1
api_key: sk-
api_proxy: ''
api_concurrencies: 5
auto_detect_model: false
llm_models:
- chatglm_pro
- chatglm_turbo
- chatglm_std
- chatglm_lite
- qwen-turbo
- qwen-plus
- qwen-max
- qwen-max-longcontext
- ERNIE-Bot
- ERNIE-Bot-turbo
- ERNIE-Bot-4
- SparkDesk
embed_models:
- text-embedding-v1
- Embedding-V1
text2image_models: []
image2text_models: []
rerank_models: []
speech2text_models: []
text2speech_models: []
- platform_name: openai
platform_type: openai
api_base_url: https://api.openai.com/v1
api_key: sk-proj-
api_proxy: ''
api_concurrencies: 5
auto_detect_model: false
llm_models:
- gpt-4o
- gpt-3.5-turbo
embed_models:
- text-embedding-3-small
- text-embedding-3-large
text2image_models: []
image2text_models: []
rerank_models: []
speech2text_models: []
text2speech_models: []

View File

@ -0,0 +1,76 @@
# Prompt 模板.除 Agent 模板使用 f-string 外,其它均使用 jinja2 格式
# 意图识别用模板
preprocess_model:
default: "你只要回复0 和 1 ,代表不需要使用工具。以下几种问题不需要使用工具:\n1. 需要联网查询的内容\n2. 需要计算的内容\n3. 需要查询实时性的内容\n\
如果我的输入满足这几种情况返回1。其他输入请你回复0你只要返回一个数字\n这是我的问题:"
# 普通 LLM 用模板
llm_model:
default: '{{input}}'
with_history: "The following is a friendly conversation between a human and an AI.\n
The AI is talkative and provides lots of specific details from its context.\n
If the AI does not know the answer to a question, it truthfully says it does not
know.\n\nCurrent conversation:\n{{history}}\nHuman: {{input}}\nAI:"
# RAG 用模板,可用于知识库问答、文件对话、搜索引擎对话
rag:
default: "【指令】根据已知信息,简洁和专业的来回答问题。如果无法从中得到答案,请说 “根据已知信息无法回答该问题”,不允许在答案中添加编造成分,答案请使用中文。\n\
\n【已知信息】{{context}}\n\n【问题】{{question}}\n"
empty: "请你回答我的问题:\n{{question}}"
# Agent 模板
action_model:
GPT-4: "Answer the following questions as best you can. You have access to the following
tools:\nThe way you use the tools is by specifying a json blob.\nSpecifically,
this json should have a `action` key (with the name of the tool to use) and a
`action_input` key (with the input to the tool going here).\nThe only values that
should be in the \"action\" field are: {tool_names}\nThe $JSON_BLOB should only
contain a SINGLE action, do NOT return a list of multiple actions. Here is an
example of a valid $JSON_BLOB:\n```\n\n{{{{\n \"action\": $TOOL_NAME,\n \"action_input\"\
: $INPUT\n}}}}\n```\n\nALWAYS use the following format:\nQuestion: the input question
you must answer\nThought: you should always think about what to do\nAction:\n
```\n\n$JSON_BLOB```\n\nObservation: the result of the action\n... (this Thought/Action/Observation
can repeat N times)\nThought: I now know the final answer\nFinal Answer: the final
answer to the original input question\nBegin! Reminder to always use the exact
characters `Final Answer` when responding.\nQuestion:{input}\nThought:{agent_scratchpad}\n"
ChatGLM3: "You can answer using the tools.Respond to the human as helpfully and
accurately as possible.\nYou have access to the following tools:\n{tools}\nUse
a json blob to specify a tool by providing an action key (tool name)\nand an action_input
key (tool input).\nValid \"action\" values: \"Final Answer\" or [{tool_names}]\n
Provide only ONE action per $JSON_BLOB, as shown:\n\n```\n{{{{\n \"action\":
$TOOL_NAME,\n \"action_input\": $INPUT\n}}}}\n```\n\nFollow this format:\n\n
Question: input question to answer\nThought: consider previous and subsequent
steps\nAction:\n```\n$JSON_BLOB\n```\nObservation: action result\n... (repeat
Thought/Action/Observation N times)\nThought: I know what to respond\nAction:\n\
```\n{{{{\n \"action\": \"Final Answer\",\n \"action_input\": \"Final response
to human\"\n}}}}\nBegin! Reminder to ALWAYS respond with a valid json blob of
a single action. Use tools if necessary.\nRespond directly if appropriate. Format
is Action:```$JSON_BLOB```then Observation:.\nQuestion: {input}\n\n{agent_scratchpad}\n"
qwen: "Answer the following questions as best you can. You have access to the following
APIs:\n\n{tools}\n\nUse the following format:\n\nQuestion: the input question
you must answer\nThought: you should always think about what to do\nAction: the
action to take, should be one of [{tool_names}]\nAction Input: the input to the
action\nObservation: the result of the action\n... (this Thought/Action/Action
Input/Observation can be repeated zero or more times)\nThought: I now know the
final answer\nFinal Answer: the final answer to the original input question\n\n
Format the Action Input as a JSON object.\n\nBegin!\n\nQuestion: {input}\n\n{agent_scratchpad}\n\
\n"
structured-chat-agent: "Respond to the human as helpfully and accurately as possible.
You have access to the following tools:\n\n{tools}\n\nUse a json blob to specify
a tool by providing an action key (tool name) and an action_input key (tool input).\n
\nValid \"action\" values: \"Final Answer\" or {tool_names}\n\nProvide only ONE
action per $JSON_BLOB, as shown:\n\n```\n{{\n \"action\": $TOOL_NAME,\n \"action_input\"\
: $INPUT\n}}\n```\n\nFollow this format:\n\nQuestion: input question to answer\n
Thought: consider previous and subsequent steps\nAction:\n```\n$JSON_BLOB\n```\n
Observation: action result\n... (repeat Thought/Action/Observation N times)\n
Thought: I know what to respond\nAction:\n```\n{{\n \"action\": \"Final Answer\"\
,\n \"action_input\": \"Final response to human\"\n}}\n\nBegin! Reminder to ALWAYS
respond with a valid json blob of a single action. Use tools if necessary. Respond
directly if appropriate. Format is Action:```$JSON_BLOB```then Observation\n{input}\n\
\n{agent_scratchpad}\n\n"
# 后处理模板
postprocess_model:
default: '{{input}}'

View File

@ -0,0 +1,96 @@
# Agent 工具配置项
# 本地知识库工具配置项
search_local_knowledgebase:
use: false
top_k: 3
score_threshold: 2.0
conclude_prompt:
with_result: "<指令>根据已知信息,简洁和专业的来回答问题。如果无法从中得到答案,请说 \"根据已知信息无法回答该问题\",不允许在答案中添加编造成分,答案请使用中文。
</指令>\n<已知信息>{{ context }}</已知信息>\n<问题>{{ question }}</问题>\n"
without_result: "请你根据我的提问回答我的问题:\n{{ question }}\n请注意你必须在回答结束后强调你的回答是根据你的经验回答而不是参考资料回答的。\n"
# 搜索引擎工具配置项。推荐自己部署 searx 搜索引擎,国内使用最方便。
search_internet:
use: false
search_engine_name: duckduckgo
search_engine_config:
bing:
bing_search_url: https://api.bing.microsoft.com/v7.0/search
bing_key: ''
metaphor:
metaphor_api_key: ''
split_result: false
chunk_size: 500
chunk_overlap: 0
duckduckgo: {}
searx:
host: https://metasearx.com
engines: []
categories: []
language: zh-CN
top_k: 5
verbose: Origin
conclude_prompt: "<指令>这是搜索到的互联网信息,请你根据这些信息进行提取并有调理,简洁的回答问题。如果无法从中得到答案,请说 “无法搜索到能回答问题的内容”。
</指令>\n<已知信息>{{ context }}</已知信息>\n<问题>\n{{ question }}\n</问题>\n"
arxiv:
use: false
# 心知天气https://www.seniverse.com/)工具配置项
weather_check:
use: true
api_key: 'SwOnf9XkLSik-uUBt'
search_youtube:
use: false
wolfram:
use: false
appid: ''
# numexpr 数学计算工具配置项
calculate:
use: false
# 图片生成工具配置项。model 必须是在 model_settings.yaml/MODEL_PLATFORMS 中配置过的。
text2images:
use: false
model: sd-turbo
size: 256*256
# text2sql使用建议
# 1、因大模型生成的sql可能与预期有偏差请务必在测试环境中进行充分测试、评估
# 2、生产环境中对于查询操作由于不确定查询效率推荐数据库采用主从数据库架构让text2sql连接从数据库防止可能的慢查询影响主业务
# 3、对于写操作应保持谨慎如不需要写操作设置read_only为True,最好再从数据库层面收回数据库用户的写权限,防止用户通过自然语言对数据库进行修改操作;
# 4、text2sql与大模型在意图理解、sql转换等方面的能力有关可切换不同大模型进行测试
# 5、数据库表名、字段名应与其实际作用保持一致、容易理解且应对数据库表名、字段进行详细的备注说明帮助大模型更好理解数据库结构
# 6、若现有数据库表名难于让大模型理解可配置下面table_comments字段补充说明某些表的作用。
text2sql:
model_name: qwen-plus
use: false
sqlalchemy_connect_str: mysql+pymysql://用户名:密码@主机地址/数据库名称
read_only: false
top_k: 50
return_intermediate_steps: true
table_names: []
table_comments: {}
# 高德地图、天气相关工具配置项。
amap:
use: false
api_key: 高德地图 API KEY
# text2promql 使用建议
# 1、因大模型生成的 promql 可能与预期有偏差, 请务必在测试环境中进行充分测试、评估;
# 2、text2promql 与大模型在意图理解、metric 选择、promql 转换等方面的能力有关, 可切换不同大模型进行测试;
# 3、当前仅支持 单prometheus 查询, 后续考虑支持 多prometheus 查询.
text2promql:
use: false
prometheus_endpoint: http://127.0.0.1:9090
username: ''
password: ''
# URL内容阅读https://r.jina.ai/)工具配置项
# 请确保部署的网络环境良好,以免造成超时等问题
url_reader:
use: false
timeout: '10000'

View File

@ -85,6 +85,7 @@ def regist_tool(
def _parse_tool(t: BaseTool):
nonlocal description, title
print(f"_parse_too:t.name : {t.name}")
_TOOLS_REGISTRY[t.name] = t
# change default description
@ -165,6 +166,7 @@ def format_context(self: BaseToolOutput) -> str:
doc = DocumentWithVSId.parse_obj(doc)
source_documents.append(doc.page_content)
print(f"format_context: doc.page_content: {doc.page_content}")
if len(source_documents) == 0:
context = "没有找到相关文档,请更换关键词重试"
else:

View File

@ -15,6 +15,7 @@ def weather_check(
):
"""Use this tool to check the weather at a specific city"""
print(f"weather_check,city{city}")
tool_config = get_tool_config("weather_check")
api_key = tool_config.get("api_key")
url = f"https://api.seniverse.com/v3/weather/now.json?key={api_key}&location={city}&language=zh-Hans&unit=c"

View File

@ -22,6 +22,7 @@ from chatchat.settings import Settings
from chatchat.utils import build_logger
from .openai_routes import openai_request, OpenAIChatOutput
# FastAPI 路由处理器,处理与对话相关的请求
logger = build_logger()
@ -73,12 +74,16 @@ async def chat_completions(
# check tools & tool_choice in request body
if isinstance(body.tool_choice, str):
logger.info(f"tool_choice")
if t := get_tool(body.tool_choice):
logger.info(f"function name: {t.name}")
body.tool_choice = {"function": {"name": t.name}, "type": "function"}
if isinstance(body.tools, list):
logger.info(f"tools")
for i in range(len(body.tools)):
if isinstance(body.tools[i], str):
if t := get_tool(body.tools[i]):
logger.info(f"function name: {t.name}")
body.tools[i] = {
"type": "function",
"function": {

View File

@ -46,7 +46,7 @@ if __name__ == "__main__":
with st.sidebar:
st.image(
get_img_base64("logo-long-chatchat-trans-v2.png"), use_column_width=True
get_img_base64("logo-long-chatchat-trans-v2.png"), use_container_width=True
)
st.caption(
f"""<p align="right">当前版本:{__version__}</p>""",