Skip to content

Commit 4993e50

Browse files
authored
Merge pull request #103 from chatchat-space/feature/api
Feature/api
2 parents aa9e634 + 85f9eb5 commit 4993e50

File tree

18 files changed

+513
-827
lines changed

18 files changed

+513
-827
lines changed

.github/workflows/docker-build.yaml

Lines changed: 97 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,112 @@
1-
#name: docker-build
2-
#on:
3-
# push:
1+
name: docker-build
2+
on:
3+
push:
4+
branches:
5+
- master
6+
paths-ignore:
7+
- 'README.md'
8+
- 'README_en.md'
9+
- 'docs/**'
10+
- '.github/actions/**'
11+
- '.github/ISSUE_TEMPLATE/**'
12+
- 'docker/docker-compose.yaml'
13+
# pull_request:
414
# branches:
515
# - master
16+
# types:
17+
# - closed
618
# paths-ignore:
719
# - 'README.md'
820
# - 'README_en.md'
921
# - 'docs/**'
1022
# - '.github/actions/**'
1123
# - '.github/ISSUE_TEMPLATE/**'
1224
# - 'docker/docker-compose.yaml'
13-
## pull_request:
14-
## branches:
15-
## - master
16-
## types:
17-
## - closed
18-
## paths-ignore:
19-
## - 'README.md'
20-
## - 'README_en.md'
21-
## - 'docs/**'
22-
## - '.github/actions/**'
23-
## - '.github/ISSUE_TEMPLATE/**'
24-
## - 'docker/docker-compose.yaml'
25-
#env:
26-
# TZ: Asia/Shanghai
27-
#jobs:
28-
# docker-build:
29-
# runs-on: ubuntu-latest
30-
# steps:
31-
# - name: Optimize Disk Space
32-
# uses: hugoalh/[email protected]
25+
env:
26+
TZ: Asia/Shanghai
27+
jobs:
28+
docker-build:
29+
runs-on: ubuntu-latest
30+
steps:
31+
- name: Optimize Disk Space
32+
uses: hugoalh/[email protected]
33+
with:
34+
operate_sudo: "True"
35+
general_include: ".+"
36+
general_exclude: |-
37+
^GCC$
38+
^G\+\+$
39+
Clang
40+
LLVM
41+
docker_include: ".+"
42+
docker_prune: "True"
43+
docker_clean: "True"
44+
apt_prune: "True"
45+
apt_clean: "True"
46+
homebrew_prune: "True"
47+
homebrew_clean: "True"
48+
npm_prune: "True"
49+
npm_clean: "True"
50+
os_swap: "True"
51+
- name: Remove Unnecessary Tools And Files
52+
env:
53+
DEBIAN_FRONTEND: noninteractive
54+
run: |
55+
sudo apt-get remove -y '^dotnet-.*' '^llvm-.*' 'php.*' azure-cli google-chrome-stable firefox powershell mono-devel
56+
sudo apt-get autoremove --purge -y
57+
sudo find /var/log -name "*.gz" -type f -delete
58+
sudo rm -rf /var/cache/apt/archives
59+
sudo rm -rf /tmp/*
60+
sudo rm -rf /etc/apt/sources.list.d/* /usr/share/dotnet /usr/local/lib/android /opt/ghc /etc/mysql /etc/php
61+
sudo -E apt-get -y purge azure-cli* docker* ghc* zulu* hhvm* llvm* firefox* google* dotnet* aspnetcore* powershell* openjdk* adoptopenjdk* mysql* php* mongodb* moby* snap* || true
62+
sudo rm -rf /etc/apt/sources.list.d/* /usr/local/lib/android /opt/ghc /usr/share/dotnet /usr/local/graalvm /usr/local/.ghcup \
63+
/usr/local/share/powershell /usr/local/share/chromium /usr/local/lib/node_modules
64+
sudo rm -rf /etc/apt/sources.list.d/* /usr/share/dotnet /usr/local/lib/android /opt/ghc /etc/mysql /etc/php
65+
sudo -E apt-get -y purge azure-cli* docker* ghc* zulu* hhvm* llvm* firefox* google* dotnet* aspnetcore* powershell* openjdk* adoptopenjdk* mysql* php* mongodb* moby* snap* || true
66+
sudo -E apt-get -qq update
67+
sudo -E apt-get -qq install libfuse-dev $(curl -fsSL git.io/depends-ubuntu-2204)
68+
sudo -E apt-get -qq autoremove --purge
69+
sudo -E apt-get -qq clean
70+
sudo apt-get clean
71+
rm -rf /opt/hostedtoolcache
72+
sudo timedatectl set-timezone "$TZ"
73+
# - name: Free Up Disk Space
74+
# uses: easimon/maximize-build-space@master
3375
# with:
34-
# operate_sudo: "True"
35-
# general_include: ".+"
36-
# general_exclude: |-
37-
# ^GCC$
38-
# ^G\+\+$
39-
# Clang
40-
# LLVM
41-
# docker_include: ".+"
42-
# docker_prune: "True"
43-
# docker_clean: "True"
44-
# apt_prune: "True"
45-
# apt_clean: "True"
46-
# homebrew_prune: "True"
47-
# homebrew_clean: "True"
48-
# npm_prune: "True"
49-
# npm_clean: "True"
50-
# os_swap: "True"
51-
# - name: Remove Unnecessary Tools And Files
52-
# env:
53-
# DEBIAN_FRONTEND: noninteractive
54-
# run: |
55-
# sudo apt-get remove -y '^dotnet-.*' '^llvm-.*' 'php.*' azure-cli google-chrome-stable firefox powershell mono-devel
56-
# sudo apt-get autoremove --purge -y
57-
# sudo find /var/log -name "*.gz" -type f -delete
58-
# sudo rm -rf /var/cache/apt/archives
59-
# sudo rm -rf /tmp/*
60-
# sudo rm -rf /etc/apt/sources.list.d/* /usr/share/dotnet /usr/local/lib/android /opt/ghc /etc/mysql /etc/php
61-
# sudo -E apt-get -y purge azure-cli* docker* ghc* zulu* hhvm* llvm* firefox* google* dotnet* aspnetcore* powershell* openjdk* adoptopenjdk* mysql* php* mongodb* moby* snap* || true
62-
# sudo rm -rf /etc/apt/sources.list.d/* /usr/local/lib/android /opt/ghc /usr/share/dotnet /usr/local/graalvm /usr/local/.ghcup \
63-
# /usr/local/share/powershell /usr/local/share/chromium /usr/local/lib/node_modules
64-
# sudo rm -rf /etc/apt/sources.list.d/* /usr/share/dotnet /usr/local/lib/android /opt/ghc /etc/mysql /etc/php
65-
# sudo -E apt-get -y purge azure-cli* docker* ghc* zulu* hhvm* llvm* firefox* google* dotnet* aspnetcore* powershell* openjdk* adoptopenjdk* mysql* php* mongodb* moby* snap* || true
66-
# sudo -E apt-get -qq update
67-
# sudo -E apt-get -qq install libfuse-dev $(curl -fsSL git.io/depends-ubuntu-2204)
68-
# sudo -E apt-get -qq autoremove --purge
69-
# sudo -E apt-get -qq clean
70-
# sudo apt-get clean
71-
# rm -rf /opt/hostedtoolcache
72-
# sudo timedatectl set-timezone "$TZ"
73-
## - name: Free Up Disk Space
74-
## uses: easimon/maximize-build-space@master
75-
## with:
76-
## root-reserve-mb: 30720 # 给 / 预留 30GiB 空间( docker 预留)
77-
## swap-size-mb: 1
78-
## remove-dotnet: 'true'
79-
## remove-android: 'true'
80-
## remove-haskell: 'true'
81-
## remove-codeql: 'true'
82-
## remove-docker-images: 'true'
83-
# - name: Checkout Repository
84-
# uses: actions/checkout@v4
85-
# - name: Get Version
86-
# id: version
87-
# run: |
88-
# VERSION=$(awk -F'"' '/__version__ =/ {print $2}' libs/chatchat-server/chatchat/__init__.py)
89-
# echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV
90-
# - name: Set DockerImage Tag
91-
# id: imageTag
92-
# run: echo "image_tag=${RELEASE_VERSION}-$(git rev-parse --short HEAD)-$(date +%Y%m%d)" >> $GITHUB_ENV
93-
# - name: Set Up QEMU
94-
# uses: docker/setup-qemu-action@v2
95-
# - name: Set Up Docker Buildx
96-
# uses: docker/setup-buildx-action@v2
97-
# - name: Login To Docker Hub
76+
# root-reserve-mb: 30720 # 给 / 预留 30GiB 空间( docker 预留)
77+
# swap-size-mb: 1
78+
# remove-dotnet: 'true'
79+
# remove-android: 'true'
80+
# remove-haskell: 'true'
81+
# remove-codeql: 'true'
82+
# remove-docker-images: 'true'
83+
- name: Checkout Repository
84+
uses: actions/checkout@v4
85+
- name: Get Version
86+
id: version
87+
run: |
88+
VERSION=$(awk -F'"' '/__version__ =/ {print $2}' libs/chatchat-server/chatchat/__init__.py)
89+
echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV
90+
- name: Set DockerImage Tag
91+
id: imageTag
92+
run: echo "image_tag=${RELEASE_VERSION}-$(git rev-parse --short HEAD)-$(date +%Y%m%d)" >> $GITHUB_ENV
93+
- name: Set Up QEMU
94+
uses: docker/setup-qemu-action@v2
95+
- name: Set Up Docker Buildx
96+
uses: docker/setup-buildx-action@v2
97+
- name: Login To Docker Hub
98+
uses: docker/login-action@v2
99+
with:
100+
username: ${{ vars.DOCKER_HUB_USERNAME }}
101+
password: ${{ secrets.DOCKER_HUB_SECRET }}
102+
# - name: Login To Tencent CCR
98103
# uses: docker/login-action@v2
99104
# with:
100-
# username: ${{ vars.DOCKER_HUB_USERNAME }}
101-
# password: ${{ secrets.DOCKER_HUB_SECRET }}
102-
## - name: Login To Tencent CCR
103-
## uses: docker/login-action@v2
104-
## with:
105-
## registry: ccr.ccs.tencentyun.com
106-
## username: ${{ secrets.CCR_REGISTRY_USERNAME }}
107-
## password: ${{ secrets.CCR_REGISTRY_PASSWORD }}
108-
# - name: Show Runner Disk
109-
# run: df -hT
105+
# registry: ccr.ccs.tencentyun.com
106+
# username: ${{ secrets.CCR_REGISTRY_USERNAME }}
107+
# password: ${{ secrets.CCR_REGISTRY_PASSWORD }}
108+
- name: Show Runner Disk
109+
run: df -hT
110110
# - name: Build and push Docker image
111111
# uses: docker/build-push-action@v4
112112
# with:

README.md

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,6 @@ ps: 保持这么多的联系的目的: 方便大家在两个项目间平滑切
8181

8282
---
8383

84-
## 项目里程碑
85-
86-
+ `2023年4月`: `Langchain-ChatGLM 0.1.0` 发布,支持基于 ChatGLM-6B 模型的本地知识库问答。
87-
+ `2023年8月`: `Langchain-ChatGLM` 改名为 `Langchain-Chatchat`,发布 `0.2.0` 版本,使用 `fastchat` 作为模型加载方案,支持更多的模型和数据库。
88-
+ `2023年10月`: `Langchain-Chatchat 0.2.5` 发布,推出 Agent 内容,开源项目在`Founder Park & Zhipu AI & Zilliz`
89-
举办的黑客马拉松获得三等奖。
90-
+ `2023年12月`: `Langchain-Chatchat` 开源项目获得超过 **20K** stars.
91-
+ `2024年6月`: `Langchain-Chatchat 0.3.0` 发布,带来全新项目架构。
92-
+ `2024年11月`: `LangGraph-Chatchat 0.3.0` 发布,带来全新项目架构。
93-
94-
+ 🔥 让我们一起期待未来 Chatchat 的故事 ···
95-
96-
---
97-
9884
## 协议
9985

10086
本项目代码遵循 [Apache-2.0](LICENSE) 协议。
@@ -118,8 +104,8 @@ ps: 保持这么多的联系的目的: 方便大家在两个项目间平滑切
118104
```
119105
@software{LangGraph-Chatchat,
120106
title = {{LangGraph-Chatchat}},
121-
author = {Liu, Qian and Zhang, Yuehua, and Song, Jinke, and liunux4odoo, and glide-the, and Huang, Zhiguo, and Zhang, Yuxuan},
122-
year = 2024,
107+
author = {Zhang, Yuehua},
108+
year = 2025,
123109
journal = {GitHub repository},
124110
publisher = {GitHub},
125111
howpublished = {\url{https://github.com/chatchat-space/LangGraph-Chatchat}}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from .base_rag import BaseRagGraph
2-
from .base_graph import BaseAgentGraph
2+
from .base_agent import BaseAgentGraph
33
from .plan_and_execute import PlanExecuteGraph
44
from .reflexion import ReflexionGraph
55
from .text_to_sql import TextToSQLGraph
6-
# from .article_generation import ArticleGenerationGraph

chatchat-server/chatchat/server/agent/graphs_factory/base_graph.py renamed to chatchat-server/chatchat/server/agent/graphs_factory/base_agent.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ def __init__(self,
2424
llm: ChatOpenAI,
2525
tools: list[BaseTool],
2626
history_len: int,
27-
checkpoint: BaseCheckpointSaver):
27+
checkpoint: BaseCheckpointSaver,
28+
knowledge_base: str = None,
29+
top_k: int = None,
30+
score_threshold: float = None):
2831
super().__init__(llm, tools, history_len, checkpoint)
2932
prompt = ChatPromptTemplate.from_messages(
3033
[

chatchat-server/chatchat/server/agent/graphs_factory/graphs_registry.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"State",
1919
"register_graph",
2020
"list_graph_titles_by_label",
21-
"get_graph_class_by_label_and_title"
21+
"get_graph_class_by_label_and_title",
22+
"get_graph_class"
2223
]
2324

2425

@@ -36,6 +37,7 @@ class State(TypedDict):
3637
# 全局字典用于存储不同类型图的名称和对应的类
3738
rag_registry = {}
3839
agent_registry = {}
40+
graph_registry = {}
3941

4042

4143
def register_graph(cls):
@@ -57,6 +59,11 @@ def register_graph(cls):
5759
else:
5860
raise ValueError(f"Unknown label '{label}' for class '{cls.__name__}'.")
5961

62+
graph_registry[name] = {
63+
"class": cls,
64+
"title": title
65+
}
66+
6067
return cls
6168

6269

@@ -158,3 +165,9 @@ def get_graph_class_by_label_and_title(label: str, title: str) -> Type[Graph]:
158165
else:
159166
raise ValueError(f"Unknown label '{label}'.")
160167
raise ValueError(f"No graph found with title '{title}' for label '{label}'.")
168+
169+
170+
def get_graph_class(name: str) -> Type[Graph]:
171+
if name not in graph_registry:
172+
raise ValueError(f"Graph '{name}' is not registered in graph_registry.")
173+
return graph_registry[name]["class"]

chatchat-server/chatchat/server/agent/graphs_factory/plan_and_execute.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ def __init__(self,
6767
llm: ChatOpenAI,
6868
tools: list[BaseTool],
6969
history_len: int,
70-
checkpoint: BaseCheckpointSaver):
70+
checkpoint: BaseCheckpointSaver,
71+
knowledge_base: str = None,
72+
top_k: int = None,
73+
score_threshold: float = None):
7174
super().__init__(llm, tools, history_len, checkpoint)
7275

7376
async def plan_step(self, state: PlanExecute) -> PlanExecute:

chatchat-server/chatchat/server/agent/graphs_factory/reflexion.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ def __init__(self,
103103
llm: ChatOpenAI,
104104
tools: list[BaseTool],
105105
history_len: int,
106-
checkpoint: BaseCheckpointSaver):
106+
checkpoint: BaseCheckpointSaver,
107+
knowledge_base: str = None,
108+
top_k: int = None,
109+
score_threshold: float = None):
107110
super().__init__(llm, tools, history_len, checkpoint)
108111
# 担心用户没有选择任何 tool 而造成 agent 逻辑无效, 为保证效果, 强行追加一个 search_internet 工具, 如开发者不需要可注释此行代码.
109112
search_internet = get_tool(name="search_internet")

chatchat-server/chatchat/server/agent/graphs_factory/text_to_sql.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ def __init__(self,
2424
llm: ChatOpenAI,
2525
tools: list[BaseTool],
2626
history_len: int,
27-
checkpoint: BaseCheckpointSaver):
27+
checkpoint: BaseCheckpointSaver,
28+
knowledge_base: str = None,
29+
top_k: int = None,
30+
score_threshold: float = None):
2831
super().__init__(llm, tools, history_len, checkpoint)
2932
query_sql_data = get_tool(name="query_sql_data")
3033
self.tools = add_tools_if_not_exists(tools_provides=self.tools, tools_need_append=[query_sql_data])

chatchat-server/chatchat/server/agent/tools_factory/search_internet.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ def search_engine(query: str, top_k: int = 0, engine_name: str = "", config: dic
106106
top_k = config.get("top_k", Settings.kb_settings.SEARCH_ENGINE_TOP_K)
107107
engine_name = engine_name or config.get("search_engine_name")
108108
search_engine_use = SEARCH_ENGINES[engine_name]
109-
print(f"Searching engine: {engine_name}")
110109
if engine_name == "duckduckgo":
111110
results = search_engine_use(
112111
text=query, top_k=top_k

0 commit comments

Comments
 (0)