chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 12:36:28 +08:00
commit 9d3590ab86
509 changed files with 2512422 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
---
name: Bug 报告 / Bug Report
about: 报告项目中的错误或问题 / Report errors or issues in the project
title: "[BUG] 简洁阐述问题 / Concise description of the issue"
labels: bug
assignees: ''
---
**问题描述 / Problem Description**
用简洁明了的语言描述这个问题 / Describe the problem in a clear and concise manner.
**复现问题的步骤 / Steps to Reproduce**
1. 执行 '...' / Run '...'
2. 点击 '...' / Click '...'
3. 滚动到 '...' / Scroll to '...'
4. 问题出现 / Problem occurs
**预期的结果 / Expected Result**
描述应该出现的结果 / Describe the expected result.
**实际结果 / Actual Result**
描述实际发生的结果 / Describe the actual result.
**环境信息 / Environment Information**
- Langchain-Chatchat 版本 / commit 号:(例如:0.3.1 或 commit 123456) / Langchain-Chatchat version / commit number: (e.g., 0.3.1 or commit 123456)
- 部署方式(pypi 安装 / 源码部署 / docker 部署):pypi 安装 / Deployment method (pypi installation / dev deployment / docker deployment): pypi installation
- 使用的模型推理框架(Xinference / Ollama / OpenAI API 等):Xinference / Model serve methodXinference / Ollama / OpenAI API, etc.): Xinference
- 使用的 LLM 模型(GLM-4-9B / Qwen2-7B-Instruct 等):GLM-4-9B / LLM used (GLM-4-9B / Qwen2-7B-Instruct, etc.): GLM-4-9B
- 使用的 Embedding 模型(bge-large-zh-v1.5 / m3e-base 等):bge-large-zh-v1.5 / Embedding model used (bge-large-zh-v1.5 / m3e-base, etc.): bge-large-zh-v1.5
- 使用的向量库类型 (faiss / milvus / pg_vector 等) faiss / Vector library used (faiss, milvus, pg_vector, etc.): faiss
- 操作系统及版本 / Operating system and version: MacOS
- Python 版本 / Python version: 3.8
- 推理使用的硬件(GPU / CPU / MPS / NPU 等) / Inference hardware (GPU / CPU / MPS / NPU, etc.): GPU
- 其他相关环境信息 / Other relevant environment information:
**附加信息 / Additional Information**
添加与问题相关的任何其他信息 / Add any other information related to the issue.
+23
View File
@@ -0,0 +1,23 @@
---
name: 功能请求 / Feature Request
about: 为项目提出新功能或建议 / Propose new features or suggestions for the project
title: "[FEATURE] 简洁阐述功能 / Concise description of the feature"
labels: enhancement
assignees: ''
---
**功能描述 / Feature Description**
用简洁明了的语言描述所需的功能 / Describe the desired feature in a clear and concise manner.
**解决的问题 / Problem Solved**
解释此功能如何解决现有问题或改进项目 / Explain how this feature solves existing problems or improves the project.
**实现建议 / Implementation Suggestions**
如果可能,请提供关于如何实现此功能的建议 / If possible, provide suggestions on how to implement this feature.
**替代方案 / Alternative Solutions**
描述您考虑过的替代方案 / Describe alternative solutions you have considered.
**其他信息 / Additional Information**
添加与功能请求相关的任何其他信息 / Add any other information related to the feature request.
+93
View File
@@ -0,0 +1,93 @@
# An action for setting up poetry install with caching.
# Using a custom action since the default action does not
# take poetry install groups into account.
# Action code from:
# https://github.com/actions/setup-python/issues/505#issuecomment-1273013236
name: poetry-install-with-caching
description: Poetry install with support for caching of dependency groups.
inputs:
python-version:
description: Python version, supporting MAJOR.MINOR only
required: true
poetry-version:
description: Poetry version
required: true
cache-key:
description: Cache key to use for manual handling of caching
required: true
working-directory:
description: Directory whose poetry.lock file should be cached
required: true
runs:
using: composite
steps:
- uses: actions/setup-python@v5
name: Setup python ${{ inputs.python-version }}
id: setup-python
with:
python-version: ${{ inputs.python-version }}
- uses: actions/cache@v4
id: cache-bin-poetry
name: Cache Poetry binary - Python ${{ inputs.python-version }}
env:
SEGMENT_DOWNLOAD_TIMEOUT_MIN: "1"
with:
path: |
/opt/pipx/venvs/poetry
# This step caches the poetry installation, so make sure it's keyed on the poetry version as well.
key: bin-poetry-${{ runner.os }}-${{ runner.arch }}-py-${{ inputs.python-version }}-${{ inputs.poetry-version }}
- name: Refresh shell hashtable and fixup softlinks
if: steps.cache-bin-poetry.outputs.cache-hit == 'true'
shell: bash
env:
POETRY_VERSION: ${{ inputs.poetry-version }}
PYTHON_VERSION: ${{ inputs.python-version }}
run: |
set -eux
# Refresh the shell hashtable, to ensure correct `which` output.
hash -r
# `actions/cache@v3` doesn't always seem able to correctly unpack softlinks.
# Delete and recreate the softlinks pipx expects to have.
rm /opt/pipx/venvs/poetry/bin/python
cd /opt/pipx/venvs/poetry/bin
ln -s "$(which "python$PYTHON_VERSION")" python
chmod +x python
cd /opt/pipx_bin/
ln -s /opt/pipx/venvs/poetry/bin/poetry poetry
chmod +x poetry
# Ensure everything got set up correctly.
/opt/pipx/venvs/poetry/bin/python --version
/opt/pipx_bin/poetry --version
- name: Install poetry
if: steps.cache-bin-poetry.outputs.cache-hit != 'true'
shell: bash
env:
POETRY_VERSION: ${{ inputs.poetry-version }}
PYTHON_VERSION: ${{ inputs.python-version }}
# Install poetry using the python version installed by setup-python step.
run: pipx install "poetry==$POETRY_VERSION" --python '${{ steps.setup-python.outputs.python-path }}' --verbose
- name: Restore pip and poetry cached dependencies
uses: actions/cache@v4
env:
SEGMENT_DOWNLOAD_TIMEOUT_MIN: "4"
WORKDIR: ${{ inputs.working-directory == '' && '.' || inputs.working-directory }}
with:
path: |
~/.cache/pip
~/.cache/pypoetry/virtualenvs
~/.cache/pypoetry/cache
~/.cache/pypoetry/artifacts
${{ env.WORKDIR }}/.venv
key: py-deps-${{ runner.os }}-${{ runner.arch }}-py-${{ inputs.python-version }}-poetry-${{ inputs.poetry-version }}-${{ inputs.cache-key }}-${{ hashFiles(format('{0}/**/poetry.lock', env.WORKDIR)) }}
+91
View File
@@ -0,0 +1,91 @@
name: integration_test
on:
workflow_dispatch:
inputs:
working-directory:
required: true
type: string
default: './libs/chatchat-server'
description: "From which folder this pipeline executes"
env:
POETRY_VERSION: "1.7.1"
jobs:
build:
defaults:
run:
working-directory: ${{ inputs.working-directory }}
if: github.ref == 'refs/heads/master'
environment: Scheduled testing publish
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ["3.8", "3.9", "3.10", "3.11"]
name: "make integration_test #${{ matrix.os }} Python ${{ matrix.python-version }}"
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }} + Poetry ${{ env.POETRY_VERSION }}
uses: "./.github/actions/poetry_setup"
with:
python-version: ${{ matrix.python-version }}
poetry-version: ${{ env.POETRY_VERSION }}
working-directory: ${{ inputs.working-directory }}
cache-key: core
- name: Import test dependencies
run: poetry install --with test
working-directory: ${{ inputs.working-directory }}
- name: Run integration tests
shell: bash
env:
ZHIPUAI_API_KEY: ${{ secrets.ZHIPUAI_API_KEY }}
ZHIPUAI_BASE_URL: ${{ secrets.ZHIPUAI_BASE_URL }}
run: |
make integration_tests
- name: Remove chatchat Test Untracked files (Linux/macOS)
if: runner.os != 'Windows'
working-directory: ${{ inputs.working-directory }}
run: |
if [ -d "tests/unit_tests/config/chatchat/" ]; then
rm -rf tests/unit_tests/config/chatchat/
fi
- name: Remove chatchat Test Untracked files (Windows)
if: runner.os == 'Windows'
working-directory: ${{ inputs.working-directory }}
run: |
if (Test-Path -Path "tests/unit_tests/config/chatchat/") {
Remove-Item -Recurse -Force "tests/unit_tests/config/chatchat/"
}
- name: Ensure the tests did not create any additional files (Linux/macOS)
if: runner.os != 'Windows'
shell: bash
run: |
set -eu
STATUS="$(git status)"
echo "$STATUS"
# grep will exit non-zero if the target message isn't found,
# and `set -e` above will cause the step to fail.
echo "$STATUS" | grep 'nothing to commit, working tree clean'
- name: Ensure the tests did not create any additional files (Windows)
if: runner.os == 'Windows'
shell: powershell
run: |
$STATUS = git status
Write-Host $STATUS
# Select-String will exit non-zero if the target message isn't found.
$STATUS | Select-String 'nothing to commit, working tree clean'
+257
View File
@@ -0,0 +1,257 @@
name: release
run-name: Release ${{ inputs.working-directory }} by @${{ github.actor }}
on:
workflow_call:
inputs:
working-directory:
required: true
type: string
description: "From which folder this pipeline executes"
workflow_dispatch:
inputs:
working-directory:
required: true
type: string
default: './libs/chatchat-server'
description: "From which folder this pipeline executes"
env:
PYTHON_VERSION: "3.8"
POETRY_VERSION: "1.7.1"
jobs:
build:
if: github.ref == 'refs/heads/master'
environment: Scheduled testing
runs-on: ubuntu-latest
outputs:
pkg-name: ${{ steps.check-version.outputs.pkg-name }}
version: ${{ steps.check-version.outputs.version }}
steps:
- uses: actions/checkout@v4
- name: Set up Python + Poetry ${{ env.POETRY_VERSION }}
uses: "./.github/actions/poetry_setup"
with:
python-version: ${{ env.PYTHON_VERSION }}
poetry-version: ${{ env.POETRY_VERSION }}
working-directory: ${{ inputs.working-directory }}
cache-key: release
# We want to keep this build stage *separate* from the release stage,
# so that there's no sharing of permissions between them.
# The release stage has trusted publishing and GitHub repo contents write access,
# and we want to keep the scope of that access limited just to the release job.
# Otherwise, a malicious `build` step (e.g. via a compromised dependency)
# could get access to our GitHub or PyPI credentials.
#
# Per the trusted publishing GitHub Action:
# > It is strongly advised to separate jobs for building [...]
# > from the publish job.
# https://github.com/pypa/gh-action-pypi-publish#non-goals
- name: Build project for distribution
run: poetry build
working-directory: ${{ inputs.working-directory }}
- name: Upload build
uses: actions/upload-artifact@v4
with:
name: dist
path: ${{ inputs.working-directory }}/dist/
- name: Check Version
id: check-version
shell: bash
working-directory: ${{ inputs.working-directory }}
run: |
echo pkg-name="$(poetry version | cut -d ' ' -f 1)" >> $GITHUB_OUTPUT
echo version="$(poetry version --short)" >> $GITHUB_OUTPUT
test-pypi-publish:
needs:
- build
uses:
./.github/workflows/_test_release.yml
with:
working-directory: ${{ inputs.working-directory }}
secrets: inherit
pre-release-checks:
needs:
- build
- test-pypi-publish
environment: Scheduled testing
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# We explicitly *don't* set up caching here. This ensures our tests are
# maximally sensitive to catching breakage.
#
# For example, here's a way that caching can cause a falsely-passing test:
# - Make the chatchat package manifest no longer list a dependency package
# as a requirement. This means it won't be installed by `pip install`,
# and attempting to use it would cause a crash.
# - That dependency used to be required, so it may have been cached.
# When restoring the venv packages from cache, that dependency gets included.
# - Tests pass, because the dependency is present even though it wasn't specified.
# - The package is published, and it breaks on the missing dependency when
# used in the real world.
- name: Set up Python + Poetry ${{ env.POETRY_VERSION }}
uses: "./.github/actions/poetry_setup"
with:
python-version: ${{ env.PYTHON_VERSION }}
poetry-version: ${{ env.POETRY_VERSION }}
working-directory: ${{ inputs.working-directory }}
- name: Import published package
shell: bash
working-directory: ${{ inputs.working-directory }}
env:
PKG_NAME: ${{ needs.build.outputs.pkg-name }}
VERSION: ${{ needs.build.outputs.version }}
# Here we use:
# - The default regular PyPI index as the *primary* index, meaning
# that it takes priority (https://pypi.org/simple)
# - The test PyPI index as an extra index, so that any dependencies that
# are not found on test PyPI can be resolved and installed anyway.
# (https://test.pypi.org/simple). This will include the PKG_NAME==VERSION
# package because VERSION will not have been uploaded to regular PyPI yet.
# - attempt install again after 5 seconds if it fails because there is
# sometimes a delay in availability on test pypi
run: |
poetry run pip install \
--extra-index-url https://test.pypi.org/simple/ \
"$PKG_NAME==$VERSION" || \
( \
sleep 5 && \
poetry run pip install \
--extra-index-url https://test.pypi.org/simple/ \
"$PKG_NAME==$VERSION" \
)
# Replace all dashes in the package name with underscores,
# since that's how Python imports packages with dashes in the name.
IMPORT_NAME="$(echo "$PKG_NAME" | sed s/-/_/g)"
poetry run python -c "import $IMPORT_NAME; print(dir($IMPORT_NAME))"
- name: Import test dependencies
run: poetry install --with test
working-directory: ${{ inputs.working-directory }}
# Overwrite the local version of the package with the test PyPI version.
- name: Import published package (again)
working-directory: ${{ inputs.working-directory }}
shell: bash
env:
PKG_NAME: ${{ needs.build.outputs.pkg-name }}
VERSION: ${{ needs.build.outputs.version }}
run: |
poetry run pip install \
--extra-index-url https://test.pypi.org/simple/ \
"$PKG_NAME==$VERSION"
- name: Run unit tests
run: make tests
env:
ZHIPUAI_API_KEY: ${{ secrets.ZHIPUAI_API_KEY }}
ZHIPUAI_BASE_URL: ${{ secrets.ZHIPUAI_BASE_URL }}
working-directory: ${{ inputs.working-directory }}
# - name: Run integration tests
# env:
# ZHIPUAI_API_KEY: ${{ secrets.ZHIPUAI_API_KEY }}
# ZHIPUAI_BASE_URL: ${{ secrets.ZHIPUAI_BASE_URL }}
# run: make integration_tests
# working-directory: ${{ inputs.working-directory }}
publish:
needs:
- build
- test-pypi-publish
- pre-release-checks
environment: Scheduled testing
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ inputs.working-directory }}
steps:
- uses: actions/checkout@v4
- name: Set up Python + Poetry ${{ env.POETRY_VERSION }}
uses: "./.github/actions/poetry_setup"
with:
python-version: ${{ env.PYTHON_VERSION }}
poetry-version: ${{ env.POETRY_VERSION }}
working-directory: ${{ inputs.working-directory }}
cache-key: release
- uses: actions/download-artifact@v4
with:
name: dist
path: ${{ inputs.working-directory }}/dist/
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: ${{ inputs.working-directory }}/dist/
verbose: true
print-hash: true
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
# We overwrite any existing distributions with the same name and version.
# This is *only for CI use* and is *extremely dangerous* otherwise!
# https://github.com/pypa/gh-action-pypi-publish#tolerating-release-package-file-duplicates
# skip-existing: true
# mark-release:
# needs:
# - build
# - test-pypi-publish
# - pre-release-checks
# - publish
# environment: Scheduled testing
# runs-on: ubuntu-latest
# permissions:
# # This permission is needed by `ncipollo/release-action` to
# # create the GitHub release.
# contents: write
# id-token: none
# defaults:
# run:
# working-directory: ${{ inputs.working-directory }}
# steps:
# - uses: actions/checkout@v4
# - name: Set up Python + Poetry ${{ env.POETRY_VERSION }}
# uses: "./.github/actions/poetry_setup"
# with:
# python-version: ${{ env.PYTHON_VERSION }}
# poetry-version: ${{ env.POETRY_VERSION }}
# working-directory: ${{ inputs.working-directory }}
# cache-key: release
# - uses: actions/download-artifact@v4
# with:
# name: dist
# path: ${{ inputs.working-directory }}/dist/
# - name: Create Release
# uses: ncipollo/release-action@v1
# if: ${{ inputs.working-directory == './chatchat-server' }}
# with:
# artifacts: "dist/*"
# token: ${{ secrets.GITHUB_TOKEN }}
# draft: false
# generateReleaseNotes: true
# tag: v${{ needs.build.outputs.version }}
# commit: main
+85
View File
@@ -0,0 +1,85 @@
name: test
on:
workflow_dispatch:
inputs:
working-directory:
required: true
type: string
default: './libs/chatchat-server'
description: "From which folder this pipeline executes"
env:
POETRY_VERSION: "1.7.1"
jobs:
build:
defaults:
run:
working-directory: ${{ inputs.working-directory }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ["3.8", "3.9", "3.10", "3.11"]
name: "make test #${{ matrix.os }} Python ${{ matrix.python-version }}"
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }} + Poetry ${{ env.POETRY_VERSION }}
uses: "./.github/actions/poetry_setup"
with:
python-version: ${{ matrix.python-version }}
poetry-version: ${{ env.POETRY_VERSION }}
working-directory: ${{ inputs.working-directory }}
cache-key: core
- name: Install chatchat editable
working-directory: ${{ inputs.working-directory }}
shell: bash
run: poetry install --with test
- name: Run core tests
shell: bash
run: |
make test
- name: Remove chatchat Test Untracked files (Linux/macOS)
if: runner.os != 'Windows'
working-directory: ${{ inputs.working-directory }}
run: |
if [ -d "tests/unit_tests/config/chatchat/" ]; then
rm -rf tests/unit_tests/config/chatchat/
fi
- name: Remove chatchat Test Untracked files (Windows)
if: runner.os == 'Windows'
working-directory: ${{ inputs.working-directory }}
run: |
if (Test-Path -Path "tests/unit_tests/config/chatchat/") {
Remove-Item -Recurse -Force "tests/unit_tests/config/chatchat/"
}
- name: Ensure the tests did not create any additional files (Linux/macOS)
if: runner.os != 'Windows'
shell: bash
run: |
set -eu
STATUS="$(git status)"
echo "$STATUS"
# grep will exit non-zero if the target message isn't found,
# and `set -e` above will cause the step to fail.
echo "$STATUS" | grep 'nothing to commit, working tree clean'
- name: Ensure the tests did not create any additional files (Windows)
if: runner.os == 'Windows'
shell: powershell
run: |
$STATUS = git status
Write-Host $STATUS
# Select-String will exit non-zero if the target message isn't found.
$STATUS | Select-String 'nothing to commit, working tree clean'
+90
View File
@@ -0,0 +1,90 @@
name: test-release
on:
workflow_call:
inputs:
working-directory:
required: true
type: string
description: "From which folder this pipeline executes"
env:
POETRY_VERSION: "1.7.1"
PYTHON_VERSION: "3.8"
jobs:
build:
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
outputs:
pkg-name: ${{ steps.check-version.outputs.pkg-name }}
version: ${{ steps.check-version.outputs.version }}
steps:
- uses: actions/checkout@v4
- name: Set up Python + Poetry ${{ env.POETRY_VERSION }}
uses: "./.github/actions/poetry_setup"
with:
python-version: ${{ env.PYTHON_VERSION }}
poetry-version: ${{ env.POETRY_VERSION }}
working-directory: ${{ inputs.working-directory }}
cache-key: release
# We want to keep this build stage *separate* from the release stage,
# so that there's no sharing of permissions between them.
# The release stage has trusted publishing and GitHub repo contents write access,
# and we want to keep the scope of that access limited just to the release job.
# Otherwise, a malicious `build` step (e.g. via a compromised dependency)
# could get access to our GitHub or PyPI credentials.
#
# Per the trusted publishing GitHub Action:
# > It is strongly advised to separate jobs for building [...]
# > from the publish job.
# https://github.com/pypa/gh-action-pypi-publish#non-goals
- name: Build project for distribution
run: poetry build
working-directory: ${{ inputs.working-directory }}
- name: Upload build
uses: actions/upload-artifact@v4
with:
name: test-dist
path: ${{ inputs.working-directory }}/dist/
- name: Check Version
id: check-version
shell: bash
working-directory: ${{ inputs.working-directory }}
run: |
echo pkg-name="$(poetry version | cut -d ' ' -f 1)" >> $GITHUB_OUTPUT
echo version="$(poetry version --short)" >> $GITHUB_OUTPUT
publish:
needs:
- build
runs-on: ubuntu-latest
environment: Scheduled test pypi publish
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: test-dist
path: ${{ inputs.working-directory }}/dist/
- name: Publish to test PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
packages-dir: ${{ inputs.working-directory }}/dist/
verbose: true
print-hash: true
repository-url: https://test.pypi.org/legacy/
# We overwrite any existing distributions with the same name and version.
# This is *only for CI use* and is *extremely dangerous* otherwise!
# https://github.com/pypa/gh-action-pypi-publish#tolerating-release-package-file-duplicates
# skip-existing: true
+22
View File
@@ -0,0 +1,22 @@
name: Close inactive issues
on:
schedule:
- cron: "30 21 * * *"
jobs:
close-issues:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- uses: actions/stale@v5
with:
days-before-issue-stale: 30
days-before-issue-close: 14
stale-issue-label: "stale"
stale-issue-message: "这个问题已经被标记为 `stale` ,因为它已经超过 30 天没有任何活动。"
close-issue-message: "这个问题已经被自动关闭,因为它被标为 `stale` 后超过 14 天没有任何活动。"
days-before-pr-stale: -1
days-before-pr-close: -1
repo-token: ${{ secrets.GITHUB_TOKEN }}
+32
View File
@@ -0,0 +1,32 @@
name: label_ad_issue
on:
issues:
types:
- opened
jobs:
label_ad_issue:
runs-on: ubuntu-latest
environment: Scheduled GITHUB_OWNER publish
steps:
- env:
GH_TOKEN: ${{ secrets.GITHUB_OWNER_TOKEN }}
ISSUE_URL: ${{ github.event.issue.html_url }}
ISSUE_TITLE: ${{ github.event.issue.title }}
run: |
stat=no
AD_KEYWORDS=(download crack "serial key" "license key" "product key" "free download" "full version" "full crack" "full keygen" "full license" "full activation" "full serial")
ISSUE_TITLE_LOWER=$(echo $ISSUE_TITLE | tr '[:upper:]' '[:lower:]')
for KEYWORD in ${AD_KEYWORDS[@]}; do
if [[ $ISSUE_TITLE_LOWER == *$KEYWORD* ]] && [[ $ISSUE_TITLE_LOWER != *input* ]]; then
stat=yes
break
fi
done
if [[ $stat == yes ]]; then
echo "Issue title contains advertisement keywords."
gh issue delete $ISSUE_URL --yes
fi
+183
View File
@@ -0,0 +1,183 @@
*.yaml
*.json
*.log
*.log.*
*.bak
/libs/chatchat-server/chatchat/data/*
!/libs/chatchat-server/chatchat/data/knowledge_base/samples
/libs/chatchat-server/chatchat/data/knowledge_base/samples/vector_store
!/libs/chatchat-server/chatchat/data/nltk_data
config/
.vscode/
# below are standard python ignore files
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
.python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
Pipfile.lock
# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
poetry.lock
# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/
.pytest_cache
.DS_Store
# Test File
test.py
/knowledge_base/samples/content/202311-D平台项目工作大纲参数,人员中间库表结构说明V1.1(1).docx
/knowledge_base/samples/content/imi_temeplate.txt
chatchat/data
+3
View File
@@ -0,0 +1,3 @@
[submodule "knowledge_base/samples/content/wiki"]
path = chatchat/chatchat/data/knowledge_base/samples/content/wiki
url = https://github.com/chatchat-space/Langchain-Chatchat.wiki.git
+201
View File
@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2024 LangChain-Chatchat Team
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
+372
View File
@@ -0,0 +1,372 @@
![](docs/img/logo-long-chatchat-trans-v2.png)
<a href="https://trendshift.io/repositories/329" target="_blank"><img src="https://trendshift.io/api/badge/repositories/329" alt="chatchat-space%2FLangchain-Chatchat | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>
[![pypi badge](https://img.shields.io/pypi/v/langchain-chatchat.svg)](https://shields.io/)
[![Generic badge](https://img.shields.io/badge/python-3.8%7C3.9%7C3.10%7C3.11-blue.svg)](https://pypi.org/project/pypiserver/)
[![zread](https://img.shields.io/badge/Ask_Zread-_.svg?style=flat&color=00b0aa&labelColor=000000&logo=data%3Aimage%2Fsvg%2Bxml%3Bbase64%2CPHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxNiAxNiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTQuOTYxNTYgMS42MDAxSDIuMjQxNTZDMS44ODgxIDEuNjAwMSAxLjYwMTU2IDEuODg2NjQgMS42MDE1NiAyLjI0MDFWNC45NjAxQzEuNjAxNTYgNS4zMTM1NiAxLjg4ODEgNS42MDAxIDIuMjQxNTYgNS42MDAxSDQuOTYxNTZDNS4zMTUwMiA1LjYwMDEgNS42MDE1NiA1LjMxMzU2IDUuNjAxNTYgNC45NjAxVjIuMjQwMUM1LjYwMTU2IDEuODg2NjQgNS4zMTUwMiAxLjYwMDEgNC45NjE1NiAxLjYwMDFaIiBmaWxsPSIjZmZmIi8%2BCjxwYXRoIGQ9Ik00Ljk2MTU2IDEwLjM5OTlIMi4yNDE1NkMxLjg4ODEgMTAuMzk5OSAxLjYwMTU2IDEwLjY4NjQgMS42MDE1NiAxMS4wMzk5VjEzLjc1OTlDMS42MDE1NiAxNC4xMTM0IDEuODg4MSAxNC4zOTk5IDIuMjQxNTYgMTQuMzk5OUg0Ljk2MTU2QzUuMzE1MDIgMTQuMzk5OSA1LjYwMTU2IDE0LjExMzQgNS42MDE1NiAxMy43NTk5VjExLjAzOTlDNS42MDE1NiAxMC42ODY0IDUuMzE1MDIgMTAuMzk5OSA0Ljk2MTU2IDEwLjM5OTlaIiBmaWxsPSIjZmZmIi8%2BCjxwYXRoIGQ9Ik0xMy43NTg0IDEuNjAwMUgxMS4wMzg0QzEwLjY4NSAxLjYwMDEgMTAuMzk4NCAxLjg4NjY0IDEwLjM5ODQgMi4yNDAxVjQuOTYwMUMxMC4zOTg0IDUuMzEzNTYgMTAuNjg1IDUuNjAwMSAxMS4wMzg0IDUuNjAwMUgxMy43NTg0QzE0LjExMTkgNS42MDAxIDE0LjM5ODQgNS4zMTM1NiAxNC4zOTg0IDQuOTYwMVYyLjI0MDFDMTQuMzk4NCAxLjg4NjY0IDE0LjExMTkgMS42MDAxIDEzLjc1ODQgMS42MDAxWiIgZmlsbD0iI2ZmZiIvPgo8cGF0aCBkPSJNNCAxMkwxMiA0TDQgMTJaIiBmaWxsPSIjZmZmIi8%2BCjxwYXRoIGQ9Ik00IDEyTDEyIDQiIHN0cm9rZT0iI2ZmZiIgc3Ryb2tlLXdpZHRoPSIxLjUiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIvPgo8L3N2Zz4K&logoColor=ffffff)](https://zread.ai/chatchat-space/Langchain-Chatchat)
🌍 [READ THIS IN ENGLISH](README_en.md)
📃 **LangChain-Chatchat** (原 Langchain-ChatGLM)
基于 ChatGLM 等大语言模型与 Langchain 等应用框架实现,开源、可离线部署的 RAG 与 Agent 应用项目。
---
## 目录
* [概述](README.md#概述)
* [功能介绍](README.md#功能介绍)
* [0.3.x 功能一览](README.md#03x-版本功能一览)
* [已支持的模型推理框架与模型](README.md#已支持的模型部署框架与模型)
* [快速上手](README.md#快速上手)
* [pip 安装部署](README.md#pip-安装部署)
* [源码安装部署/开发部署](README.md#源码安装部署开发部署)
* [Docker 部署](README.md#docker-部署)
* [项目里程碑](README.md#项目里程碑)
* [联系我们](README.md#联系我们)
## 概述
🤖️ 一种利用 [langchain](https://github.com/langchain-ai/langchain)
思想实现的基于本地知识库的问答应用,目标期望建立一套对中文场景与开源模型支持友好、可离线运行的知识库问答解决方案。
💡 受 [GanymedeNil](https://github.com/GanymedeNil) 的项目 [document.ai](https://github.com/GanymedeNil/document.ai)
和 [AlexZhangji](https://github.com/AlexZhangji)
创建的 [ChatGLM-6B Pull Request](https://github.com/THUDM/ChatGLM-6B/pull/216)
启发,建立了全流程可使用开源模型实现的本地知识库问答应用。本项目的最新版本中可使用 [Xinference](https://github.com/xorbitsai/inference)、[Ollama](https://github.com/ollama/ollama)
等框架接入 [GLM-4-Chat](https://github.com/THUDM/GLM-4)、 [Qwen2-Instruct](https://github.com/QwenLM/Qwen2)、 [Llama3](https://github.com/meta-llama/llama3)
等模型,依托于 [langchain](https://github.com/langchain-ai/langchain)
框架支持通过基于 [FastAPI](https://github.com/tiangolo/fastapi) 提供的 API
调用服务,或使用基于 [Streamlit](https://github.com/streamlit/streamlit) 的 WebUI 进行操作。
![](docs/img/langchain_chatchat_0.3.0.png)
✅ 本项目支持市面上主流的开源 LLM、 Embedding 模型与向量数据库,可实现全部使用**开源**模型**离线私有部署**。与此同时,本项目也支持
OpenAI GPT API 的调用,并将在后续持续扩充对各类模型及模型 API 的接入。
⛓️ 本项目实现原理如下图所示,过程包括加载文件 -> 读取文本 -> 文本分割 -> 文本向量化 -> 问句向量化 ->
在文本向量中匹配出与问句向量最相似的 `top k`个 -> 匹配出的文本作为上下文和问题一起添加到 `prompt`中 -> 提交给 `LLM`生成回答。
📺 [原理介绍视频](https://www.bilibili.com/video/BV13M4y1e7cN/?share_source=copy_web&vd_source=e6c5aafe684f30fbe41925d61ca6d514)
![实现原理图](docs/img/langchain+chatglm.png)
从文档处理角度来看,实现流程如下:
![实现原理图2](docs/img/langchain+chatglm2.png)
🚩 本项目未涉及微调、训练过程,但可利用微调或训练对本项目效果进行优化。
🌐 [AutoDL 镜像](https://www.codewithgpu.com/i/chatchat-space/Langchain-Chatchat/Langchain-Chatchat) 中 `0.3.0`
版本所使用代码已更新至本项目 `v0.3.0` 版本。
🐳 Docker 镜像将会在近期更新。
🧑‍💻 如果你想对本项目做出贡献,欢迎移步[开发指南](docs/contributing/README_dev.md) 获取更多开发部署相关信息。
## 功能介绍
### 0.3.x 版本功能一览
| 功能 | 0.2.x | 0.3.x |
|-----------|----------------------------------|---------------------------------------------------------------------|
| 模型接入 | 本地:fastchat<br>在线:XXXModelWorker | 本地:model_provider,支持大部分主流模型加载框架<br>在线:oneapi<br>所有模型接入均兼容openai sdk |
| Agent | ❌不稳定 | ✅针对ChatGLM3和Qwen进行优化,Agent能力显著提升 ||
| LLM对话 | ✅ | ✅ ||
| 知识库对话 | ✅ | ✅ ||
| 搜索引擎对话 | ✅ | ✅ ||
| 文件对话 | ✅仅向量检索 | ✅统一为File RAG功能,支持BM25+KNN等多种检索方式 ||
| 数据库对话 | ❌ | ✅ ||
| 多模态图片对话 | ❌ | ✅ 推荐使用 qwen-vl-chat ||
| ARXIV文献对话 | ❌ | ✅ ||
| Wolfram对话 | ❌ | ✅ ||
| 文生图 | ❌ | ✅ ||
| 本地知识库管理 | ✅ | ✅ ||
| WEBUI | ✅ | ✅更好的多会话支持,自定义系统提示词... |
0.3.x 版本的核心功能由 Agent 实现,但用户也可以手动实现工具调用:
|操作方式|实现的功能|适用场景|
|-------|---------|-------|
|选中"启用Agent",选择多个工具|由LLM自动进行工具调用|使用ChatGLM3/Qwen或在线API等具备Agent能力的模型|
|选中"启用Agent",选择单个工具|LLM仅解析工具参数|使用的模型Agent能力一般,不能很好的选择工具<br>想手动选择功能|
|不选中"启用Agent",选择单个工具|不使用Agent功能的情况下,手动填入参数进行工具调用|使用的模型不具备Agent能力|
|不选中任何工具,上传一个图片|图片对话|使用 qwen-vl-chat 等多模态模型|
更多功能和更新请实际部署体验.
### 已支持的模型部署框架与模型
本项目中已经支持市面上主流的如 [GLM-4-Chat](https://github.com/THUDM/GLM-4)
与 [Qwen2-Instruct](https://github.com/QwenLM/Qwen2) 等新近开源大语言模型和 Embedding
模型,这些模型需要用户自行启动模型部署框架后,通过修改配置信息接入项目,本项目已支持的本地模型部署框架如下:
| 模型部署框架 | Xinference | LocalAI | Ollama | FastChat |
|--------------------|------------------------------------------------------------------------------------------|------------------------------------------------------------|--------------------------------------------------------------------------------|--------------------------------------------------------------------------------------|
| OpenAI API 接口对齐 | ✅ | ✅ | ✅ | ✅ |
| 加速推理引擎 | GPTQ, GGML, vLLM, TensorRT, mlx | GPTQ, GGML, vLLM, TensorRT | GGUF, GGML | vLLM |
| 接入模型类型 | LLM, Embedding, Rerank, Text-to-Image, Vision, Audio | LLM, Embedding, Rerank, Text-to-Image, Vision, Audio | LLM, Text-to-Image, Vision | LLM, Vision |
| Function Call | ✅ | ✅ | ✅ | / |
| 更多平台支持(CPU, Metal) | ✅ | ✅ | ✅ | ✅ |
| 异构 | ✅ | ✅ | / | / |
| 集群 | ✅ | ✅ | / | / |
| 操作文档链接 | [Xinference 文档](https://inference.readthedocs.io/zh-cn/latest/models/builtin/index.html) | [LocalAI 文档](https://localai.io/model-compatibility/) | [Ollama 文档](https://github.com/ollama/ollama?tab=readme-ov-file#model-library) | [FastChat 文档](https://github.com/lm-sys/FastChat#install) |
| 可用模型 | [Xinference 已支持模型](https://inference.readthedocs.io/en/latest/models/builtin/index.html) | [LocalAI 已支持模型](https://localai.io/model-compatibility/#/) | [Ollama 已支持模型](https://ollama.com/library#/) | [FastChat 已支持模型](https://github.com/lm-sys/FastChat/blob/main/docs/model_support.md) |
除上述本地模型加载框架外,项目中也为可接入在线 API 的 [One API](https://github.com/songquanpeng/one-api)
框架接入提供了支持,支持包括 [OpenAI ChatGPT](https://platform.openai.com/docs/guides/gpt/chat-completions-api)、[Azure OpenAI API](https://learn.microsoft.com/en-us/azure/ai-services/openai/reference)、[Anthropic Claude](https://anthropic.com/)、[智谱清言](https://bigmodel.cn/)、[百川](https://platform.baichuan-ai.com/)
等常用在线 API 的接入使用。
> [!Note]
> 关于 Xinference 加载本地模型:
> Xinference 内置模型会自动下载,如果想让它加载本机下载好的模型,可以在启动 Xinference 服务后,到项目 tools/model_loaders
> 目录下执行 `streamlit run xinference_manager.py`,按照页面提示为指定模型设置本地路径即可.
## 快速上手
### pip 安装部署
#### 0. 软硬件要求
💡 软件方面,本项目已支持在 Python 3.8-3.11 环境中进行使用,并已在 Windows、macOS、Linux 操作系统中进行测试。
💻 硬件方面,因 0.3.0 版本已修改为支持不同模型部署框架接入,因此可在 CPU、GPU、NPU、MPS 等不同硬件条件下使用。
#### 1. 安装 Langchain-Chatchat
从 0.3.0 版本起,Langchain-Chatchat 提供以 Python 库形式的安装方式,具体安装请执行:
```shell
pip install langchain-chatchat -U
```
> [!important]
> 为确保所使用的 Python 库为最新版,建议使用官方 Pypi 源或清华源。
> [!Note]
> 因模型部署框架 Xinference 接入 Langchain-Chatchat 时需要额外安装对应的 Python 依赖库,因此如需搭配 Xinference
> 框架使用时,建议使用如下安装方式:
> ```shell
> pip install "langchain-chatchat[xinference]" -U
> ```
#### 2. 模型推理框架并加载模型
从 0.3.0 版本起,Langchain-Chatchat 不再根据用户输入的本地模型路径直接进行模型加载,涉及到的模型种类包括
LLM、Embedding、Reranker
及后续会提供支持的多模态模型等,均改为支持市面常见的各大模型推理框架接入,如 [Xinference](https://github.com/xorbitsai/inference)、[Ollama](https://github.com/ollama/ollama)、[LocalAI](https://github.com/mudler/LocalAI)、[FastChat](https://github.com/lm-sys/FastChat)、[One API](https://github.com/songquanpeng/one-api)
等。
因此,请确认在启动 Langchain-Chatchat 项目前,首先进行模型推理框架的运行,并加载所需使用的模型。
这里以 Xinference 举例,
请参考 [Xinference文档](https://inference.readthedocs.io/zh-cn/latest/getting_started/installation.html) 进行框架部署与模型加载。
> [!WARNING]
> 为避免依赖冲突,请将 Langchain-Chatchat 和模型部署框架如 Xinference 等放在不同的 Python 虚拟环境中, 比如 conda, venv,
> virtualenv 等。
#### 3. 初始化项目配置与数据目录
从 0.3.1 版本起,Langchain-Chatchat 使用本地 `yaml` 文件的方式进行配置,用户可以直接查看并修改其中的内容,服务器会自动更新无需重启。
1. 设置 Chatchat 存储配置文件和数据文件的根目录(可选)
```shell
# on linux or macos
export CHATCHAT_ROOT=/path/to/chatchat_data
# on windows
set CHATCHAT_ROOT=/path/to/chatchat_data
```
若不设置该环境变量,则自动使用当前目录。
2. 执行初始化
```shell
chatchat init
```
该命令会执行以下操作:
- 创建所有需要的数据目录
- 复制 samples 知识库内容
- 生成默认 `yaml` 配置文件
3. 修改配置文件
- 配置模型(model_settings.yaml
需要根据步骤 **2. 模型推理框架并加载模型**
中选用的模型推理框架与加载的模型进行模型接入配置,具体参考 `model_settings.yaml` 中的注释。主要修改以下内容:
```yaml
# 默认选用的 LLM 名称
DEFAULT_LLM_MODEL: qwen1.5-chat
# 默认选用的 Embedding 名称
DEFAULT_EMBEDDING_MODEL: bge-large-zh-v1.5
# 将 `LLM_MODEL_CONFIG` 中 `llm_model, action_model` 的键改成对应的 LLM 模型
# 在 `MODEL_PLATFORMS` 中修改对应模型平台信息
```
- 配置知识库路径(basic_settings.yaml)(可选)
默认知识库位于 `CHATCHAT_ROOT/data/knowledge_base`,如果你想把知识库放在不同的位置,或者想连接现有的知识库,可以在这里修改对应目录即可。
```yaml
# 知识库默认存储路径
KB_ROOT_PATH: D:\chatchat-test\data\knowledge_base
# 数据库默认存储路径。如果使用sqlite,可以直接修改DB_ROOT_PATH;如果使用其它数据库,请直接修改SQLALCHEMY_DATABASE_URI。
DB_ROOT_PATH: D:\chatchat-test\data\knowledge_base\info.db
# 知识库信息数据库连接URI
SQLALCHEMY_DATABASE_URI: sqlite:///D:\chatchat-test\data\knowledge_base\info.db
```
- 配置知识库(kb_settings.yaml)(可选)
默认使用 `FAISS` 知识库,如果想连接其它类型的知识库,可以修改 `DEFAULT_VS_TYPE` 和 `kbs_config`。
#### 4. 初始化知识库
> [!WARNING]
> 进行知识库初始化前,请确保已经启动模型推理框架及对应 `embedding` 模型,且已按照上述**步骤3**完成模型接入配置。
```shell
chatchat kb -r
```
更多功能可以查看 `chatchat kb --help`
出现以下日志即为成功:
```text
----------------------------------------------------------------------------------------------------
知识库名称 samples
知识库类型 faiss
向量模型: bge-large-zh-v1.5
知识库路径 /root/anaconda3/envs/chatchat/lib/python3.11/site-packages/chatchat/data/knowledge_base/samples
文件总数量 47
入库文件数 42
知识条目数 740
用时 0:02:29.701002
----------------------------------------------------------------------------------------------------
总计用时 0:02:33.414425
```
> [!Note]
> 知识库初始化的常见问题
>
> <details>
>
> ##### 1. Windows 下重建知识库或添加知识文件时卡住不动
> 此问题常出现于新建虚拟环境中,可以通过以下方式确认:
>
> `from unstructured.partition.auto import partition`
>
> 如果该语句卡住无法执行,可以执行以下命令:
> ```shell
> pip uninstall python-magic-bin
> # check the version of the uninstalled package
> pip install 'python-magic-bin=={version}'
> ```
> 然后按照本节指引重新创建知识库即可。
>
> </details>
#### 5. 启动项目
```shell
chatchat start -a
```
出现以下界面即为启动成功:
![WebUI界面](docs/img/langchain_chatchat_webui.png)
> [!WARNING]
> 由于 chatchat 配置默认监听地址 `DEFAULT_BIND_HOST` 为 127.0.0.1, 所以无法通过其他 ip 进行访问。
>
> 如需通过机器ip 进行访问(如 Linux 系统), 需要到 `basic_settings.yaml` 中将监听地址修改为 0.0.0.0。
> </details>
### 其它配置
1. 数据库对话配置请移步这里 [数据库对话配置说明](docs/install/README_text2sql.md)
### 源码安装部署/开发部署
源码安装部署请参考 [开发指南](docs/contributing/README_dev.md)
### Docker 部署
```shell
docker pull chatimage/chatchat:0.3.1.3-93e2c87-20240829
docker pull ccr.ccs.tencentyun.com/langchain-chatchat/chatchat:0.3.1.3-93e2c87-20240829 # 国内镜像
```
> [!important]
> 强烈建议: 使用 docker-compose 部署, 具体参考 [README_docker](docs/install/README_docker.md)
### 旧版本迁移
* 0.3.x 结构改变很大,强烈建议您按照文档重新部署. 以下指南不保证100%兼容和成功. 记得提前备份重要数据!
- 首先按照 `安装部署` 中的步骤配置运行环境,修改配置文件
- 将 0.2.x 项目的 knowledge_base 目录拷贝到配置的 `DATA` 目录下
---
## 项目里程碑
+ `2023年4月`: `Langchain-ChatGLM 0.1.0` 发布,支持基于 ChatGLM-6B 模型的本地知识库问答。
+ `2023年8月`: `Langchain-ChatGLM` 改名为 `Langchain-Chatchat`,发布 `0.2.0` 版本,使用 `fastchat` 作为模型加载方案,支持更多的模型和数据库。
+ `2023年10月`: `Langchain-Chatchat 0.2.5` 发布,推出 Agent 内容,开源项目在`Founder Park & Zhipu AI & Zilliz`
举办的黑客马拉松获得三等奖。
+ `2023年12月`: `Langchain-Chatchat` 开源项目获得超过 **20K** stars.
+ `2024年6月`: `Langchain-Chatchat 0.3.0` 发布,带来全新项目架构。
+ 🔥 让我们一起期待未来 Chatchat 的故事 ···
---
## 协议
本项目代码遵循 [Apache-2.0](LICENSE) 协议。
## 联系我们
### Telegram
[![Telegram](https://img.shields.io/badge/Telegram-2CA5E0?style=for-the-badge&logo=telegram&logoColor=white "langchain-chatchat")](https://t.me/+RjliQ3jnJ1YyN2E9)
### 项目交流群
<img src="docs/img/qr_code_117_2.jpg" alt="二维码" width="300" />
🎉 Langchain-Chatchat 项目微信交流群,如果你也对本项目感兴趣,欢迎加入群聊参与讨论交流。
### 公众号
<img src="docs/img/official_wechat_mp_account.png" alt="二维码" width="300" />
🎉 Langchain-Chatchat 项目官方公众号,欢迎扫码关注。
## 引用
如果本项目有帮助到您的研究,请引用我们:
```
@software{langchain_chatchat,
title = {{langchain-chatchat}},
author = {Liu, Qian and Song, Jinke, and Huang, Zhiguo, and Zhang, Yuxuan, and glide-the, and liunux4odoo},
year = 2024,
journal = {GitHub repository},
publisher = {GitHub},
howpublished = {\url{https://github.com/chatchat-space/Langchain-Chatchat}}
}
```
+7
View File
@@ -0,0 +1,7 @@
# WeHub 来源说明
- 原始项目:`chatchat-space/Langchain-Chatchat`
- 原始仓库:https://github.com/chatchat-space/Langchain-Chatchat
- 导入方式:上游默认分支的最新快照
- 原作者、版权和许可证信息以原始仓库及本仓库 LICENSE 为准
- 本文件仅用于记录来源,不代表 WeHub 是原项目作者
+540
View File
@@ -0,0 +1,540 @@
![](docs/img/logo-long-chatchat-trans-v2.png)
[![pypi badge](https://img.shields.io/pypi/v/langchain-chatchat.svg)](https://shields.io/)
[![Generic badge](https://img.shields.io/badge/python-3.8%7C3.9%7C3.10%7C3.11-blue.svg)](https://pypi.org/project/pypiserver/)
🌍 [READ THIS IN CHINESE](README.md)
📃 **LangChain-Chatchat** (formerly Langchain-ChatGLM)
An open-source, offline-deployable RAG and Agent application project based on large language models like ChatGLM and
application frameworks like Langchain.
---
## Contents
* [Overview](README_en.md#Overview)
* [Features](README_en.md#What-Does-Langchain-Chatchat-Offer)
* [Quick Start](README_en.md#Quick-Start)
* [Installation](README_en.md#Installation)
* [Contact Us](README_en.md#Contact-Us)
## Overview
🤖️ A question-answering application based on local knowledge bases using
the [langchain](https://github.com/langchain-ai/langchain) concept. The goal is to create a friendly and
offline-operable knowledge base Q&A solution that supports Chinese scenarios and open-source models.
💡 Inspired by [GanymedeNil](https://github.com/GanymedeNil)'s
project [document.ai](https://github.com/GanymedeNil/document.ai) and [AlexZhangji](https://github.com/AlexZhangji)'
s [ChatGLM-6B Pull Request](https://github.com/THUDM/ChatGLM-6B/pull/216), this project aims to establish a local
knowledge base Q&A application fully utilizing open-source models. The latest version of the project
uses [FastChat](https://github.com/lm-sys/FastChat) to integrate models like Vicuna, Alpaca, LLaMA, Koala, and RWKV,
leveraging the [langchain](https://github.com/langchain-ai/langchain) framework to support API calls provided
by [FastAPI](https://github.com/tiangolo/fastapi) or operations using a WebUI based
on [Streamlit](https://github.com/streamlit/streamlit).
![](docs/img/langchain_chatchat_0.3.0.png)
✅ This project supports mainstream open-source LLMs, embedding models, and vector databases, allowing full **open-source
** model **offline private deployment**. Additionally, the project supports OpenAI GPT API
calls and will continue to expand access to various models and model APIs.
⛓️ The implementation principle of this project is as shown below, including loading files -> reading text -> text
segmentation -> text vectorization -> question vectorization -> matching the `top k` most similar text vectors with the
question vector -> adding the matched text as context along with the question to the `prompt` -> submitting to the `LLM`
for generating answers.
📺 [Introduction Video](https://www.bilibili.com/video/BV13M4y1e7cN/?share_source=copy_web&vd_source=e6c5aafe684f30fbe41925d61ca6d514)
![Implementation Diagram](docs/img/langchain+chatglm.png)
From the document processing perspective, the implementation process is as follows:
![Implementation Diagram 2](docs/img/langchain+chatglm2.png)
🚩 This project does not involve fine-tuning or training processes but can utilize fine-tuning or training to optimize
the project's performance.
🌐 The `0.3.0` version code used in
the [AutoDL Mirror](https://www.codewithgpu.com/i/chatchat-space/Langchain-Chatchat/Langchain-Chatchat) has been updated
to version `v0.3.0` of this project.
🐳 Docker images will be updated soon.
🧑‍💻 If you want to contribute to this project, please refer to the [Developer Guide](docs/contributing/README_dev.md)
for more information on development and deployment.
## What Does Langchain-Chatchat Offer
### Features of Version 0.3.x
| Features | 0.2.x | 0.3.x |
|---------------------------------|-------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------|
| Model Integration | Local: fastchat<br>Online: XXXModelWorker | Local: model_provider, supports most mainstream model loading frameworks<br>Online: oneapi<br>All model integrations are compatible with the openai sdk |
| Agent | ❌ Unstable | ✅ Optimized for ChatGLM3 and QWen, significantly enhanced Agent capabilities ||
| LLM Conversations | ✅ | ✅ ||
| Knowledge Base Conversations | ✅ | ✅ ||
| Search Engine Conversations | ✅ | ✅ ||
| File Conversations | ✅ Only vector search | ✅ Unified as File RAG feature, supports BM25+KNN and other retrieval methods ||
| Database Conversations | ❌ | ✅ ||
| ARXIV Document Conversations | ❌ | ✅ ||
| Wolfram Conversations | ❌ | ✅ ||
| Text-to-Image | ❌ | ✅ ||
| Local Knowledge Base Management | ✅ | ✅ ||
| WEBUI | ✅ | ✅ Better multi-session support, custom system prompts... |
The core functionality of 0.3.x is implemented by Agent, but users can also manually perform tool calls:
|Operation Method|Function Implemented|Applicable Scenario|
|----------------|--------------------|-------------------|
|Select "Enable Agent", choose multiple tools|Automatic tool calls by LLM|Using models with Agent capabilities like
ChatGLM3/Qwen or online APIs|
|Select "Enable Agent", choose a single tool|LLM only parses tool parameters|Using models with general Agent
capabilities, unable to choose tools well<br>Want to manually select functions|
|Do not select "Enable Agent", choose a single tool|Manually fill in parameters for tool calls without using Agent
function|Using models without Agent capabilities|
More features and updates can be experienced in the actual deployment.
### Supported Model Deployment Frameworks and Models
This project already supports mainstream models on the market, such as [GLM-4-Chat](https://github.com/THUDM/GLM-4)
and [Qwen2-Instruct](https://github.com/QwenLM/Qwen2), among the latest open-source large language models and embedding
models. Users need to start the model deployment framework and load the required models by modifying the configuration
information. The supported local model deployment frameworks in this project are as follows:
| Model Deployment Framework | Xinference | LocalAI | Ollama | FastChat |
|------------------------------------|-----------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------|-------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------|
| Aligned with OpenAI API | ✅ | ✅ | ✅ | ✅ |
| Accelerated Inference Engine | GPTQ, GGML, vLLM, TensorRT | GPTQ, GGML, vLLM, TensorRT | GGUF, GGML | vLLM |
| Model Types Supported | LLM, Embedding, Rerank, Text-to-Image, Vision, Audio | LLM, Embedding, Rerank, Text-to-Image, Vision, Audio | LLM, Text-to-Image, Vision | LLM, Vision |
| Function Call | ✅ | ✅ | ✅ | / |
| More Platform Support (CPU, Metal) | ✅ | ✅ | ✅ | ✅ |
| Heterogeneous | ✅ | ✅ | / | / |
| Cluster | ✅ | ✅ | / | / |
| Documentation Link | [Xinference Documentation](https://inference.readthedocs.io/zh-cn/latest/models/builtin/index.html) | [LocalAI Documentation](https://localai.io/model-compatibility/) | [Ollama Documentation](https://github.com/ollama/ollama?tab=readme-ov-file#model-library) | [FastChat Documentation](https://github.com/lm-sys/FastChat#install) |
| Available Models | [Xinference Supported Models](https://inference.readthedocs.io/en/latest/models/builtin/index.html) | [LocalAI Supported Models](https://localai.io/model-compatibility/#/) | [Ollama Supported Models](https://ollama.com/library#) | [FastChat Supported Models](https://github.com/lm-sys/FastChat/blob/main/docs/model_support.md) |
In addition to the above local model loading frameworks, the project also supports
the [One API](https://github.com/songquanpeng/one-api) framework for integrating online APIs, supporting commonly used
online APIs such
as [OpenAI ChatGPT](https://platform.openai.com/docs/guides/gpt/chat-completions-api), [Azure OpenAI API](https://learn.microsoft.com/en-us/azure/ai-services/openai/reference), [Anthropic Claude](https://anthropic.com/), [Zhipu Qingyan](https://bigmodel.cn/),
and [Baichuan](https://platform.baichuan-ai.com/).
> [!Note]
> Regarding Xinference loading local models:
> Xinference built-in models will automatically download. To load locally downloaded models, you can
> execute `streamlit run xinference_manager.py` in the tools/model_loaders directory of the project after starting the
> Xinference service and set the local path for the specified model as prompted on the page.
## Quick Start
### Installation
#### 0. Software and Hardware Requirements
💡 On the software side, this project supports Python 3.8-3.11 environments and has been tested on Windows, macOS, and
Linux operating systems.
💻 On the hardware side, as version 0.3.0 has been modified to support integration with different model deployment
frameworks, it can be used under various hardware conditions such as CPU, GPU, NPU, and MPS.
#### 1. Install Langchain-Chatchat
Starting from version 0.3.0, Langchain-Chatchat provides installation in the form of a Python library. Execute the
following command for installation:
```shell
pip install langchain-chatchat -U
```
[!Note]
> Since the model deployment framework Xinference requires additional Python dependencies when integrated with
> Langchain-Chatchat, it is recommended to use the following installation method if you want to use it with the
> Xinference
> framework:
> ```shell
> pip install "langchain-chatchat[xinference]" -U
> ```
2. Model Inference Framework and Load Models
2. Model Inference Framework and Load Models
Starting from version 0.3.0, Langchain-Chatchat no longer directly loads models based on the local model path entered by
users. The involved model types include LLM, Embedding, Reranker, and the multi-modal models to be supported in the
future. Instead, it supports integration with mainstream model inference frameworks such
as [Xinference](https://github.com/xorbitsai/inference), [Ollama](https://github.com/ollama/ollama), [LocalAI](https://github.com/mudler/LocalAI), [FastChat](https://github.com/lm-sys/FastChat)
and [One API](https://github.com/songquanpeng/one-api).
Therefore, please ensure to run the model inference framework and load the required models before starting
Langchain-Chatchat.
Here is an example of Xinference. Please refer to
the [Xinference Document](https://inference.readthedocs.io/zh-cn/latest/getting_started/installation.html) for framework
deployment and model loading.
> [!WARNING]
> To avoid dependency conflicts, place Langchain-Chatchat and model deployment frameworks like Xinference in different
> Python virtual environments, such as conda, venv, virtualenv, etc.
#### 3. View and Modify Langchain-Chatchat Configuration
Starting from version 0.3.0, Langchain-Chatchat no longer modifies the configuration through local files but uses
command-line methods and will add configuration item modification pages in future versions.
The following introduces how to view and modify the configuration.
##### 3.1 View chatchat-config Command Help
Enter the following command to view the optional configuration types:
```shell
chatchat-config --help
```
You will get the following response:
```text
Usage: chatchat-config [OPTIONS] COMMAND [ARGS]...
指令` chatchat-config` 工作空间配置
Options:
--help Show this message and exit.
Commands:
basic 基础配置
kb 知识库配置
model 模型配置
server 服务配置
```
You can choose the required configuration type based on the above commands. For example, to view or
modify `basic configuration`, you can enter the following command to get help information:
```shell
chatchat-config basic --help
```
You will get the following response:
```text
Usage: chatchat-config basic [OPTIONS]
基础配置
Options:
--verbose [true|false] 是否开启详细日志
--data TEXT 初始化数据存放路径,注意:目录会清空重建
--format TEXT 日志格式
--clear 清除配置
--show 显示配置
--help Show this message and exit.
```
##### 3.2 Use chatchat-config to Modify Corresponding Configuration Parameters
To modify the `default llm` model in `model configuration`, you can execute the following command to view the
configuration item names:
```shell
chatchat-config basic --show
```
If no configuration item modification is made, the default configuration is as follows:
```text
{
"log_verbose": false,
"CHATCHAT_ROOT": "/root/anaconda3/envs/chatchat/lib/python3.11/site-packages/chatchat",
"DATA_PATH": "/root/anaconda3/envs/chatchat/lib/python3.11/site-packages/chatchat/data",
"IMG_DIR": "/root/anaconda3/envs/chatchat/lib/python3.11/site-packages/chatchat/img",
"NLTK_DATA_PATH": "/root/anaconda3/envs/chatchat/lib/python3.11/site-packages/chatchat/data/nltk_data",
"LOG_FORMAT": "%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s",
"LOG_PATH": "/root/anaconda3/envs/chatchat/lib/python3.11/site-packages/chatchat/data/logs",
"MEDIA_PATH": "/root/anaconda3/envs/chatchat/lib/python3.11/site-packages/chatchat/data/media",
"BASE_TEMP_DIR": "/root/anaconda3/envs/chatchat/lib/python3.11/site-packages/chatchat/data/temp",
"class_name": "ConfigBasic"
}
```
##### 3.3 Use chatchat-config to Modify Corresponding Configuration Parameters
To modify the default `llm model` in `model configuration`, you can execute the following command to view the
configuration item names:
```shell
chatchat-config model --help
```
You will get:
```text
Usage: chatchat-config model [OPTIONS]
模型配置
Options:
--default_llm_model TEXT 默认llm模型
--default_embedding_model TEXT 默认embedding模型
--agent_model TEXT agent模型
--history_len INTEGER 历史长度
--max_tokens INTEGER 最大tokens
--temperature FLOAT 温度
--support_agent_models TEXT 支持的agent模型
--set_model_platforms TEXT 模型平台配置 as a JSON string.
--set_tool_config TEXT 工具配置项 as a JSON string.
--clear 清除配置
--show 显示配置
--help Show this message and exit.
```
First, view the current `model configuration` parameters:
```shell
chatchat-config model --show
```
You will get:
```text
{
"DEFAULT_LLM_MODEL": "glm4-chat",
"DEFAULT_EMBEDDING_MODEL": "bge-large-zh-v1.5",
"Agent_MODEL": null,
"HISTORY_LEN": 3,
"MAX_TOKENS": null,
"TEMPERATURE": 0.7,
...
"class_name": "ConfigModel"
}
```
To modify the `default llm` model to `qwen2-instruct`, execute:
```shell
chatchat-config model --default_llm_model qwen2-instruct
```
For more configuration modification help, refer to [README.md](libs/chatchat-server/README.md)
4. Custom Model Integration Configuration
After completing the above project configuration item viewing and modification, proceed to step 2. Model Inference
Framework and Load Models and select the model inference framework and loaded models. Model inference frameworks include
[Xinference](https://github.com/xorbitsai/inference),[Ollama](https://github.com/ollama/ollama),[LocalAI](https://github.com/mudler/LocalAI),[FastChat](https://github.com/lm-sys/FastChat)
and [One API](https://github.com/songquanpeng/one-api), supporting new Chinese open-source models
like [GLM-4-Chat](https://github.com/THUDM/GLM-4) and [Qwen2-Instruct](https://github.com/QwenLM/Qwen2)
If you already have an address with the capability of an OpenAI endpoint, you can directly configure it in
MODEL_PLATFORMS as follows:
```text
chatchat-config model --set_model_platforms TEXT Configure model platforms as a JSON string.
```
- `platform_name` can be arbitrarily filled, just ensure it is unique.
- `platform_type` might be used in the future for functional distinctions based on platform types, so it should match
the platform_name.
- List the models deployed on the framework in the corresponding list. Different frameworks can load models with the
same name, and the project will automatically balance the load.
- Set up the model
```shell
$ chatchat-config model --set_model_platforms "[{
\"platform_name\": \"xinference\",
\"platform_type\": \"xinference\",
\"api_base_url\": \"http://127.0.0.1:9997/v1\",
\"api_key\": \"EMPT\",
\"api_concurrencies\": 5,
\"llm_models\": [
\"autodl-tmp-glm-4-9b-chat\"
],
\"embed_models\": [
\"bge-large-zh-v1.5\"
],
\"image_models\": [],
\"reranking_models\": [],
\"speech2text_models\": [],
\"tts_models\": []
}]"
```
#### 5. Initialize Knowledge Base
> [!WARNING]
> Before initializing the knowledge base, ensure that the model inference framework and corresponding embedding model
> are
> running, and complete the model integration configuration as described in steps 3 and 4.
```shell
cd # Return to the original directory
chatchat-kb -r
```
Specify text-embedding model for initialization (if needed):
```
cd # Return to the original directory
chatchat-kb -r --embed-model=text-embedding-3-smal
```
Successful output will be:
```text
----------------------------------------------------------------------------------------------------
知识库名称 samples
知识库类型 faiss
向量模型: bge-large-zh-v1.5
知识库路径 /root/anaconda3/envs/chatchat/lib/python3.11/site-packages/chatchat/data/knowledge_base/samples
文件总数量 47
入库文件数 42
知识条目数 740
用时 0:02:29.701002
----------------------------------------------------------------------------------------------------
总计用时 0:02:33.414425
```
The knowledge base path is in the knowledge_base directory under the path pointed by the *DATA_PATH* variable in
step `3.2`:
```shell
(chatchat) [root@VM-centos ~]# ls /root/anaconda3/envs/chatchat/lib/python3.11/site-packages/chatchat/data/knowledge_base/samples/vector_store
bge-large-zh-v1.5 text-embedding-3-small
```
##### Frequently asked questions
##### 1. Stuck when rebuilding the knowledge base or adding knowledge files under Windows
This issue often occurs in newly created virtual environments and can be confirmed through the following methods:
`from unstructured.partition.auto import partition`
If the statement gets stuck and cannot be executed, the following command can be executed:
```shell
pip uninstall python-magic-bin
# check the version of the uninstalled package
pip install 'python-magic-bin=={version}'
```
Then follow the instructions in this section to recreate the knowledge base.
#### 6. Start the Project
```shell
chatchat -a
```
Successful startup output:
![WebUI](docs/img/langchain_chatchat_webui.png)
> [!WARNING]
> As the `DEFAULT_BIND_HOST` of the chatchat-config server configuration is set to `127.0.0.1` by default, it cannot be
> accessed through other IPs.
>
> To modify, refer to the following method:
> <details>
> <summary>Instructions</summary>
>
> ```shell
> chatchat-config server --show
> ```
> You will get:
> ```text
> {
> "HTTPX_DEFAULT_TIMEOUT": 300.0,
> "OPEN_CROSS_DOMAIN": true,
> "DEFAULT_BIND_HOST": "127.0.0.1",
> "WEBUI_SERVER_PORT": 8501,
> "API_SERVER_PORT": 7861,
> "WEBUI_SERVER": {
> "host": "127.0.0.1",
> "port": 8501
> },
> "API_SERVER": {
> "host": "127.0.0.1",
> "port": 7861
> },
> "class_name": "ConfigServer"
> }
> ```
> To access via the machine's IP (such as in a Linux system), change the listening address to `0.0.0.0`.
> ```shell
> chatchat-config server --default_bind_host=0.0.0.0
> ```
> You will get:
> ```text
> {
> "HTTPX_DEFAULT_TIMEOUT": 300.0,
> "OPEN_CROSS_DOMAIN": true,
> "DEFAULT_BIND_HOST": "0.0.0.0",
> "WEBUI_SERVER_PORT": 8501,
> "API_SERVER_PORT": 7861,
> "WEBUI_SERVER": {
> "host": "0.0.0.0",
> "port": 8501
> },
> "API_SERVER": {
> "host": "0.0.0.0",
> "port": 7861
> },
> "class_name": "ConfigServer"
> }
> ```
> </details>
### Migration from Older Versions
* The structure of 0.3.x has changed significantly, it is strongly recommended to redeploy according to the
documentation.
The following guide does not guarantee 100% compatibility and success. Remember to backup important data in advance!
- First configure the operating environment according to the steps in `Installation`.
- Configure `DATA` and other options.
- Copy the knowledge_base directory of the 0.2.x project to the configured `DATA` directory.
---
## License
The code of this project follows the [Apache-2.0](LICENSE) agreement.
## Project Milestones
+ `April 2023`: `Langchain-ChatGLM 0.1.0` released, supporting local knowledge base question and answer based on
ChatGLM-6B model.
+ `August 2023`: `Langchain-ChatGLM` renamed to `Langchain-Chatchat`, released `0.2.0` version, using `fastchat` as
model loading solution, supporting more models and databases.
+ `October 2023`: `Langchain-Chatchat 0.2.5` released, launching Agent content, open source project won the third prize
in the hackathon held by `Founder Park & Zhipu AI & Zilliz`.
+ `December 2023`: `Langchain-Chatchat` open source project received more than **20K** stars.
+ `June 2024`: `Langchain-Chatchat 0.3.0` released, bringing a new project architecture.
+ 🔥 Let us look forward to the future story of Chatchat ···
## Contact Us
### Telegram
[![Telegram](https://img.shields.io/badge/Telegram-2CA5E0?style=for-the-badge&logo=telegram&logoColor=white "langchain-chatchat")](https://t.me/+RjliQ3jnJ1YyN2E9)
### Project Exchange Group
<img src="docs/img/qr_code_109.jpg" alt="二维码" width="300" />
🎉 Langchain-Chatchat project WeChat exchange group, if you are also interested in this project, welcome to join the
group chat to participate in the discussion.
### Official Account
<img src="docs/img/official_wechat_mp_account.png" alt="二维码" width="300" />
🎉 Langchain-Chatchat project official public account, welcome to scan the code to follow.
+13
View File
@@ -0,0 +1,13 @@
.idea/
.github/
Dockerfile
.dockerignore
../.gitignore
../.gitmodules
../LICENSE
../poetry.lock
../poetry.toml
../pyproject.toml
../docs/
../README.md
../README_en.md
+43
View File
@@ -0,0 +1,43 @@
# 基础镜像
FROM python:3.11
LABEL maintainer=Langchain-Chatchat
WORKDIR /root
# 环境变量
ENV CHATCHAT_ROOT=/root/chatchat_data
# 初始化环境
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo "Asia/Shanghai" > /etc/timezone
RUN apt-get update -y && \
apt-get install -y git && \
apt-get install -y --no-install-recommends libgl1 libglib2.0-0 && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
RUN pip install --upgrade pip setuptools
RUN pip install --index-url https://pypi.python.org/simple/ pipx && \
pipx install poetry --force
# Add poetry to PATH
ENV PATH="/root/.local/bin:${PATH}"
# 下载 Langchain-Chatchat
RUN git clone https://github.com/chatchat-space/Langchain-Chatchat.git
# 安装依赖
WORKDIR /root/Langchain-Chatchat/libs/chatchat-server
RUN poetry config virtualenvs.create false
RUN poetry install --with lint,test -E xinference
## 确保 Python 可以找到 chatchat 模块
ENV PYTHONPATH="/root/Langchain-Chatchat/libs/chatchat-server:${PYTHONPATH}"
# 初始化配置
WORKDIR /root/Langchain-Chatchat/libs/chatchat-server/chatchat
RUN python cli.py init
# 初始化知识库文件
ADD data.tar.gz $CHATCHAT_ROOT/
EXPOSE 7861 8501
ENTRYPOINT ["python", "cli.py", "start", "-a"]
Binary file not shown.
+32
View File
@@ -0,0 +1,32 @@
# 贡献指南
各位开发者,Langchain-Chatchat 由个人组织经过了不断地迭代和完善,作为一个不断进化的项目,
我们欢迎您的参与,无论是提交bug报告、功能请求、代码贡献、文档编写、测试、或者其他形式的贡献。
## 贡献方式
这里列出了一些您可以为 Langchain-Chatchat 做出贡献的方式:
- [Code](code.md): 帮助我们编写代码,修复bug,或者改进基础设施。
- Documentation: 帮助我们编写文档,使 chatchat 更容易使用。
- Discussions: 帮助回答用户的使用问题,讨论问题。
当您的贡献被接受,并在 master 分支生效后,您的名字将会自动被添加到贡献者列表中。
## Github Issue
我们需要跟踪功能请求与 Bug 报告
目前我们有使用 Issue 默认模板来让用户更好的描述问题,但是目前这个大部分 Issue 的用户可能依然选择只回复一句话,
对于这样的情况我们需要告知用户如何更好的描述问题。在 15 天内没有回复的 Issue 我们会关闭 Issue。
关于功能请求,备受关注的RAG话题我们会考虑加入到我们的开发计划中。
我们努力保持 Issue 的更新,但是我们也需要您的帮助,如果您发现有问题没有得到及时回复,请在 Issue 下@我们
## 寻求帮助
我们尽量使开发者更容易上手,当您遇到问题时,请联系维护人员,我们会尽力帮助您。
类似的 diff、formatting、linting、testing等问题,如果您不确定如何解决,请随时联系我们,
很多时候规则校验会阻碍一些开发者,您的思路如果足够优秀,我们会考虑调整规则。
+96
View File
@@ -0,0 +1,96 @@
# Langchain-Chatchat 源代码部署/开发部署指南
## 0. 拉取项目代码
如果您是想要使用源码启动的用户,请直接拉取 master 分支代码
```shell
git clone https://github.com/chatchat-space/Langchain-Chatchat.git
```
## 1. 初始化开发环境
Langchain-Chatchat 自 0.3.0 版本起,为方便支持用户使用 pip 方式安装部署,以及为避免环境中依赖包版本冲突等问题,
在源代码/开发部署中不再继续使用 requirements.txt 管理项目依赖库,转为使用 Poetry 进行环境管理。
### 1.1 安装 Poetry
> 在安装 Poetry 之前,如果您使用 Conda,请创建并激活一个新的 Conda 环境,例如使用 `conda create -n chatchat python=3.9` 创建一个新的 Conda 环境。
安装 Poetry: [Poetry 安装文档](https://python-poetry.org/docs/#installing-with-pipx)
> [!Note]
> 如果你没有其它 poetry 进行环境/依赖管理的项目,利用 pipx 或 pip 都可以完成 poetry 的安装,
> [!Note]
> 如果您使用 Conda 或 Pyenv 作为您的环境/包管理器,在安装Poetry之后,
> 使用如下命令使 Poetry 使用 virtualenv python environment (`poetry config virtualenvs.prefer-active-python true`)
### 1.2 安装源代码/开发部署所需依赖库
进入主项目目录,并安装 Langchain-Chatchat 依赖
```shell
cd Langchain-Chatchat/libs/chatchat-server/
poetry install --with lint,test -E xinference
# or use pip to install in editing mode:
pip install -e .
```
> [!Note]
> Poetry install 后会在你的虚拟环境中 site-packages 路径下生成一个 chatchat-`<version>`.dist-info 文件夹带有 direct_url.json 文件,这个文件指向你的开发环境
### 1.3 更新开发部署环境依赖库
当开发环境中所需的依赖库发生变化时,一般按照更新主项目目录(`Langchain-Chatchat/libs/chatchat-server/`)下的 pyproject.toml 再进行 poetry update 的顺序执行。
### 1.4 将更新后的代码打包测试
如果需要对开发环境中代码打包成 Python 库并进行测试,可在主项目目录执行以下命令:
```shell
poetry build
```
命令执行完成后,在主项目目录下会新增 `dist` 路径,其中存储了打包后的 Python 库。
## 2. 设置源代码根目录
如果您在开发时所使用的 IDE 需要指定项目源代码根目录,请将主项目目录(`Langchain-Chatchat/libs/chatchat-server/`)设置为源代码根目录。
执行以下命令之前,请先设置当前目录和项目数据目录:
```shell
cd Langchain-Chatchat/libs/chatchat-server/chatchat
export CHATCHAT_ROOT=/parth/to/chatchat_data
```
## 3. 关于 chatchat 配置项
`0.3.1` 版本开始,所有配置项改为 `yaml` 文件,具体参考 [Settings](settings.md)。
执行以下命令初始化项目配置文件和数据目录:
```shell
cd libs/chatchat-server
python chatchat/cli.py init
```
## 4. 初始化知识库
> [!WARNING]
> 这个命令会清空数据库、删除已有的配置文件,如果您有重要数据,请备份。
```shell
cd libs/chatchat-server
python chatchat/cli.py kb --recreate-vs
```
如需使用其它 Embedding 模型,或者重建特定的知识库,请查看 `python chatchat/cli.py kb --help` 了解更多的参数。
## 5. 启动服务
```shell
cd libs/chatchat-server
python chatchat/cli.py start -a
```
如需调用 API,请参考 [API 使用说明](api.md)
+132
View File
@@ -0,0 +1,132 @@
# Agent 和 Function Call
如果您希望寻找本框架的 Agent 部分,您可以参考 `libs/chatchat-server/chatchat/server/agent`,这里包含了目前框架中所有的Agent内容。
## Agent Factory
Agent Factory 中用于存储特殊的 Agent 模型,目前,拥有两个系列,分别是:
+ GLM 系列:包含 GLM-3GLM-4 开源模型。
+ Qwen系列:支持Qwen-2Qwen1.5 开源模型。
## Tool Factory
Tool Factory 中用于存储特殊的工具,目前,Chatchat已经自带了多个工具,分别是:
+ 高德地图POI搜索工具:利用高德地图API进行POI搜索,根据指定位置和类型返回相关地点的信息。
+ 高德地图天气查询工具:利用高德地图API获取指定城市的天气信息。
+ 音频问答工具:处理音频问题,使用提供的音频文件和文本问题来生成答案。
+ ARXIV论文工具:使用Arxiv.org进行搜索并检索各个领域的科学文章。
+ 数学计算器工具:用于进行简单数学计算,将用户的问题转换为可以由numexpr评估的数学表达式。
+ 互联网搜索工具:使用指定的搜索引擎在互联网上搜索并获取信息。
+ 本地知识库工具:使用本地知识库进行搜索,根据指定的数据库和查询获取信息。
+ 油管视频工具:使用该工具搜索YouTube视频。
+ 系统命令工具:使用Shell执行系统命令。
+ 文生图工具:根据用户的描述生成图片。
+ Prometheus对话工具:将自然语言转换为PromQL并在Prometheus服务器中执行查询,返回执行结果。
+ 数据库对话工具:将自然语言转换为SQL并在数据库中执行查询,返回执行结果。
+ 图片对话工具:根据图片和文本问题生成回答,并在图片上绘制矩形框。
+ 天气查询工具:查询指定城市的当前天气情况。
+ 维基百科搜索工具:使用维基百科进行搜索。
+ WolframAlpha工具:计算复杂的公式和执行高级数学运算。
## 增加自己的工具
我们支持使用 LangChain方式来增加自己的工具,您可以参考 `libs/chatchat-server/chatchat/server/agent/tools_registry`
中的工具模板,来增加自己的工具。
一个简单的构建方式是:
1. 新建一个 py 文件,用于书写自己的工具实现,例如
```python
@regist_tool(title="数学计算器")
def calculate(text: str = Field(description="a math expression")) -> float:
"""
Useful to answer questions about simple calculations.
translate user question to a math expression that can be evaluated by numexpr.
"""
import numexpr
try:
ret = str(numexpr.evaluate(text))
except Exception as e:
ret = f"wrong: {e}"
return BaseToolOutput(ret)
```
+ 使用 `@regist_tool` 装饰器用于注册工具。
+ 填写需要传入的参数以及传入参数对应的函数。
+ 使用 `BaseToolOutput` 来封装工具的顺畅。
2. 如果你想使用 LangChain 自带的工具,可以这么使用,这里列举了一个使用 LangChain Shell 工具的例子。
```python
from langchain_community.tools import ShellTool
from chatchat.server.pydantic_v1 import Field
from .tools_registry import BaseToolOutput, regist_tool
@regist_tool(title="系统命令")
def shell(query: str = Field(description="The command to execute")):
"""Use Shell to execute system shell commands"""
tool = ShellTool()
return BaseToolOutput(tool.run(tool_input=query))
```
这个例子在LangChain工具的基础上实例化工具,并作为Chatchat可以使用的工具进行调用。
## 让模型知道要调用工具
除了添加工具,在用户传入提示词的时候,也尽可能的强调需要使用工具,这样能提升模型调用工具的概率。比如
#### search_internet
使用这个工具是因为用户需要在联网进行搜索。这些问题通常是你不知道的,这些问题具有特点,
例如:
+ 联网帮我查询 xxx
+ 我想知道最新的新闻
或者,用户有明显的意图,需要获取事实的信息。
返回字段如下
```
search_internet
```
#### search_local_knowledge
使用这个工具是希望用户能够获取本地的知识,这些知识通常是你自身能力不具备的专业问题,或者用户指定了某个任务的。
例如:
+ 告诉我 关于 xxx 的 xxx 信息
+ xxx 中 xxx 的 xxx 是什么
返回字段如下
```
search_local_knowledge
```
## 优化Agent系统提示词
如果您的模型不兼容 / 不适配 LangChain 默认的 Struct Agent提示词模板。您可以在 配置文件中的 `prompt_settings.yaml`自定义提示词。
例如:GLM-3 模型的提示词为:
```
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
```
同时,如果您的模型返回格式不适配 LangChain 默认的 Struct Agent,您需要像 GLM-3 / GLM-4 一样自定义Agent执行逻辑,以确保能正确返回
Function Call的内容。
+307
View File
@@ -0,0 +1,307 @@
## 常用 API 接口调用方式
### 说明
所有接口可以到 `{api_address}/docs` 中查看参数和测试。
### /tools
该接口列出所有工具及其参数信息。
输入参数:无
输出示例:
```
{
"code": 200,
"msg": "success",
"data": {
"search_local_knowledgebase": {
"name": "search_local_knowledgebase",
"title": "本地知识库",
"description": "Use local knowledgebase from one or more of these: test: 关于test的知识库 samples: 关于本项目issue的解答 to get informationOnly local data on this knowledge use this tool. The 'database' should be one of the above [test samples].",
"args": {
"database": {
"title": "Database",
"description": "Database for Knowledge Search",
"choices": [
"test",
"samples"
],
"type": "string"
},
"query": {
"title": "Query",
"description": "Query for Knowledge Search",
"type": "string"
}
},
"config": {
"use": false,
"top_k": 3,
"score_threshold": 1,
"conclude_prompt": {
"with_result": "<指令>根据已知信息,简洁和专业的来回答问题。如果无法从中得到答案,请说 \"根据已知信息无法回答该问题\",不允许在答案中添加编造成分,答案请使用中文。 </指令>\n<已知信息>{{ context }}</已知信息>\n<问题>{{ question }}</问题>\n",
"without_result": "请你根据我的提问回答我的问题:\n{{ question }}\n请注意,你必须在回答结束后强调,你的回答是根据你的经验回答而不是参考资料回答的。\n"
}
}
},
...
}
}
```
### 通用对话接口(/chat/chat/completions
最主要的对话接口,兼容 openai sdk 格式。它支持以下3种对话模式:
- 纯 LLM 对话。传入 `model`, `messages` 参数即可,可选参数: `temperature`, `max_tokens`, `stream` 等。
- Agent 对话。在 LLM 对话的基础上,传入 `tools` 参数,可以让 LLM 选择合适的工具和参数,作为对话的参考。
- 半 Agent 对话。在 LLM 对话的基础上,传入 `tool_choice` 参数,可以让 LLM 解析参数,直接调用指定的工具,作为对话的参考。如果使用的 LLM 解析参数的效果不理想,也可以手动指定工具参数。
输入参数:与 openai sdk 参数一致。针对 chatchat 做了以下优化:
- `tools` 参数可以使用 chatchat 中编写的工具名称,所有支持的工具可以通过 `/tools` 接口获取。
- 在指定 `tool_choice` 的情况下,可以在 `extra_body` 中传入 `tool_input={...}` 来手动指定工具参数。
- 使用 Agent 功能时,`stream` 参数必须指定为 `True`。因为 Agent 是分步执行的,必须通过 SSE 把每个步骤逐一输出。注意:此时 SSE 的单元是执行步骤,LLM 的输出是非流式的。
调用示例:
- 纯 LLM 对话:
```python3
base_url = "http://127.0.0.1:7861/chat"
data = {
"model": "qwen1.5-chat",
"messages": [
{"role": "user", "content": "你好"},
{"role": "assistant", "content": "你好,我是人工智能大模型"},
{"role": "user", "content": "请用100字左右的文字介绍自己"},
],
"stream": True,
"temperature": 0.7,
}
# 方式一:使用 requests
import requests
response = requests.post(f"{base_url}/chat/completions", json=data, stream=True)
for line in response.iter_content(None, decode_unicode=True):
print(line, end="", flush=True)
# 方式二:使用 openai sdk
import openai
client = openai.Client(base_url=base_url, api_key="EMPTY")
resp = client.chat.completions.create(**data)
for r in resp:
print(r)
```
```shell
# 方式一输出,SSE 格式
data: {"id":"chat6aa251c3-3425-11ef-be81-603a7c6af450","choices":[{"delta":{"content":"","function_call":null,"role":"assistant","tool_calls":null},"finish_reason":null,"index":0,"logprobs":null}],"created":1719452077,"model":"qwen1.5-chat","object":"chat.completion.chunk","system_fingerprint":null,"usage":null,"message_id":null,"status":null}
data: {"id":"chat6aa251c3-3425-11ef-be81-603a7c6af450","choices":[{"delta":{"content":"我是","function_call":null,"role":null,"tool_calls":null},"finish_reason":null,"index":0,"logprobs":null}],"created":1719452077,"model":"qwen1.5-chat","object":"chat.completion.chunk","system_fingerprint":null,"usage":null,"message_id":null,"status":null}
data: {"id":"chat6abf605c-3425-11ef-9f15-603a7c6af450","choices":[{"delta":{"content":"阿里云","function_call":null,"role":null,"tool_calls":null},"finish_reason":null,"index":0,"logprobs":null}],"created":1719452078,"model":"qwen1.5-chat","object":"chat.completion.chunk","system_fingerprint":null,"usage":null,"message_id":null,"status":null}
data: {"id":"chat6ad00242-3425-11ef-af45-603a7c6af450","choices":[{"delta":{"content":"自主研发的","function_call":null,"role":null,"tool_calls":null},"finish_reason":null,"index":0,"logprobs":null}],"created":1719452078,"model":"qwen1.5-chat","object":"chat.completion.chunk","system_fingerprint":null,"usage":null,"message_id":null,"status":null}
...
```
```shell
# 方式二输出:
ChatCompletionChunk(id='chat682070c8-3426-11ef-947d-603a7c6af450', choices=[Choice(delta=ChoiceDelta(content='', function_call=None, role='assistant', tool_calls=None), finish_reason=None, index=0, logprobs=None)], created=1719452503, model='qwen1.5-chat', object='chat.completion.chunk', system_fingerprint=None, usage=None, message_id=None, status=None)
ChatCompletionChunk(id='chat682070c8-3426-11ef-947d-603a7c6af450', choices=[Choice(delta=ChoiceDelta(content='我是', function_call=None, role=None, tool_calls=None), finish_reason=None, index=0, logprobs=None)], created=1719452503, model='qwen1.5-chat', object='chat.completion.chunk', system_fingerprint=None, usage=None, message_id=None, status=None)
ChatCompletionChunk(id='chat683fdd72-3426-11ef-be33-603a7c6af450', choices=[Choice(delta=ChoiceDelta(content='由阿里', function_call=None, role=None, tool_calls=None), finish_reason=None, index=0, logprobs=None)], created=1719452503, model='qwen1.5-chat', object='chat.completion.chunk', system_fingerprint=None, usage=None, message_id=None, status=None)
ChatCompletionChunk(id='chat68511ba1-3426-11ef-b2be-603a7c6af450', choices=[Choice(delta=ChoiceDelta(content='云开发', function_call=None, role=None, tool_calls=None), finish_reason=None, index=0, logprobs=None)], created=1719452503, model='qwen1.5-chat', object='chat.completion.chunk', system_fingerprint=None, usage=None, message_id=None, status=None)
...
```
- Agent 对话
以下示例仅展示使用 `requests` 的情况,可以自行尝试使用 `openai sdk` 进行请求,参数和输出内容是一样的。
```python3
base_url = "http://127.0.0.1:7861/chat"
tools = list(requests.get(f"http://127.0.0.1:7861/tools").json()["data"])
data = {
"model": "qwen1.5-chat",
"messages": [
{"role": "user", "content": "37+48="},
],
"stream": True,
"temperature": 0.7,
"tools": tools,
}
import requests
response = requests.post(f"{base_url}/chat/completions", json=data, stream=True)
for line in response.iter_content(None, decode_unicode=True):
print(line)
```
```shell
# 输出:
data: {"id": "chat39830df6-d016-4b91-b502-e113bb71542c", "object": "chat.completion.chunk", "model": "qwen1.5-chat", "created": 1719453364, "status": 1, "message_type": 1, "message_id": null, "is_ref": false, "choices": [{"delta": {"content": "", "tool_calls": []}, "role": "assistant"}]}
data: {"id": "chatb05f9cb2-1e93-4657-806b-29ec135483b9", "object": "chat.completion.chunk", "model": "qwen1.5-chat", "created": 1719453367, "status": 3, "message_type": 1, "message_id": null, "is_ref": false, "choices": [{"delta": {"content": "Thought: The problem involves adding two numbers: 37 and 48. To perform this calculation, I will use the calculator API.\nAction: calculate\nAction Input: {\"text\": \"37 + 48\"}", "tool_calls": []}, "role": "assistant"}]}
data: {"id": "chat73adade0-b62f-412a-a448-9002a59cbc30", "object": "chat.completion.chunk", "model": "qwen1.5-chat", "created": 1719453367, "status": 4, "message_type": 1, "message_id": null, "is_ref": false, "choices": [{"delta": {"content": "Thought: The problem involves adding two numbers: 37 and 48. To perform this calculation, I will use the calculator API.\nAction: calculate\nAction Input: {\"text\": \"37 + 48\"}", "tool_calls": []}, "role": "assistant"}]}
data: {"id": "chat7752232b-7360-4010-bc55-e50fa8ac9f44", "object": "chat.completion.chunk", "model": "qwen1.5-chat", "created": 1719453367, "status": 6, "message_type": 1, "message_id": null, "is_ref": false, "choices": [{"delta": {"content": "", "tool_calls": [{"index": 0, "id": "f2b20744-3958-4e3b-9e51-c5738d87a020", "type": "function", "function": {"name": "calculate", "arguments": "{'text': '37 + 48'}"}, "tool_output": null, "is_error": false}]}, "role": "assistant"}]}
data: {"id": "chatef5f948e-4772-477d-823d-ce74b38ba586", "object": "chat.completion.chunk", "model": "qwen1.5-chat", "created": 1719453367, "status": 7, "message_type": 1, "message_id": null, "is_ref": false, "choices": [{"delta": {"content": "", "tool_calls": [{"index": 0, "id": "f2b20744-3958-4e3b-9e51-c5738d87a020", "type": "function", "function": {"name": "calculate", "arguments": "{'text': '37 + 48'}"}, "tool_output": "85", "is_error": false}]}, "role": "assistant"}]}
data: {"id": "chatdee106c6-42e6-41cf-b2df-692431829e4d", "object": "chat.completion.chunk", "model": "qwen1.5-chat", "created": 1719453367, "status": 1, "message_type": 1, "message_id": null, "is_ref": false, "choices": [{"delta": {"content": "", "tool_calls": []}, "role": "assistant"}]}
data: {"id": "chat819ef11b-576f-4489-b6bb-47565eb69ee8", "object": "chat.completion.chunk", "model": "qwen1.5-chat", "created": 1719453370, "status": 3, "message_type": 1, "message_id": null, "is_ref": false, "choices": [{"delta": {"content": " The calculation 37 + 48 has been successfully performed using the calculate API, resulting in the result of 85. Therefore, the final answer to the given question is 85. \n\nJSON Object:\n{\n \"answer\": 85\n}", "tool_calls": []}, "role": "assistant"}]}
data: {"id": "chatb6b1071b-5346-4713-922c-b2887728491f", "object": "chat.completion.chunk", "model": "qwen1.5-chat", "created": 1719453370, "status": 5, "message_type": 1, "message_id": null, "is_ref": false, "choices": [{"delta": {"content": " The calculation 37 + 48 has been successfully performed using the calculate API, resulting in the result of 85. Therefore, the final answer to the given question is 85. \n\nJSON Object:\n{\n \"answer\": 85\n}", "tool_calls": []}, "role": "assistant"}]}
```
输出中包含一个 `status` 字段,代表 Agent 当前执行阶段。在 `status` 为 6 和 7 的输出中,可以看到 tool_call 的相关信息。具体值为:
```python3
class AgentStatus:
llm_start: int = 1
llm_new_token: int = 2
llm_end: int = 3
agent_action: int = 4
agent_finish: int = 5
tool_start: int = 6
tool_end: int = 7
error: int = 8
```
输出中包含一个 `message_type` 字段,代表输出内容的类型,主要用于前端渲染不同的消息,当前除了`text2image` 工具是 `IMAGE`,其它都是 `TEXT`。具体值为:
```python3
class MsgType:
TEXT = 1
IMAGE = 2
AUDIO = 3
VIDEO = 4
```
- 知识库对话(LLM 自动解析参数)
直接指定 `tool_choice` 为 `"search_local_knowledgebase"`工具即可使用知识库对话功能。其它工具对话类似。
```python3
base_url = "http://127.0.0.1:7861/chat"
data = {
"messages": [
{"role": "user", "content": "如何提问以获得高质量答案"},
],
"model": "qwen1.5-chat",
"tool_choice": "search_local_knowledgebase",
"stream": True,
}
import requests
response = requests.post(f"{base_url}/chat/completions", json=data, stream=True)
for line in response.iter_content(None, decode_unicode=True):
print(line)
```
在 `status` 为 6 和 7 的返回值中,可以获取工具的调用和输出信息。
由于输出信息太多,这里不做展示,请自行测试。
- 知识库对话(手动传入参数)
直接指定 `tool_choice` 为 `"search_local_knowledgebase"`,再通过 `tool_input` 设定工具参数,即可手动调用工具,实现指定知识库对话。
```python3
base_url = "http://127.0.0.1:7861/chat"
data = {
"messages": [
{"role": "user", "content": "如何提问以获得高质量答案"},
],
"model": "qwen1.5-chat",
"tool_choice": "search_local_knowledgebase",
"tool_input": {"database": "samples", "query": "如何提问以获得高质量答案"},
"stream": True,
}
import requests
response = requests.post(f"{base_url}/chat/completions", json=data, stream=True)
for line in response.iter_content(None, decode_unicode=True):
print(line)
```
在输出中可以看出 `status` 为 6 和 7 的工具解析过程已经不存在了,说明工具调用不是通过 LLM 完成的。
由于输出信息太多,这里不做展示,请自行测试。
### RAG 接口 /knowledge_base/chat/compleitons
相比于 /chat/chat/completions 接口,本接口主要用于 RAG,支持更多的参数,其返回值也是 openai sdk 兼容的。除了 openai.chat.completions 规定的参数,还支持以下参数:
- mode:检索模式:
- "local_kb" 检索本地知识库,需提供 "kb_name" 指定知识库名称
- "temp_kb" 文件对话,需提供 "knowledge_id" 指定文件对话的临时知识库 ID
- "search_engine" 使用搜索引擎,需提供 "search_engine_name" 指定使用的搜索引擎
- top_k: 检索结果数量
- score_threshold: 匹配分值阈值
- prompt_name: 使用的 prompt 模板名称
- return_direct: 如果为 True,则仅返回检索结果,不经由 LLM
- messages: messages[-1]["content"] 将作为检索对象,messages[:-1] 将作为 history
返回值:
- stream 为 True 时,第一个 ChatCompletionChunk.docs 包含检索结果
- stream 为 False 时,ChatCompletion.docs 包含检索结果
调用示例(这里使用 openai sdk 演示本地知识库问答的情况,requests 参数相同,只是把 extra_body 中的内容放到 data 里即可):
- 本地知识库问答
```python3
base_url = "http://127.0.0.1:7861/knowledge_base/local_kb/samples"
data = {
"model": "qwen2-instruct",
"messages": [
{"role": "user", "content": "你好"},
{"role": "assistant", "content": "你好,我是人工智能大模型"},
{"role": "user", "content": "如何高质量提问?"},
],
"stream": True,
"temperature": 0.7,
"extra_body": {
"top_k": 3,
"score_threshold": 2.0,
"return_direct": True,
},
}
import openai
client = openai.Client(base_url=base_url, api_key="EMPTY")
resp = client.chat.completions.create(**data)
for r in resp:
print(r)
```
输出示例:
```shell
ChatCompletionChunk(id='chat9973e445-8581-45ca-bde5-148fc724b30b', choices=[Choice(delta=None, finish_reason=None, index=None, logprobs=None, message={'role': 'assistant', 'content': '', 'finish_reason': 'stop', 'tool_calls': []})], created=1720592802, model=None, object='chat.completion', service_tier=None, system_fingerprint=None, usage=None, status=None, message_type=1, message_id=None, is_ref=False, docs=['出处 [1] [test_files/test.txt](http://127.0.0.1:7861//knowledge_base/download_doc?knowledge_base_name=samples&file_name=test_files%2Ftest.txt) \n\n[这就是那幅名画]: http://yesaiwen.com/art\nof\nasking\nchatgpt\nfor\nhigh\nquality\nansw\nengineering\ntechniques/#i\n3\t"《如何向ChatGPT提问并获得高质量的答案》"\n\n', '出处 [2] [test_files/test.txt](http://127.0.0.1:7861//knowledge_base/download_doc?knowledge_base_name=samples&file_name=test_files%2Ftest.txt) \n\nChatGPT是OpenAI开发的一个大型语言模型,可以提供各种主题的信息,\n# 如何向 ChatGPT 提问以获得高质量答案:提示技巧工程完全指南\n## 介绍\n我很高兴欢迎您阅读我的最新书籍《The Art of Asking ChatGPT for High-Quality Answers: A complete Guide to Prompt Engineering Techniques》。本书是一本全面指南,介绍了各种提示技术,用于从ChatGPT中生成高质量的答案。\n我们将探讨如何使用不同的提示工 程技术来实现不同的目标。ChatGPT是一款最先进的语言模型,能够生成类似人类的文本。然而,理解如何正确地向ChatGPT提问以获得我们所需的高质量输出非常重要。而这正是 本书的目的。\n无论您是普通人、研究人员、开发人员,还是只是想在自己的领域中将ChatGPT作为个人助手的人,本书都是为您编写的。我使用简单易懂的语言,提供实用的解释,并在每个提示技术中提供了示例和提示公式。通过本书,您将学习如何使用提示工程技术来控制ChatGPT的输出,并生成符合您特定需求的文本。\n在整本书中,我们还提供了如何结合不同的提示技术以实现更具体结果的示例。我希望您能像我写作时一样,享受阅读本书并从中获得知识。\n<div style="page\nbreak\nafter:always;"></div>\n## 第一章:Prompt 工程技术简介\n什么是 Prompt 工程?\nPrompt 工程是创建提示或指导像 ChatGPT 这样的语言模型输出的过程。它允许用户控制模型的输出并生成符合其特定需求的文本。\n\n', '出处 [3] [test_files/test.txt](http://127.0.0.1:7861//knowledge_base/download_doc?knowledge_base_name=samples&file_name=test_files%2Ftest.txt) \n\nPrompt 公式是提示的特定格式,通常由三个主要元素组成:**\n任务:对提示要求模型生成的内容进行清晰而简洁的陈述。\n指令:在生成文本时模型应遵循的指令。\n角色:模型在生成文本时应扮演的角色。\n在本书中,我们将探讨可用于 ChatGPT 的各种 Prompt 工程技术。我们将讨论不同类型的提示,以及如何使用它们实现您想要的特定目标。\n<div style="page\nbreak\nafter:always;"></div>\n## 第二章:指令提示技术\n现在,让我们开始探索“指令提示技术”,以及如何使用它从ChatGPT中生成高质量的文本。\n 指令提示技术是通过为模型提供具体指令来引导ChatGPT的输出的一种方法。这种技术对于确保输出相关和高质量非常有用。\n要使用指令提示技术,您需要为模型提供清晰简洁的任务,以及具体的指令以供模型遵循。\n例如,如果您正在生成客户服务响应,您将提供任务,例如“生成响应客户查询”的指令,例如“响应应该专业且提供准确的信息”。\n 提示公式:“按照以下指示生成[任务]:[指令]”\n示例:\n生成客户服务响应:**\n任务:生成响应客户查询\n指令:响应应该专业且提供准确的信息\n提示公式:“按照以下 指示生成专业且准确的客户查询响应:响应应该专业且提供准确的信息。”\n生成法律文件:**\n任务:生成法律文件\n指令:文件应符合相关法律法规\n提示公式:“按照以下 指示生成符合相关法律法规的法律文件:文件应符合相关法律法规。”\n使用指令提示技术时,重要的是要记住指令应该清晰具体。这将有助于确保输出相关和高质量。可以将指 令提示技术与下一章节中解释的“角色提示”和“种子词提示”相结合,以增强ChatGPT的输出。\n\n'])
```
- 文件对话
```python3
# knowledge_id 为 /knowledge_base/upload_temp_docs 的返回值
base_url = "http://127.0.0.1:7861/knowledge_base/temp_kb/{knowledge_id}"
data = {
"model": "qwen2-instruct",
"messages": [
{"role": "user", "content": "你好"},
{"role": "assistant", "content": "你好,我是人工智能大模型"},
{"role": "user", "content": "如何高质量提问?"},
],
"stream": True,
"temperature": 0.7,
"extra_body": {
"top_k": 3,
"score_threshold": 2.0,
"return_direct": True,
},
}
import openai
client = openai.Client(base_url=base_url, api_key="EMPTY")
resp = client.chat.completions.create(**data)
for r in resp:
print(r)
```
- 搜索引擎问答
```python3
engine_name = "bing" # 可选值:bing, duckduckgo, metaphor, searx
base_url = f"http://127.0.0.1:7861/knowledge_base/search_engine/{engine_name}"
data = {
"model": "qwen2-instruct",
"messages": [
{"role": "user", "content": "你好"},
{"role": "assistant", "content": "你好,我是人工智能大模型"},
{"role": "user", "content": "如何高质量提问?"},
],
"stream": True,
"temperature": 0.7,
"extra_body": {
"top_k": 3,
"score_threshold": 2.0,
"return_direct": True,
},
}
import openai
client = openai.Client(base_url=base_url, api_key="EMPTY")
resp = client.chat.completions.create(**data)
for r in resp:
print(r)
```
+62
View File
@@ -0,0 +1,62 @@
# 代码贡献
贡献此仓库的代码时,请查阅 ["fork and pull request"](https://docs.github.com/en/get-started/exploring-projects-on-github/contributing-to-a-project) 流程,除非您是项目的维护者。请不要直接提交到主分支。
在提交PR之前,请检查按照pull request模板的指导进行操作。注意,我们的CI系统会自动运行linting和测试,以确保您的代码符合我们的标准。
更重要的是,我们需要保持良好的单元测试和文档,如果你做了如下操作:
- 添加新功能
更新受影响的操作文档
- 修复bug
尽可能添加一个单元测试,在tests/integration_tests或tests/unit_tests中
## 依赖管理:Poetry 与 env/dependency 管理方法
这个项目使用 Poetry 来管理依赖。
> [!Note]
> 在安装 Poetry 之前,如果您使用 Conda,请创建并激活一个新的 Conda 环境,例如使用 `conda create -n chatchat python=3.9` 创建一个新的 Conda 环境。
安装 Poetry: [Poetry 安装文档](https://python-poetry.org/docs/#installing-with-pipx)
> [!Note]
> 如果你没有其它 poetry 进行环境/依赖管理的项目,利用 pipx 或 pip 都可以完成 poetry 的安装,
> [!Note]
> 如果您使用 Conda 或 Pyenv 作为您的环境/包管理器,在安装Poetry之后,
> 使用如下命令使 Poetry 使用 virtualenv python environment (`poetry config virtualenvs.prefer-active-python true`)
## 本地开发环境安装
- 选择主项目目录
```shell
cd Langchain-Chatchat/libs/chatchat-server/
```
- 安装chatchat依赖(for running chatchat lint\tests):
```shell
poetry install --with lint,test
```
> Poetry install后会在你的site-packages安装一个chatchat-`<version>`.dist-info文件夹带有direct_url.json文件,这个文件指向你的开发环境
## 格式化和代码检查
在提交PR之前,请在本地运行以下命令;CI系统也会进行检查。
### 代码格式化
本项目使用ruff进行代码格式化。
### 关于
要对某个库进行格式化,请在相应的库目录下运行相同的命令:
```shell
cd {chatchat-server|chatchat-frontend}
make format
```
此外,你可以使用format_diff命令仅对当前分支中与主分支相比已修改的文件进行格式化:
```shell
make format_diff
```
当你对项目的一部分进行了更改,并希望确保更改的部分格式正确,而不影响代码库的其他部分时,这个命令特别有用。
+38
View File
@@ -0,0 +1,38 @@
### 仓库结构
如果您想要贡献代码,您需要了解仓库的结构。这将有助于您找到您想要的文件,以及了解如何将您的代码提交到仓库。
chatchat沿用了 monorepo的组织方式, 项目的代码库包含了多个包。
以下是可视化为树的结构:
```shell
.
├── docker
├── docs # 文档
├── frontend # 前端
├── libs
│ ├── chatchat-server # 服务端
│ │ └── tests
│ │ ├── integration_tests # 集成测试 (每个包都有,为了简洁没有展示)
│ │ └── unit_tests # 单元测试 (每个包都有,为了简洁没有展示)
```
根目录还包含以下文件:
pyproject.toml: 用于构建文档和文档linting的依赖项,cookbook。
Makefile: 包含用于构建,linting和文档和cookbook的快捷方式的文件。
根目录中还有其他文件,但它们的都应该是顾名思义的,请查看相应的文件夹以了解更多信息。
### 代码
代码库中的代码分为两个部分:
- libs/chatchat-server目录包含chatchat服务端代码。
- frontend目录包含chatchat前端代码。
详细的
+35
View File
@@ -0,0 +1,35 @@
## 项目配置项使用说明
项目所有配置项由 `chatchat.settings.Settings` 统一管理,代替原来通过 `chatchat/configs/*.py` 配置的方式。
绝大部分配置项沿用了原来的名字和分组,少数进行了整合。
### 改进后的优点:
- 配置项与 py 代码分离,减少代码升级带来的麻烦,更改配置更方便
- 切换不同的 yaml 文件即可加载不同的配置,方便多环境管理和测试
- 配置项通过 `pydantic` 模型定义,加强了数据验证,简化了环境变量的读取,可以使用 `yaml/json/toml` 不同的文件后端
- 可以自动生成 yaml 文件模板,添加配置说明
- 所有配置项进行了缓存减少文件读取,当 .yaml/.env 文件被修改时可以自动刷新缓存
### 使用方式:
```python3
from chatchat.settings import Settings
print(Settings.basic_settings) # 基本配置信息,包括数据目录、服务器配置等
print(Settings.kb_settings) # 知识库相关配置项
print(Settings.model_settings) # 模型相关配置项
print(Settings.tool_settings) # 工具相关配置项
print(Settings.prompt_settings) # prompt 模板
```
** 注意 **:如果使用 `Settings.xx_settings.XX` 这种方式,配置项会自动跟踪配置文件的修改而刷新;如果使用 `s = Settings.xx_settings; s.XX` 这种方式,配置项不会自动刷新。
### 添加或更改配置项:
第一步:直接在 `chatchat/settings.py` 对应的 XXSettings 类中添加字段,建议:
- 每个字段都设定默认值
- 给字段添加必要的说明
第二步:执行 `CHATCHAT_ROOT=/path/to/data chatchat init --gen-config` 更新配置模板
Binary file not shown.

After

Width:  |  Height:  |  Size: 148 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 554 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 MiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 123 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 42 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 28 KiB

+9
View File
@@ -0,0 +1,9 @@
<svg width="654" height="213" viewBox="0 0 654 213" fill="none" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<rect x="654" width="213" height="654" transform="rotate(90 654 0)" fill="url(#pattern0)"/>
<defs>
<pattern id="pattern0" patternContentUnits="objectBoundingBox" width="1" height="1">
<use xlink:href="#image0_237_57" transform="matrix(0.0204695 0 0 0.00666667 -0.00150228 0)"/>
</pattern>
<image id="image0_237_57" width="49" height="150" xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADEAAACWCAYAAAB3hWBKAAAMyElEQVR4Ae1de5AcRRk/AR88C2MgIdzdfB0jIioFIoggGkoeCbnt3lAVtUALygdCUSWI0X8M3LcHiUHkEQoIuem7aKR4pCJSFFqQ6cvyCMnMXngVBORhBaG0ohaiIgqCrPX1bO/OzM7uzcztZAO1VzU1szPf1/39+uvn933d19fX+9vNSgAFuwo53J/rVYDzcoWNAtaiYNVcLw5X5guCA+YKgAoodxAFODdXEByeKhVA5KyJ/nlI2mh1CfZaAOSzLeka/GMB+uqIGDgpVwBTJX7VabP2DQqEAlZNxUPfUcCWOh9nz685pu/9SfhyoRnh1tF1YQSrljhckCSjUsFaGORDbn0zCV8uNCVuLQoLw3iSjLCvbw/k7I0GL9yehC8XmpKArzYEYdWSsBYnzQgFbG/wwmNJ+TpOh8I6qyGI7ipXJMkEl/R9ADm8XuflbHMSvlxoRoasz9cFaQyIG1CwpSXOTsUizG+6CoNDyOGuEB+H1bkImCRRnN+3Fwp4NSRQA0ziUb40NPjlJPnlRlPi7IfTAsHZxtyES5qw7mkEjGcCwmErnt4/I2leudONFAePGebwIxRsHQoot5/1snuwAMVqX9/7chesl0GvBHolkK0E/JEbHsvUQ+mJI7s0W84d4kLBrsgqvOEr8S6CuJLP3D88G822Fu8qCBSDp5jSnM69uyA4403CF+C8pklf3EQw8O6KM5jVodqdPpkR0f/pCAgvfSpd5qBZ7LBgf68D4ewPXRYpW/YoGK0fGtPuxXMPy5ZSF7lKnH0nBEKw5V0UJ1vWP1k0+GEU7M06EM52rl/St2e21LrERdNp5DBRB6HNkmyy/VQ8YqAuwLldEt/PFgV7KQQg2D6SPnPA7oLg7K0eCF39uqwJmjIkMCK3NkiTobkI87tanXqZ90qggyWAwjoh7ay1iZ73z+ugSOmTQs52TruLFdb16XPuIEcPRH1Ef7drgrNfYhGO6mDlyD8p5OzqYBvK3f2bB6QrxJyBIAgU8Os88sk9TW01r7cH9iaZfnLPtNMZlDhcFNRGiVtndzqP3NPDAhwfBIEcbss9005ngBzOD4EQsL3TeaRKjxpmqqVoyH9dt5K8nCrTThOjYH8Ol2pdsIYZp9GI499x9lCn5UqVXidAkNknVaadJp4WCA7vIGc3dN3EQ9EDWZanJW79AAtweKcLtZfebl8COhClEf6GyNkXd3uhowKWBHw/1I1ytixKQ79rJs1ADC27IY6uK+90Iwz09a3cU9TLhMAK2NIVgeMy7YGIK5VuvOtpohulHpdnTxNxpdKNd+8NTTQNdjDWZE8twvwSt04OjRMcnoqja3q3aHBu7sqJaiIkaGAQzPw+7/0TVEI9EEk01dNEwtaECw/tb2qMgVCfaX/bFQ07IdYeWa8EeiVQKwHPkWd5jv2Yp2Q1y+UqO1VcrA5jHbI+E1XANUv6976cs49H30/521P28iyCB3nSgKDdAcjhGdrysGLxoR8pcRg2/g3kek/g2JRCBwk2bx7b33PsN4ICZXlOCuL6hfM+iII9iQXrKvKfLz/TOgQ53IHcGiH3gJ67cUgHYlKNn5JF6ChPUhBITkoBt+s9S4IVDIgVC2cfhILdqCPg0oJwHVtEBfIc+1bPsTHNVdk0/qWghuOekVujyOFvtXC9paUACEM/wgdPxNQglH1kGIT9rEmwk3cSGDn7J1UhSrdm/73N98TC9rotWMAqFDCeKu9yubyXq+zX6kAcO5e42BJnS5DD76khN4GgNYuxTgrr+tQgKEHPkffUQShZdTeu/ViqkkhAjEsO2g85PIoCtmFhzj6hNiEaWz5x8dzDUlcnDULJc4IgqMtNIFdqkuWczdJBkxzWxIEg+zAKeDgTCNe95QBX2W8ZIK6yd1aruEdqKRMw4BA7DnXgpLW83sVSb0VB9gJeoB1jmUBQ3p6S6w0IuruOPZ6md5p07MQxgCVh/RiFv+EW+cAc3eUW4Sg9htBgl7ZhEwDXketcZf87CCL1s2MnjovVRmsOjw4PDX4hqjzaeJgpViRYlVILb+ZaKUBEBe/I7/cKCMdz7Punc1UmxrobK94RdfYS6ZVAcwnQIDfpyKOp349envqFnvc0c+0mb6rr1+/pKftbniNfatXNViZkwYi7rbzmcG9ibNhVtuMq2f0dYdu2rdnHVbLcSvjG+9EhA0Kvyc0YoWS1smn0k+ZbqztNAmk2G/yOHH5LE0K9VY4miNMY7G5oCNraUBDUxBP3rTs4yOM6csoTVPAMmE1L0RAIAb/Rs1oOm0pF9o1Ma+xtD645xHXk2xGB3nYd6dbGjf+Zb0EQJIir5IvmmzchrwkKF33WEz86/4azv4QCxAS8ghyuq81uz/dBMBnlb/vbVfapdUH0xE8+75btfsMUnFNNbhoLHRHjOnKz4XWVbBsDSNUEuXUmctiEgt2NBbgYOdw6zFkFOXvePxsHVmbShKdk0QhC94qyv24A0N1z5L8a3xttwv9m32u+UQMP8sU96+qkjQRwszZgC1iJAu7V6wwdGNkpEBtHQ+HSSUFQ1YsTPPiuFQgU7EF/1ad3mXmp1xNRTXhKnhPM2HPs101pR9uE58hJ88117LuCfHHPbUAsR84kcrYZs6yxPWWfZAShu+vYz2wv37ifEaKVJlw1dnKIT9lTHm7VGoR1gh9nW6tOaRdFNQtgvQfygcintWmTbE/K/m9dWLJHKblS91pKvlN/T+DV2MkGeNy91uv8DMmyQcYCDj/3Sx5eoLN0/P2vGdsEZegp+86gQBmeH48TPPguBMKYZ/SdPYcF9hXk8B9/fU222JRdLGXkKnuWp+xnMwhfpTaTZLSmfHR14mx9GJw/YlNb8Pf7ZVxjayDa4iE3pAHiKrmjokaPDQrV7lkfbCUGjwjSoICV2kCweNbByNktmU37wUQrE6MnuI5c6jpylPr+6GqP5lgVx76WeiqyHgZ5e8+9EnivlQD1MtHVXOLfajz/KJt2BV4pr53tKntjmp6pmdb+abs8cv/mOfbWZqFaL47iabsIgqpQvFC7BoQ+wm+6Gw1p/bCrQGARDtQW8YUzDjDVCzl8DTmbJDcwXSjgMhrZzfdE94oaOzsKgpyRiZhTEmERgLyjwwKepg2HtZDuJ5Gzh5DDtTWX1x30nCrpaHUiB0uqBFIQ+yDgduSwAgXs8H3X7GrtFi4CUFKXFwc+Smc+p0i2r69mb/qr0QZZyLdsWb93qkQSEl9esBg5VIgcOawmrdQOyaINuNlBUIKekmMGRO1eTChXYrIRAZ/THiEOt2FhzkwdFsFhgg7ZpcMTzflQmTRBUjQ55B05mVi6hIR+xABc45/WAjv02qEIByJnzyGHX+lzaykSjo5+TeuMJxl2lNd+yHXkK0Ft0Gw2oXypyHDhjAP0sZXcuoQYa435d/6GXCjTnY62bErUc6QKCpjPc7LBjsyVly6YfSyFP5SEdSEumjWXutkmoaMvPEfelI/gwQGxPQhtPKPqQtE0ZLqkSBs6Pj8mmDI23slV8qJug9ANm8P9NEaEo6Dh1ZBZk2jiqlNFyQXdBmFqhx6hBazS1g2KuqGD2Ws9lqGJvZMdKfGUOsa5kog34VTcN+EPfNYISoez0wZ16mp7Z8+aUundd0UJuI59fDDgpOLYF0wnkmZbec3MYHrk58gdh+vYF0d7KPIGPVKWmU4D2urYnwin136c6AjAOBAkhO8JGrskrVZ2KxCmNEkrW8tr9XQ4SantliA0GDIOK/t71Wp1yrPCOw0CFw3OHSlA+7DUmOr0qNFC891+cCqtaGd8wI/tqanbBA1qtDCK07Q+fJezZTRvarlXPDp/Ik8oRSe7jvxjMwhZJQ+Rq+wLW2kliyboQAZcNPApWi8gHdAQ2aukTfv6ZHl2ZBxQ8jmHJoHGnas9Rc0ru3rkPrl5Kw+MD0QTnSaIZ7RVQx99DDf7R73qY5BfjjrrQ/lGq1PUotFOK7Xg3+8GE8wGAm5Czo6subkuQw4LdOg1nVdLz4K9aIJ/g3nVn6cCQYSkFfJLxFYv3R3LstFKJhCC3ehPAMlLCpdhgZ1mQJQEnN5qt34qEIaYZq0to20c+Q9vQn67uWHLtv/2KvQPbDg80hEQUZ+0AWDuNa/q6lZa8ZSM9m5tQVC6tLXAaEI3Yq0JHa28gbRCFkCTf+w9SXWKY2yrlZRdLPKp2gT8qa0JMysIAvbEfev2dZVN4UQh33VYS1OPE4Eu9nHqZmv7Ye9Gzh7wn+FhFHBnXGHqd9MBYRKd3CRPJI9pWHhjLEgAol6dAv8aKDhWcLZMN/QhdpzJM3TvBAhKkEycrrJXNWslAQgKD2qxvdPvbtkyvculZtIMAcjjh6vGjwitvROusVvJQiYdY8psRfOuff9/T15+hUcbNtcAAAAASUVORK5CYII="/>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 207 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 211 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 240 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 215 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 167 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 194 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 210 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 207 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 202 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 237 KiB

+172
View File
@@ -0,0 +1,172 @@
### chatchat 容器化部署指引
> 提示: 此指引为在 Linux 环境下编写完成, 其他环境下暂未测试, 理论上可行.
>
> Langchain-Chatchat docker 镜像已支持多架构, 欢迎大家自行测试.
#### 一. Langchain-Chatchat 体验部署
##### 1. 安装 docker-compose
寻找适合你环境的 docker-compose 版本, 请参考 [Docker-Compose](https://github.com/docker/compose).
举例: Linux X86 环境 可下载 [docker-compose-linux-x86_64](https://github.com/docker/compose/releases/download/v2.27.3/docker-compose-linux-x86_64) 使用.
```shell
cd ~
wget https://github.com/docker/compose/releases/download/v2.27.3/docker-compose-linux-x86_64
mv docker-compose-linux-x86_64 /usr/bin/docker-compose
which docker-compose
```
/usr/bin/docker-compose
```shell
docker-compose -v
```
Docker Compose version v2.27.3
##### 2. 安装 NVIDIA Container Toolkit
寻找适合你环境的 NVIDIA Container Toolkit 版本, 请参考: [Installing the NVIDIA Container Toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html).
安装完成后记得按照刚刚文档中`Configuring Docker`章节对 docker 进行初始化.
##### 3. 创建 xinference 数据缓存路径
这一步强烈建议, 因为可以将 xinference 缓存的模型都保存到本地, 长期使用.
```shell
mkdir -p ~/xinference
```
##### 4. 下载 chatchat & xinference 启动配置文件(docker-compose.yaml)
```shell
cd ~
wget https://github.com/chatchat-space/Langchain-Chatchat/blob/master/docker/docker-compose.yaml
```
##### 5. 启动 chatchat & xinference 服务
```shell
docker-compose up -d
```
出现如下日志即为成功 ( 第一次启动需要下载 docker 镜像, 时间较长, 这里已经提前下载好了 )
```text
WARN[0000] /root/docker-compose.yaml: `version` is obsolete
[+] Running 2/2
✔ Container root-chatchat-1 Started 0.2s
✔ Container root-xinference-1 Started 0.3s
```
##### 6.检查服务启动情况
```shell
docker-compose up -d
```
```text
WARN[0000] /root/docker-compose.yaml: `version` is obsolete
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
root-chatchat-1 chatimage/chatchat:0.3.1.2-2024-0720 "chatchat -a" chatchat 3 minutes ago Up 3 minutes
root-xinference-1 xprobe/xinference:v0.12.1 "/opt/nvidia/nvidia_…" xinference 3 minutes ago Up 3 minutes
```
```shell
ss -anptl | grep -E '(8501|7861|9997)'
```
```text
LISTEN 0 128 0.0.0.0:9997 0.0.0.0:* users:(("pt_main_thread",pid=1489804,fd=21))
LISTEN 0 128 0.0.0.0:8501 0.0.0.0:* users:(("python",pid=1490078,fd=10))
LISTEN 0 128 0.0.0.0:7861 0.0.0.0:* users:(("python",pid=1490014,fd=9))
```
如上, 服务均已正常启动, 即可体验使用.
> 提示: 先登陆 xinference ui `http://<your_ip>:9997` 启动 llm 和 embedding 后, 再登陆 chatchat ui `http://<your_ip>:8501` 进行体验.
>
> 详细文档:
> - Langchain-chatchat 使用请参考: [LangChain-Chatchat](/README.md)
>
> - Xinference 使用请参考: [欢迎来到 Xinference](https://inference.readthedocs.io/zh-cn/latest/index.html)
#### 二. Langchain-Chatchat 进阶部署
##### 1. 按照 `Langchain-Chatchat 体验部署` 内容顺序依次完成
##### 2. 创建 chatchat 数据缓存路径
```shell
cd ~
mkdir -p ~/chatchat
```
##### 3. 修改 `docker-compose.yaml` 文件内容
原文件内容:
```yaml
(上文 ...)
chatchat:
image: chatimage/chatchat:0.3.1.2-2024-0720
(省略 ...)
# 将本地路径(~/chatchat/data)挂载到容器默认数据路径(/usr/local/lib/python3.11/site-packages/chatchat/data)中
# volumes:
# - ~/chatchat/data:/usr/local/lib/python3.11/site-packages/chatchat/data
(下文 ...)
```
`volumes` 字段注释打开, 并按照 `YAML` 格式对齐, 如下:
```yaml
(上文 ...)
chatchat:
image: chatimage/chatchat:0.3.1.2-2024-0720
(省略 ...)
# 将本地路径(~/chatchat/data)挂载到容器默认数据路径(/usr/local/lib/python3.11/site-packages/chatchat/data)中
volumes:
- ~/chatchat/data:/usr/local/lib/python3.11/site-packages/chatchat/data
(下文 ...)
```
##### 4. 下载数据库初始文件
> 提示: 这里的 `data.tar.gz` 文件仅包含初始化后的数据库 `samples` 文件一份及相应目录结构, 用户可将原先数据和目录结构迁移此处.
> > [!WARNING] 请您先备份好您的数据再进行迁移!!!
```shell
cd ~/chatchat
wget https://github.com/chatchat-space/Langchain-Chatchat/blob/master/docker/data.tar.gz
tar -xvf data.tar.gz
```
```shell
cd data
pwd
```
/root/chatchat/data
```shell
ls -l
```
```text
total 20
drwxr-xr-x 3 root root 4096 Jun 22 10:46 knowledge_base
drwxr-xr-x 18 root root 4096 Jun 22 10:52 logs
drwxr-xr-x 5 root root 4096 Jun 22 10:46 media
drwxr-xr-x 5 root root 4096 Jun 22 10:46 nltk_data
drwxr-xr-x 3 root root 4096 Jun 22 10:46 temp
```
##### 6. 重启 chatchat 服务
这一步需要到 `docker-compose.yaml` 文件所在路径下执行, 即:
```shell
cd ~
docker-compose down chatchat
docker-compose up -d chatchat
```
操作及检查结果如下:
```text
[root@VM-2-15-centos ~]# docker-compose down chatchat
WARN[0000] /root/docker-compose.yaml: `version` is obsolete
[+] Running 1/1
✔ Container root-chatchat-1 Removed 0.5s
[root@VM-2-15-centos ~]# docker-compose up -d
WARN[0000] /root/docker-compose.yaml: `version` is obsolete
[+] Running 2/2
✔ Container root-xinference-1 Running 0.0s
✔ Container root-chatchat-1 Started 0.2s
[root@VM-2-15-centos ~]# docker-compose ps
WARN[0000] /root/docker-compose.yaml: `version` is obsolete
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
root-chatchat-1 chatimage/chatchat:0.3.1.2-2024-0720 "chatchat -a" chatchat 33 seconds ago Up 32 seconds
root-xinference-1 xprobe/xinference:v0.12.1 "/opt/nvidia/nvidia_…" xinference 45 minutes ago Up 45 minutes
[root@VM-2-15-centos ~]# ss -anptl | grep -E '(8501|7861|9997)'
LISTEN 0 128 0.0.0.0:9997 0.0.0.0:* users:(("pt_main_thread",pid=1489804,fd=21))
LISTEN 0 128 0.0.0.0:8501 0.0.0.0:* users:(("python",pid=1515944,fd=10))
LISTEN 0 128 0.0.0.0:7861 0.0.0.0:* users:(("python",pid=1515878,fd=9))
```
+69
View File
@@ -0,0 +1,69 @@
### chatchat 数据库对话配置说明
#### 一、使用建议
> 1. 因大模型生成的sql可能与预期有偏差,请务必在测试环境中进行充分测试、评估;
> 2. 生产环境中,对于查询操作,由于不确定查询效率,推荐数据库采用主从数据库架构,让text2sql连接从数据库,防止可能的慢查询影响主业务;
> 3. 对于写操作应保持谨慎,如不需要写操作,设置read_only为True,最好再从数据库层面收回数据库用户的写权限,防止用户通过自然语言对数据库进行修改操作;
> 4. text2sql与大模型在意图理解、sql转换等方面的能力有关,可切换不同大模型进行测试;
> 5. 数据库表名、字段名应与其实际作用保持一致、容易理解,且应对数据库表名、字段进行详细的备注说明,帮助大模型更好理解数据库结构;
> 6. 若现有数据库表名难于让大模型理解,可配置table_comments字段,补充说明某些表的作用。
#### 二、配置说明
##### 1. 配置节点
初始化后,在tool_settings.yaml文件中,找到text2sql配置节点:
```yaml
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: {}
```
##### 2. 主要参数解释
1. **model_name**
该工具需单独指定使用的大模型,与用户前端选择使用的模型无关
2. **sqlalchemy_connect_str**
SQLAlchemy连接字符串,支持的数据库有:crate、duckdb、googlesql、mssql、mysql、mariadb、oracle、postgresql、sqlite、clickhouse、prestodb
不同的数据库请查阅SQLAlchemy用法,修改sqlalchemy_connect_str,配置对应的数据库连接,如sqlite为sqlite:///数据库文件路径
如提示缺少对应数据库的驱动,请自行通过poetry安装
3. **read_only**
设置为true会开启只读模式。但我们仍然强烈推荐优先从数据库层面对用户权限进行限制
4. **top_k**
限定返回的行数
5. **table_names**
如果不指定table_names,会先使用SQLDatabaseSequentialChain,这个链会先预测需要哪些表,然后再将相关表输入SQLDatabaseChain,这是因为如果不指定table_names,直接使用SQLDatabaseChainLangchain会将全量表结构传递给大模型,可能会因token太长从而引发错误,也浪费资源,但如果表很多,SQLDatabaseSequentialChain也会使用很多token
如果指定了table_names,直接使用SQLDatabaseChain,将特定表结构传递给大模型进行判断,可节约一定资源。
使用特定表的示例如下:
```yaml
table_names: ["sys_user","sys_dept"]
```
6. **table_comments**
如果出现大模型选错表的情况,可尝试根据实际情况额外声明表名和对应的说明,例如:
```yaml
table_comments: {"tableA":"这是一个用户表,存储了用户的基本信息","tanleB":"角色表"}
```
+170
View File
@@ -0,0 +1,170 @@
#### xinference环境配置手册
- 初始化conda
```shell
$ wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
$ rm -rf ~/miniconda3/
$ bash Miniconda3-latest-Linux-x86_64.sh
$ conda config --remove channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
$ conda config --remove channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
$ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
$ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
```
- 创建chatchat环境
```shell
$ conda create -p ~/miniconda3/envs/chatchat python=3.8
$ conda activate ~/miniconda3/envs/chatchat
$ pip install langchain-chatchat -U
$ pip install xinference_client faiss-gpu "unstructured[pdf]"
```
- 创建xinference环境
```shell
$ conda create -p ~/miniconda3/envs/xinference python=3.8
$ conda activate ~/miniconda3/envs/xinference
$ pip install xinference --force
$ pip install tiktoken sentence-transformers
```
- 启动xinference服务
```shell
$ conda activate ~/miniconda3/envs/xinference
$ xinference-local
```
- 编辑注册模型脚本
```shell
$ vim model_registrations.sh
# 添加以下内容。模型路径需要根据实际情况修改
curl 'http://127.0.0.1:9997/v1/model_registrations/LLM' \
-H 'Accept: */*' \
-H 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8' \
-H 'Connection: keep-alive' \
-H 'Content-Type: application/json' \
-H 'Cookie: token=no_auth' \
-H 'Origin: http://127.0.0.1:9997' \
-H 'Referer: http://127.0.0.1:9997/ui/' \
-H 'Sec-Fetch-Dest: empty' \
-H 'Sec-Fetch-Mode: cors' \
-H 'Sec-Fetch-Site: same-origin' \
-H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36' \
-H 'sec-ch-ua: "Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99"' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'sec-ch-ua-platform: "Linux"' \
--data-raw '{"model":"{\"version\":1,\"model_name\":\"autodl-tmp-glm-4-9b-chat\",\"model_description\":\"autodl-tmp-glm-4-9b-chat\",\"context_length\":2048,\"model_lang\":[\"en\",\"zh\"],\"model_ability\":[\"generate\",\"chat\"],\"model_family\":\"glm4-chat\",\"model_specs\":[{\"model_uri\":\"/root/autodl-tmp/glm-4-9b-chat\",\"model_size_in_billions\":9,\"model_format\":\"pytorch\",\"quantizations\":[\"none\"]}],\"prompt_style\":{\"style_name\":\"CHATGLM3\",\"system_prompt\":\"\",\"roles\":[\"user\",\"assistant\"],\"intra_message_sep\":\"\",\"inter_message_sep\":\"\",\"stop\":[\"<|endoftext|>\",\"<|user|>\",\"<|observation|>\"],\"stop_token_ids\":[151329,151336,151338]}}","persist":true}'
```
- 编辑注册embedding脚本
```shell
$ vim model_registrations_emb.sh
# 添加以下内容。模型路径需要根据实际情况修改
curl 'http://127.0.0.1:9997/v1/model_registrations/embedding' \
-H 'Accept: */*' \
-H 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8' \
-H 'Connection: keep-alive' \
-H 'Content-Type: application/json' \
-H 'Cookie: token=no_auth' \
-H 'Origin: http://127.0.0.1:9997' \
-H 'Referer: http://127.0.0.1:9997/ui/' \
-H 'Sec-Fetch-Dest: empty' \
-H 'Sec-Fetch-Mode: cors' \
-H 'Sec-Fetch-Site: same-origin' \
-H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36' \
-H 'sec-ch-ua: "Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99"' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'sec-ch-ua-platform: "Linux"' \
--data-raw '{"model":"{\"model_name\":\"autodl-tmp-bge-large-zh\",\"dimensions\":768,\"max_tokens\":512,\"model_uri\":\"/root/model/bge-large-zh\",\"language\":[\"en\",\"zh\"]}","persist":true}'
```
- 编辑启动模型脚本
```shell
$ vim start_models.sh
# 添加以下内容。模型路径需要根据实际情况修改
curl 'http://127.0.0.1:9997/v1/models' \
-H 'Accept: */*' \
-H 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8' \
-H 'Connection: keep-alive' \
-H 'Content-Type: application/json' \
-H 'Cookie: token=no_auth' \
-H 'Origin: http://127.0.0.1:9997' \
-H 'Referer: http://127.0.0.1:9997/ui/' \
-H 'Sec-Fetch-Dest: empty' \
-H 'Sec-Fetch-Mode: cors' \
-H 'Sec-Fetch-Site: same-origin' \
-H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36' \
-H 'sec-ch-ua: "Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99"' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'sec-ch-ua-platform: "Linux"' \
--data-raw '{"model_uid":null,"model_name":"autodl-tmp-glm-4-9b-chat","model_type":"LLM","model_engine":"Transformers","model_format":"pytorch","model_size_in_billions":9,"quantization":"none","n_gpu":"auto","replica":1,"request_limits":null,"worker_ip":null,"gpu_idx":null}'
```
- 编辑启动embedding脚本
```shell
$ vim start_models_emb.sh
# 添加以下内容。模型路径需要根据实际情况修改
curl 'http://127.0.0.1:9997/v1/models' \
-H 'Accept: */*' \
-H 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8' \
-H 'Connection: keep-alive' \
-H 'Content-Type: application/json' \
-H 'Cookie: token=no_auth' \
-H 'Origin: http://127.0.0.1:9997' \
-H 'Referer: http://127.0.0.1:9997/ui/' \
-H 'Sec-Fetch-Dest: empty' \
-H 'Sec-Fetch-Mode: cors' \
-H 'Sec-Fetch-Site: same-origin' \
-H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36' \
-H 'sec-ch-ua: "Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99"' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'sec-ch-ua-platform: "Linux"' \
--data-raw '{"model_uid":"bge-large-zh-v1.5","model_name":"autodl-tmp-bge-large-zh","model_type":"embedding","replica":1,"n_gpu":"auto","worker_ip":null,"gpu_idx":null}'
```
- 启动模型
```shell
$ bash ./model_registrations.sh
$ bash ./model_registrations_emb.sh
$ bash ./start_models.sh
$ bash ./start_models_emb.sh
```
- 初始化chatchat配置
```shell
$ conda activate ~/miniconda3/envs/chatchat
$ chatchat-config basic --verbose true
$ chatchat-config basic --data ~/chatchat-data
```
- 设置模型
```shell
$ chatchat-config model --set_model_platforms "[{
\"platform_name\": \"xinference\",
\"platform_type\": \"xinference\",
\"api_base_url\": \"http://127.0.0.1:9997/v1\",
\"api_key\": \"EMPT\",
\"api_concurrencies\": 5,
\"llm_models\": [
\"autodl-tmp-glm-4-9b-chat\"
],
\"embed_models\": [
\"bge-large-zh-v1.5\"
],
\"image_models\": [],
\"reranking_models\": [],
\"speech2text_models\": [],
\"tts_models\": []
}]"
```
- 初始化知识库
```shell
$ conda activate ~/miniconda3/envs/chatchat
$ chatchat-kb -r
```
- 启动chatchat
```shell
$ conda activate ~/miniconda3/envs/chatchat
$ chatchat -a
```
+188
View File
@@ -0,0 +1,188 @@
#### xinference Installation Guide
- init conda
```shell
$ wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
$ rm -rf ~/miniconda3/
$ bash Miniconda3-latest-Linux-x86_64.sh
$ conda config --remove channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
$ conda config --remove channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
$ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
$ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
```
- Create chatchat environment
```shell
$ conda create -p ~/miniconda3/envs/chatchat python=3.8
$ conda activate ~/miniconda3/envs/chatchat
$ pip install langchain-chatchat -U
$ pip install xinference_client faiss-gpu "unstructured[pdf]"
```
- Create xinference environment
```shell
$ conda create -p ~/miniconda3/envs/xinference python=3.8
$ conda activate ~/miniconda3/envs/xinference
$ pip install xinference --force
$ pip install tiktoken sentence-transformers
```
- Start the xinference service
```shell
$ conda activate ~/miniconda3/envs/xinference
$ xinference-local
```
- Edit the registration model script
```shell
$ vim model_registrations.sh
# Add the following content. The model path needs to be modified according to the actual situation
curl 'http://127.0.0.1:9997/v1/model_registrations/LLM' \
-H 'Accept: */*' \
-H 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8' \
-H 'Connection: keep-alive' \
-H 'Content-Type: application/json' \
-H 'Cookie: token=no_auth' \
-H 'Origin: http://127.0.0.1:9997' \
-H 'Referer: http://127.0.0.1:9997/ui/' \
-H 'Sec-Fetch-Dest: empty' \
-H 'Sec-Fetch-Mode: cors' \
-H 'Sec-Fetch-Site: same-origin' \
-H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36' \
-H 'sec-ch-ua: "Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99"' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'sec-ch-ua-platform: "Linux"' \
--data-raw '{"model":"{\"version\":1,\"model_name\":\"autodl-tmp-glm-4-9b-chat\",\"model_description\":\"autodl-tmp-glm-4-9b-chat\",\"context_length\":2048,\"model_lang\":[\"en\",\"zh\"],\"model_ability\":[\"generate\",\"chat\"],\"model_family\":\"glm4-chat\",\"model_specs\":[{\"model_uri\":\"/root/autodl-tmp/glm-4-9b-chat\",\"model_size_in_billions\":9,\"model_format\":\"pytorch\",\"quantizations\":[\"none\"]}],\"prompt_style\":{\"style_name\":\"CHATGLM3\",\"system_prompt\":\"\",\"roles\":[\"user\",\"assistant\"],\"intra_message_sep\":\"\",\"inter_message_sep\":\"\",\"stop\":[\"<|endoftext|>\",\"<|user|>\",\"<|observation|>\"],\"stop_token_ids\":[151329,151336,151338]}}","persist":true}'
```
- Edit and register embedding script
```shell
$ vim model_registrations_emb.sh
# 添加以下内容。模型路径需要根据实际情况修改
curl 'http://127.0.0.1:9997/v1/model_registrations/embedding' \
-H 'Accept: */*' \
-H 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8' \
-H 'Connection: keep-alive' \
-H 'Content-Type: application/json' \
-H 'Cookie: token=no_auth' \
-H 'Origin: http://127.0.0.1:9997' \
-H 'Referer: http://127.0.0.1:9997/ui/' \
-H 'Sec-Fetch-Dest: empty' \
-H 'Sec-Fetch-Mode: cors' \
-H 'Sec-Fetch-Site: same-origin' \
-H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36' \
-H 'sec-ch-ua: "Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99"' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'sec-ch-ua-platform: "Linux"' \
--data-raw '{"model":"{\"model_name\":\"autodl-tmp-bge-large-zh\",\"dimensions\":768,\"max_tokens\":512,\"model_uri\":\"/root/model/bge-large-zh\",\"language\":[\"en\",\"zh\"]}","persist":true}'
```
- Edit the startup model script
```shell
$ vim start_models.sh
# 添加以下内容。模型路径需要根据实际情况修改
curl 'http://127.0.0.1:9997/v1/models' \
-H 'Accept: */*' \
-H 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8' \
-H 'Connection: keep-alive' \
-H 'Content-Type: application/json' \
-H 'Cookie: token=no_auth' \
-H 'Origin: http://127.0.0.1:9997' \
-H 'Referer: http://127.0.0.1:9997/ui/' \
-H 'Sec-Fetch-Dest: empty' \
-H 'Sec-Fetch-Mode: cors' \
-H 'Sec-Fetch-Site: same-origin' \
-H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36' \
-H 'sec-ch-ua: "Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99"' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'sec-ch-ua-platform: "Linux"' \
--data-raw '{"model_uid":null,"model_name":"autodl-tmp-glm-4-9b-chat","model_type":"LLM","model_engine":"Transformers","model_format":"pytorch","model_size_in_billions":9,"quantization":"none","n_gpu":"auto","replica":1,"request_limits":null,"worker_ip":null,"gpu_idx":null}'
```
- Edit and start embedding script
```shell
$ vim start_models_emb.sh
# 添加以下内容。模型路径需要根据实际情况修改
curl 'http://127.0.0.1:9997/v1/models' \
-H 'Accept: */*' \
-H 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8' \
-H 'Connection: keep-alive' \
-H 'Content-Type: application/json' \
-H 'Cookie: token=no_auth' \
-H 'Origin: http://127.0.0.1:9997' \
-H 'Referer: http://127.0.0.1:9997/ui/' \
-H 'Sec-Fetch-Dest: empty' \
-H 'Sec-Fetch-Mode: cors' \
-H 'Sec-Fetch-Site: same-origin' \
-H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36' \
-H 'sec-ch-ua: "Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99"' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'sec-ch-ua-platform: "Linux"' \
--data-raw '{"model_uid":"bge-large-zh-v1.5","model_name":"autodl-tmp-bge-large-zh","model_type":"embedding","replica":1,"n_gpu":"auto","worker_ip":null,"gpu_idx":null}'
```
- Start the model
```shell
$ bash ./model_registrations.sh
$ bash ./model_registrations_emb.sh
$ bash ./start_models.sh
$ bash ./start_models_emb.sh
```
- Initialize chatchat configuration
```shell
$ conda activate ~/miniconda3/envs/chatchat
$ chatchat-config basic --verbose true
$ chatchat-config basic --data ~/chatchat-data
```
- Set up the model
```shell
$ chatchat-config model --set_model_platforms "[{
\"platform_name\": \"xinference\",
\"platform_type\": \"xinference\",
\"api_base_url\": \"http://127.0.0.1:9997/v1\",
\"api_key\": \"EMPT\",
\"api_concurrencies\": 5,
\"llm_models\": [
\"autodl-tmp-glm-4-9b-chat\"
],
\"embed_models\": [
\"bge-large-zh-v1.5\"
],
\"image_models\": [],
\"reranking_models\": [],
\"speech2text_models\": [],
\"tts_models\": []
}]"
```
- Initialize knowledge base
```shell
$ conda activate ~/miniconda3/envs/chatchat
$ chatchat-kb -r
```
- Start chatchat
```shell
$ conda activate ~/miniconda3/envs/chatchat
$ chatchat -a
```
+85
View File
@@ -0,0 +1,85 @@
.PHONY: all format lint test tests test_watch integration_tests docker_tests help extended_tests
# Default target executed when no arguments are given to make.
all: help
######################
# TESTING AND COVERAGE
######################
# Define a variable for the test file path.
TEST_FILE ?= tests/unit_tests/
# Run unit tests and generate a coverage report.
coverage:
poetry run pytest --cov \
--cov-config=.coveragerc \
--cov-report xml \
--cov-report term-missing:skip-covered \
$(TEST_FILE)
test tests:
poetry run pytest --disable-socket --allow-unix-socket $(TEST_FILE)
extended_tests:
poetry run pytest --disable-socket --allow-unix-socket --only-extended tests/unit_tests
test_watch:
poetry run ptw --snapshot-update --now . -- -x --disable-socket --allow-unix-socket tests/unit_tests
test_watch_extended:
poetry run ptw --snapshot-update --now . -- -x --disable-socket --allow-unix-socket --only-extended tests/unit_tests
integration_tests:
poetry run pytest tests/integration_tests
scheduled_tests:
poetry run pytest -m scheduled tests/integration_tests
######################
# LINTING AND FORMATTING
######################
# Define a variable for Python and notebook files.
PYTHON_FILES=.
MYPY_CACHE=.mypy_cache
lint format: PYTHON_FILES=.
lint_diff format_diff: PYTHON_FILES=$(shell git diff --relative=libs/langchain --name-only --diff-filter=d master | grep -E '\.py$$|\.ipynb$$')
lint_package: PYTHON_FILES=chatchat
lint_tests: PYTHON_FILES=tests
lint_tests: MYPY_CACHE=.mypy_cache_test
lint lint_diff lint_package lint_tests:
./scripts/check_pydantic.sh .
./scripts/lint_imports.sh
poetry run ruff .
[ "$(PYTHON_FILES)" = "" ] || poetry run ruff format $(PYTHON_FILES) --diff
[ "$(PYTHON_FILES)" = "" ] || poetry run ruff --select I $(PYTHON_FILES)
[ "$(PYTHON_FILES)" = "" ] || mkdir -p $(MYPY_CACHE) && poetry run mypy $(PYTHON_FILES) --cache-dir $(MYPY_CACHE)
format format_diff:
[ "$(PYTHON_FILES)" = "" ] || poetry run ruff format $(PYTHON_FILES)
[ "$(PYTHON_FILES)" = "" ] || poetry run ruff --select I --fix $(PYTHON_FILES)
spell_check:
poetry run codespell --toml pyproject.toml
spell_fix:
poetry run codespell --toml pyproject.toml -w
######################
# HELP
######################
help:
@echo '-- LINTING --'
@echo 'format - run code formatters'
@echo 'lint - run linters'
@echo 'spell_check - run codespell on the project'
@echo 'spell_fix - run codespell on the project and fix the errors'
@echo '-- TESTS --'
@echo 'coverage - run unit tests and generate coverage report'
@echo 'test - run unit tests'
@echo 'tests - run unit tests (alias for "make test")'
@echo 'test TEST_FILE=<test_file> - run all tests in file'
+163
View File
@@ -0,0 +1,163 @@
### 项目简介
![](https://github.com/chatchat-space/Langchain-Chatchat/blob/master/docs/img/logo-long-chatchat-trans-v2.png)
[![pypi badge](https://img.shields.io/pypi/v/langchain-chatchat.svg)](https://shields.io/)
[![Generic badge](https://img.shields.io/badge/python-3.8%7C3.9%7C3.10%7C3.11-blue.svg)](https://pypi.org/project/pypiserver/)
🌍 [READ THIS IN ENGLISH](README_en.md)
📃 **LangChain-Chatchat** (原 Langchain-ChatGLM)
基于 ChatGLM 等大语言模型与 Langchain 等应用框架实现,开源、可离线部署的 RAG 与 Agent 应用项目。
点击[这里](https://github.com/chatchat-space/Langchain-Chatchat)了解项目详情。
### 安装
1. PYPI 安装
```shell
pip install langchain-chatchat
# or if you use xinference to provide model API:
# pip install langchain-chatchat[xinference]
# if you update from an old version, we suggest to run init again to update yaml templates:
# pip install -U langchain-chatchat
# chatchat init
```
详见这里的[安装指引](https://github.com/chatchat-space/Langchain-Chatchat/tree/master?tab=readme-ov-file#%E5%BF%AB%E9%80%9F%E4%B8%8A%E6%89%8B)。
> 注意:chatchat请放在独立的虚拟环境中,比如condavenvvirtualenv等
>
> 已知问题,不能跟xinference一起安装,会让一些插件出bug,例如文件无法上传
2. 源码安装
除了通过pypi安装外,您也可以选择使用[源码启动](https://github.com/chatchat-space/Langchain-Chatchat/blob/master/docs/contributing/README_dev.md)。(Tips:
源码配置可以帮助我们更快的寻找bug,或者改进基础设施。我们不建议新手使用这个方式)
3. Docker
```shell
docker pull chatimage/chatchat:0.3.1.2-2024-0720
docker pull ccr.ccs.tencentyun.com/chatchat/chatchat:0.3.1.2-2024-0720 # 国内镜像
```
> [!important]
> 强烈建议: 使用 docker-compose 部署, 具体参考 [README_docker](https://github.com/chatchat-space/Langchain-Chatchat/blob/master/docs/install/README_docker.md)
4. AudoDL
🌐 [AutoDL 镜像](https://www.codewithgpu.com/i/chatchat-space/Langchain-Chatchat/Langchain-Chatchat) 中 `0.3.1`
版本所使用代码已更新至本项目 `v0.3.1` 版本。
### 初始化与配置
项目运行需要特定的数据目录和配置文件,执行下列命令可以生成默认配置(您可以随时修改 yaml 配置文件):
```shell
# set the root path where storing data.
# will use current directory if not set
export CHATCHAT_ROOT=/path/to/chatchat_data
# initialize data and yaml configuration templates
chatchat init
```
`CHATCHAT_ROOT` 或当前目录可以找到 `*_settings.yaml` 文件,修改这些文件选择合适的模型配置,详见[初始化](https://github.com/chatchat-space/Langchain-Chatchat/tree/master?tab=readme-ov-file#3-%E5%88%9D%E5%A7%8B%E5%8C%96%E9%A1%B9%E7%9B%AE%E9%85%8D%E7%BD%AE%E4%B8%8E%E6%95%B0%E6%8D%AE%E7%9B%AE%E5%BD%95)
### 启动服务
确保所有配置正确后(特别是 LLM 和 Embedding Model),执行下列命令创建默认知识库、启动服务:
```shell
chatchat kb -r
chatchat start -a
```
如无错误将自动弹出浏览器页面。
更多命令可以通过 `chatchat --help` 查看。
### 更新日志:
#### 0.3.1.3 (2024-07-23)
- 修复:
- 修复 nltk_data 未能在项目初始化时复制的问题
- 在项目依赖包中增加 python-docx 以满足知识库初始化时 docx 格式文件处理需求
#### 0.3.1.2 (2024-07-20)
- 新功能:
- Model Platform 支持配置代理 by @liunux4odoo (#4492)
- 给定一个默认可用的 searx 服务器 by @liunux4odoo (#4504)
- 更新 docker 镜像 by @yuehua-s @imClumsyPanda (#4511)
- 新增URL内容阅读器:通过jina-ai/reader项目,将url内容处理为llm易于理解的文本形式 by @ganwumeng @imClumsyPanda (#4547)
- 优化qwen模型下对tools的json修复成功率 by @ganwumeng (#4554)
- 允许用户在 basic_settings.API_SERVER 中配置 public_host,public_port,以便使用云服务器或反向代理时生成正确的公网 API
地址 by @liunux4odoo (#4567)
- 添加模型和服务自动化脚本 by @glide-the (#4573)
- 添加单元测试 by @glide-the (#4573)
- 修复:
- WEBUI 中设置 System message 无效 by @liunux4odoo (#4491)
- 移除无效的 vqa_processor & aqa_processor 工具 by @liunux4odoo (#4498)
- KeyError of 'template' 错误 by @liunux4odoo (#4501)
- 执行 chatchat init 时 nltk_data 目录设置错误 by @liunux4odoo (#4523)
- 执行 chatchat init 时 出现 xinference-client 连接错误 by @imClumsyPanda (#4573)
- xinference 自动检测模型使用缓存,提高 UI 响应速度 by @liunux4odoo (#4510)
- chatchat.log 中重复记录 by @liunux4odoo (#4517)
- 优化错误信息的传递和前端显示 by @liunux4odoo (#4531)
- 修正 openai.chat.completions.create 参数构造方式,提高兼容性 by @liunux4odoo (#4540)
- Milvus retriever NotImplementedError by @kwunhang (#4536)
- Fix bug of ChromaDB Collection as retriever by @kwunhang (#4541)
- langchain 版本升级后,DocumentWithVsId 出现 id 重复问题 by @liunux4odoo (#4548)
- 重建知识库时只处理了一个知识库 by @liunux4odoo (#4549)
- chat api error because openapi set max_tokens to 0 by default by @liunux4odoo (#4564)
#### 0.3.1.1 (2024-07-15)
- 修复:
- WEBUI 中设置 system message 无效([#4491](https://github.com/chatchat-space/Langchain-Chatchat/pull/4491))
- 模型平台不支持代理([#4492](https://github.com/chatchat-space/Langchain-Chatchat/pull/4492))
- 移除失效的 vqa_processor & aqa_processor 工具([#4498](https://github.com/chatchat-space/Langchain-Chatchat/pull/4498))
- prompt settings 错误导致 `KeyError: 'template'`([#4501](https://github.com/chatchat-space/Langchain-Chatchat/pull/4501))
- searx 搜索引擎不支持中文([#4504](https://github.com/chatchat-space/Langchain-Chatchat/pull/4504))
- init时默认去连 xinference,若默认 xinference 服务不存在会报错([#4508](https://github.com/chatchat-space/Langchain-Chatchat/issues/4508))
- init时,调用shutil.copytree,当src与dst一样时shutil报错的问题([#4507](https://github.com/chatchat-space/Langchain-Chatchat/pull/4507))
### 项目里程碑
+ `2023年4月`: `Langchain-ChatGLM 0.1.0` 发布,支持基于 ChatGLM-6B 模型的本地知识库问答。
+ `2023年8月`: `Langchain-ChatGLM` 改名为 `Langchain-Chatchat`,发布 `0.2.0` 版本,使用 `fastchat` 作为模型加载方案,支持更多的模型和数据库。
+ `2023年10月`: `Langchain-Chatchat 0.2.5` 发布,推出 Agent 内容,开源项目在`Founder Park & Zhipu AI & Zilliz`
举办的黑客马拉松获得三等奖。
+ `2023年12月`: `Langchain-Chatchat` 开源项目获得超过 **20K** stars.
+ `2024年6月`: `Langchain-Chatchat 0.3.0` 发布,带来全新项目架构。
+ 🔥 让我们一起期待未来 Chatchat 的故事 ···
---
### 协议
本项目代码遵循 [Apache-2.0](LICENSE) 协议。
### 联系我们
#### Telegram
[![Telegram](https://img.shields.io/badge/Telegram-2CA5E0?style=for-the-badge&logo=telegram&logoColor=white "langchain-chatchat")](https://t.me/+RjliQ3jnJ1YyN2E9)
### 引用
如果本项目有帮助到您的研究,请引用我们:
```
@software{langchain_chatchat,
title = {{langchain-chatchat}},
author = {Liu, Qian and Song, Jinke, and Huang, Zhiguo, and Zhang, Yuxuan, and glide-the, and Liu, Qingwei},
year = 2024,
journal = {GitHub repository},
publisher = {GitHub},
howpublished = {\url{https://github.com/chatchat-space/Langchain-Chatchat}}
}
```
+107
View File
@@ -0,0 +1,107 @@
### Project Introduction
! []( https://github.com/chatchat-space/Langchain-Chatchat/blob/master/docs/img/logo-long-chatchat-trans-v2.png )
<a href=" https://trendshift.io/repositories/329 " target="_blank"><img src=" https://trendshift.io/api/badge/repositories/329 " alt="chatchat-space%2FLangchain-Chatchat | Trendshift" style="width: 250px; height: 55px; " width="250" height="55"/></a>
[![pypi badge](https://img.shields.io/pypi/v/langchain-chatchat.svg)](https://shields.io/)
[![Generic badge](https://img.shields.io/badge/python-3.8%7C3.9%7C3.10%7C3.11-blue.svg)](https://pypi.org/project/pypiserver/)
🌍 [READ THIS IN CHINESE](README.md)
📃 **LangChain Chatchat** (formerly Langchain ChatGLM)
An open-source and offline deployable RAG and Agent application project based on major language models such as ChatGLM and application frameworks such as Langchain.
Click [here](https://github.com/chatchat-space/Langchain-Chatchatto Understand the project details.
### Installation
1. PYPI installation
```shell
pip install langchain-chatchat
# or if you use xinference to provide model API:
# pip install langchain-chatchat[xinference]
# if you update from an old version, we suggest to run init again to update yaml templates:
# pip install -U langchain-chatchat
# chatchat init
```
Please refer to the [Installation Guide](https://github.com/chatchat-space/Langchain-Chatchat/tree/master?tab=readme-OVfile#%E5%BF%AB%E9%80%9F%E4%B8%8A%E6%89%8B) for details.
>Attention: Chatchat should be placed in a separate virtual environment, such as conda, venv, virtualienv, etc
>Known issue, cannot be installed together with xinference, which may cause some plugins to have bugs, such as file upload issues
2. Source code installation
In addition to installing through Pypi, you can also choose to use [source code startup](https://github.com/chatchat-space/Langchain-Chatchat/blob/master/docs/contributing/README_dev.md).
(Tips: Source code configuration can help us find bugs faster or improve infrastructure. We do not recommend beginners to use this method
3. Docker
```shell
docker pull chatimage/chatchat:0.3.1.2-2024-0720
docker pull ccr.ccs.tencentyun.com/chatchat/chatchat:0.3.1.2-2024-0720 # 国内镜像
```
> [!important]
> Strong recommendation: Use docker compose for deployment, refer to [README.docker](https://github.com/chatchat-space/Langchain-Chatchat/blob/master/docs/install/README_docker.md) for details
1. AudoDL
🌐 [AutoDL Image](https://www.codewithgpu.com/i/chatchat-space/Langchain-Chatchat/Langchain-ChatchatMedium ` 0.3.0`
The code used in the version has been updated to version v0.3.0 of this project.
### Initialization and Configuration
The project requires specific data directories and configuration files for operation. The following commands can generate default configurations (you can modify the YAML configuration file at any time):
```shell
# set the root path where storing data.
# will use current directory if not set
export CHATCHAT_ROOT=/path/to/chatchat_data
# initialize data and yaml configuration templates
chatchat init
```
You can find the `*_ settings.yaml` files in CHATCHAT-ROOT or the current directory. Modify these files to select the appropriate model configuration. See [Initialization](https://github.com/chatchat-space/Langchain-Chatchat/tree/master?tab=readme-ov-file#3-%E5%88%9D%E5%A7%8B%E5%8C%96%E9%A1%B9%E7%9B%AE%E9%85%8D%E7%BD%AE%E4%B8%8E%E6%95%B0%E6%8D%AE%E7%9B%AE%E5%BD%95) for details.
### Start service
After ensuring that all configurations are correct (especially LLM and Embedding Model), execute the following commands to create the default knowledge base and start the service:
```shell
chatchat kb -r
chatchat start -a
```
If there are no errors, the browser page will automatically pop up.
### Update log:
#### 0.3.1.1 (2024-07-15)
- Fix:
- Invalid system message setting in WEBUI ([# 4491](https://github.com/chatchat-space/Langchain-Chatchat/pull/4491 ))
- The model platform does not support proxies ([# 4492](https://github.com/chatchat-space/Langchain-Chatchat/pull/4492 ))
- Remove the invalid vqasprocessor&aqa_processor tools ([# 4498]( https://github.com/chatchat-space/Langchain-Chatchat/pull/4498 ))
- Prompt settings error causing 'KeyError: template' ([# 4501](https://github.com/chatchat-space/Langchain-Chatchat/pull/4501 ))
- Searx search engine does not support Chinese ([# 4504](https://github.com/chatchat-space/Langchain-Chatchat/pull/4504 ))
- When initializing, it defaults to connecting to xinference. If the default xinference service does not exist, an error will be reported ([# 4508]( https://github.com/chatchat-space/Langchain-Chatchat/issues/4508 ))
- When initializing, call shutil.cpytree, and when src is the same as dst, shutil will report an error ([# 4507]( https://github.com/chatchat-space/Langchain-Chatchat/pull/4507 ))
### Project milestones
+ April 2023: Langchain ChatGLM 0.1.0 is released, supporting local knowledge base Q&A based on ChatGLM-6B model.
+ August 2023: Langchain ChatGLM will be renamed as Langchain Chatgate and release version 0.2.0, using fastchat as the model loading solution to support more models and databases.
+ October 2023: Langchain Chatcat 0.2.5 is released, featuring Agent content and an open-source project at Founder Park&Zhipu AI&Zilliz`
The hackathon held won third prize.
+ December 2023: Langchain Chatcat open-source project receives over 20K stars
+ June 2024: Langchain Watchat 0.3.0 is released, bringing a brand new project architecture.
+ 🔥 Let's look forward to the future stories of Chatchat together···
---
### LICENSE
This project code follows the Apache 2.0 (LICENSE) protocol.
### Contact Us
#### Telegram
[![Telegram](https://img.shields.io/badge/Telegram-2CA5E0?style=for-the-badge&logo=telegram&logoColor=white "langchain-chatchat")](https://t.me/+RjliQ3jnJ1YyN2E9)
### Quoting
If this project has been helpful for your research, please cite us:
```
@software{langchain_chatchat,
title = {{langchain-chatchat}},
author = {Liu, Qian and Song, Jinke, and Huang, Zhiguo, and Zhang, Yuxuan, and glide-the, and Liu, Qingwei},
year = 2024,
journal = {GitHub repository},
publisher = {GitHub},
howpublished = {\url{ https://github.com/chatchat-space/Langchain-Chatchat }}
}
```
@@ -0,0 +1 @@
__version__ = "0.3.1.3"
+84
View File
@@ -0,0 +1,84 @@
import click
from pathlib import Path
import shutil
import typing as t
from chatchat.startup import main as startup_main
from chatchat.init_database import main as kb_main, create_tables, folder2db
from chatchat.settings import Settings
from chatchat.utils import build_logger
from chatchat.server.utils import get_default_embedding
logger = build_logger()
@click.group(help="chatchat 命令行工具")
def main():
...
@main.command("init", help="项目初始化")
@click.option("-x", "--xinference-endpoint", "xf_endpoint",
help="指定Xinference API 服务地址。默认为 http://127.0.0.1:9997/v1")
@click.option("-l", "--llm-model",
help="指定默认 LLM 模型。默认为 glm4-chat")
@click.option("-e", "--embed-model",
help="指定默认 Embedding 模型。默认为 bge-large-zh-v1.5")
@click.option("-r", "--recreate-kb",
is_flag=True,
show_default=True,
default=False,
help="同时重建知识库(必须确保指定的 embed model 可用)。")
@click.option("-k", "--kb-names", "kb_names",
show_default=True,
default="samples",
help="要重建知识库的名称。可以指定多个知识库名称,以 , 分隔。")
def init(
xf_endpoint: str = "",
llm_model: str = "",
embed_model: str = "",
recreate_kb: bool = False,
kb_names: str = "",
):
Settings.set_auto_reload(False)
bs = Settings.basic_settings
kb_names = [x.strip() for x in kb_names.split(",")]
logger.success(f"开始初始化项目数据目录:{Settings.CHATCHAT_ROOT}")
Settings.basic_settings.make_dirs()
logger.success("创建所有数据目录:成功。")
if(bs.PACKAGE_ROOT / "data/knowledge_base/samples" != Path(bs.KB_ROOT_PATH) / "samples"):
shutil.copytree(bs.PACKAGE_ROOT / "data/knowledge_base/samples", Path(bs.KB_ROOT_PATH) / "samples", dirs_exist_ok=True)
logger.success("复制 samples 知识库文件:成功。")
create_tables()
logger.success("初始化知识库数据库:成功。")
if xf_endpoint:
Settings.model_settings.MODEL_PLATFORMS[0].api_base_url = xf_endpoint
if llm_model:
Settings.model_settings.DEFAULT_LLM_MODEL = llm_model
if embed_model:
Settings.model_settings.DEFAULT_EMBEDDING_MODEL = embed_model
Settings.createl_all_templates()
Settings.set_auto_reload(True)
logger.success("生成默认配置文件:成功。")
logger.success("请先检查确认 model_settings.yaml 里模型平台、LLM模型和Embed模型信息已经正确")
if recreate_kb:
folder2db(kb_names=kb_names,
mode="recreate_vs",
vs_type=Settings.kb_settings.DEFAULT_VS_TYPE,
embed_model=get_default_embedding())
logger.success("<green>所有初始化已完成,执行 chatchat start -a 启动服务。</green>")
else:
logger.success("执行 chatchat kb -r 初始化知识库,然后 chatchat start -a 启动服务。")
main.add_command(startup_main, "start")
main.add_command(kb_main, "kb")
if __name__ == "__main__":
main()
@@ -0,0 +1,76 @@
The Carnegie Mellon Pronouncing Dictionary [cmudict.0.7a]
ftp://ftp.cs.cmu.edu/project/speech/dict/
https://cmusphinx.svn.sourceforge.net/svnroot/cmusphinx/trunk/cmudict/cmudict.0.7a
Copyright (C) 1993-2008 Carnegie Mellon University. All rights reserved.
File Format: Each line consists of an uppercased word,
a counter (for alternative pronunciations), and a transcription.
Vowels are marked for stress (1=primary, 2=secondary, 0=no stress).
E.g.: NATURAL 1 N AE1 CH ER0 AH0 L
The dictionary contains 127069 entries. Of these, 119400 words are assigned
a unique pronunciation, 6830 words have two pronunciations, and 839 words have
three or more pronunciations. Many of these are fast-speech variants.
Phonemes: There are 39 phonemes, as shown below:
Phoneme Example Translation Phoneme Example Translation
------- ------- ----------- ------- ------- -----------
AA odd AA D AE at AE T
AH hut HH AH T AO ought AO T
AW cow K AW AY hide HH AY D
B be B IY CH cheese CH IY Z
D dee D IY DH thee DH IY
EH Ed EH D ER hurt HH ER T
EY ate EY T F fee F IY
G green G R IY N HH he HH IY
IH it IH T IY eat IY T
JH gee JH IY K key K IY
L lee L IY M me M IY
N knee N IY NG ping P IH NG
OW oat OW T OY toy T OY
P pee P IY R read R IY D
S sea S IY SH she SH IY
T tea T IY TH theta TH EY T AH
UH hood HH UH D UW two T UW
V vee V IY W we W IY
Y yield Y IY L D Z zee Z IY
ZH seizure S IY ZH ER
(For NLTK, entries have been sorted so that, e.g. FIRE 1 and FIRE 2
are contiguous, and not separated by FIRE'S 1.)
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
The contents of this file are deemed to be source code.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
This work was supported in part by funding from the Defense Advanced
Research Projects Agency, the Office of Naval Research and the National
Science Foundation of the United States of America, and by member
companies of the Carnegie Mellon Sphinx Speech Consortium. We acknowledge
the contributions of many volunteers to the expansion and improvement of
this dictionary.
THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,98 @@
Pretrained Punkt Models -- Jan Strunk (New version trained after issues 313 and 514 had been corrected)
Most models were prepared using the test corpora from Kiss and Strunk (2006). Additional models have
been contributed by various people using NLTK for sentence boundary detection.
For information about how to use these models, please confer the tokenization HOWTO:
http://nltk.googlecode.com/svn/trunk/doc/howto/tokenize.html
and chapter 3.8 of the NLTK book:
http://nltk.googlecode.com/svn/trunk/doc/book/ch03.html#sec-segmentation
There are pretrained tokenizers for the following languages:
File Language Source Contents Size of training corpus(in tokens) Model contributed by
=======================================================================================================================================================================
czech.pickle Czech Multilingual Corpus 1 (ECI) Lidove Noviny ~345,000 Jan Strunk / Tibor Kiss
Literarni Noviny
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
danish.pickle Danish Avisdata CD-Rom Ver. 1.1. 1995 Berlingske Tidende ~550,000 Jan Strunk / Tibor Kiss
(Berlingske Avisdata, Copenhagen) Weekend Avisen
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
dutch.pickle Dutch Multilingual Corpus 1 (ECI) De Limburger ~340,000 Jan Strunk / Tibor Kiss
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
english.pickle English Penn Treebank (LDC) Wall Street Journal ~469,000 Jan Strunk / Tibor Kiss
(American)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
estonian.pickle Estonian University of Tartu, Estonia Eesti Ekspress ~359,000 Jan Strunk / Tibor Kiss
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
finnish.pickle Finnish Finnish Parole Corpus, Finnish Books and major national ~364,000 Jan Strunk / Tibor Kiss
Text Bank (Suomen Kielen newspapers
Tekstipankki)
Finnish Center for IT Science
(CSC)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
french.pickle French Multilingual Corpus 1 (ECI) Le Monde ~370,000 Jan Strunk / Tibor Kiss
(European)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
german.pickle German Neue Zürcher Zeitung AG Neue Zürcher Zeitung ~847,000 Jan Strunk / Tibor Kiss
(Switzerland) CD-ROM
(Uses "ss"
instead of "ß")
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
greek.pickle Greek Efstathios Stamatatos To Vima (TO BHMA) ~227,000 Jan Strunk / Tibor Kiss
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
italian.pickle Italian Multilingual Corpus 1 (ECI) La Stampa, Il Mattino ~312,000 Jan Strunk / Tibor Kiss
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
norwegian.pickle Norwegian Centre for Humanities Bergens Tidende ~479,000 Jan Strunk / Tibor Kiss
(Bokmål and Information Technologies,
Nynorsk) Bergen
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
polish.pickle Polish Polish National Corpus Literature, newspapers, etc. ~1,000,000 Krzysztof Langner
(http://www.nkjp.pl/)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
portuguese.pickle Portuguese CETENFolha Corpus Folha de São Paulo ~321,000 Jan Strunk / Tibor Kiss
(Brazilian) (Linguateca)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
slovene.pickle Slovene TRACTOR Delo ~354,000 Jan Strunk / Tibor Kiss
Slovene Academy for Arts
and Sciences
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
spanish.pickle Spanish Multilingual Corpus 1 (ECI) Sur ~353,000 Jan Strunk / Tibor Kiss
(European)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
swedish.pickle Swedish Multilingual Corpus 1 (ECI) Dagens Nyheter ~339,000 Jan Strunk / Tibor Kiss
(and some other texts)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
turkish.pickle Turkish METU Turkish Corpus Milliyet ~333,000 Jan Strunk / Tibor Kiss
(Türkçe Derlem Projesi)
University of Ankara
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
The corpora contained about 400,000 tokens on average and mostly consisted of newspaper text converted to
Unicode using the codecs module.
Kiss, Tibor and Strunk, Jan (2006): Unsupervised Multilingual Sentence Boundary Detection.
Computational Linguistics 32: 485-525.
---- Training Code ----
# import punkt
import nltk.tokenize.punkt
# Make a new Tokenizer
tokenizer = nltk.tokenize.punkt.PunktSentenceTokenizer()
# Read in training corpus (one example: Slovene)
import codecs
text = codecs.open("slovene.plain","Ur","iso-8859-2").read()
# Train tokenizer
tokenizer.train(text)
# Dump pickled tokenizer
import pickle
out = open("slovene.pickle","wb")
pickle.dump(tokenizer, out)
out.close()
---------
@@ -0,0 +1,98 @@
Pretrained Punkt Models -- Jan Strunk (New version trained after issues 313 and 514 had been corrected)
Most models were prepared using the test corpora from Kiss and Strunk (2006). Additional models have
been contributed by various people using NLTK for sentence boundary detection.
For information about how to use these models, please confer the tokenization HOWTO:
http://nltk.googlecode.com/svn/trunk/doc/howto/tokenize.html
and chapter 3.8 of the NLTK book:
http://nltk.googlecode.com/svn/trunk/doc/book/ch03.html#sec-segmentation
There are pretrained tokenizers for the following languages:
File Language Source Contents Size of training corpus(in tokens) Model contributed by
=======================================================================================================================================================================
czech.pickle Czech Multilingual Corpus 1 (ECI) Lidove Noviny ~345,000 Jan Strunk / Tibor Kiss
Literarni Noviny
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
danish.pickle Danish Avisdata CD-Rom Ver. 1.1. 1995 Berlingske Tidende ~550,000 Jan Strunk / Tibor Kiss
(Berlingske Avisdata, Copenhagen) Weekend Avisen
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
dutch.pickle Dutch Multilingual Corpus 1 (ECI) De Limburger ~340,000 Jan Strunk / Tibor Kiss
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
english.pickle English Penn Treebank (LDC) Wall Street Journal ~469,000 Jan Strunk / Tibor Kiss
(American)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
estonian.pickle Estonian University of Tartu, Estonia Eesti Ekspress ~359,000 Jan Strunk / Tibor Kiss
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
finnish.pickle Finnish Finnish Parole Corpus, Finnish Books and major national ~364,000 Jan Strunk / Tibor Kiss
Text Bank (Suomen Kielen newspapers
Tekstipankki)
Finnish Center for IT Science
(CSC)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
french.pickle French Multilingual Corpus 1 (ECI) Le Monde ~370,000 Jan Strunk / Tibor Kiss
(European)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
german.pickle German Neue Zürcher Zeitung AG Neue Zürcher Zeitung ~847,000 Jan Strunk / Tibor Kiss
(Switzerland) CD-ROM
(Uses "ss"
instead of "ß")
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
greek.pickle Greek Efstathios Stamatatos To Vima (TO BHMA) ~227,000 Jan Strunk / Tibor Kiss
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
italian.pickle Italian Multilingual Corpus 1 (ECI) La Stampa, Il Mattino ~312,000 Jan Strunk / Tibor Kiss
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
norwegian.pickle Norwegian Centre for Humanities Bergens Tidende ~479,000 Jan Strunk / Tibor Kiss
(Bokmål and Information Technologies,
Nynorsk) Bergen
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
polish.pickle Polish Polish National Corpus Literature, newspapers, etc. ~1,000,000 Krzysztof Langner
(http://www.nkjp.pl/)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
portuguese.pickle Portuguese CETENFolha Corpus Folha de São Paulo ~321,000 Jan Strunk / Tibor Kiss
(Brazilian) (Linguateca)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
slovene.pickle Slovene TRACTOR Delo ~354,000 Jan Strunk / Tibor Kiss
Slovene Academy for Arts
and Sciences
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
spanish.pickle Spanish Multilingual Corpus 1 (ECI) Sur ~353,000 Jan Strunk / Tibor Kiss
(European)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
swedish.pickle Swedish Multilingual Corpus 1 (ECI) Dagens Nyheter ~339,000 Jan Strunk / Tibor Kiss
(and some other texts)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
turkish.pickle Turkish METU Turkish Corpus Milliyet ~333,000 Jan Strunk / Tibor Kiss
(Türkçe Derlem Projesi)
University of Ankara
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
The corpora contained about 400,000 tokens on average and mostly consisted of newspaper text converted to
Unicode using the codecs module.
Kiss, Tibor and Strunk, Jan (2006): Unsupervised Multilingual Sentence Boundary Detection.
Computational Linguistics 32: 485-525.
---- Training Code ----
# import punkt
import nltk.tokenize.punkt
# Make a new Tokenizer
tokenizer = nltk.tokenize.punkt.PunktSentenceTokenizer()
# Read in training corpus (one example: Slovene)
import codecs
text = codecs.open("slovene.plain","Ur","iso-8859-2").read()
# Train tokenizer
tokenizer.train(text)
# Dump pickled tokenizer
import pickle
out = open("slovene.pickle","wb")
pickle.dump(tokenizer, out)
out.close()
---------
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More