From 54d686554d05088f6a57593141fcf50ffa94d8ec Mon Sep 17 00:00:00 2001 From: joecryptotoo <80373433+joecryptotoo@users.noreply.github.com> Date: Thu, 22 Jun 2023 16:23:02 -0700 Subject: [PATCH 01/14] changed to gpu 0(first GPU) For me GPU0 is a 3080 and GPU1 is a 4090 others may only have one GPU --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index b224e1ac3..1f8dc9f52 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -50,7 +50,7 @@ services: reservations: devices: - driver: nvidia - device_ids: ['1'] + device_ids: ['0'] capabilities: [gpu] From c5b61e65b92c38aa2284bd484b6433a575d121ea Mon Sep 17 00:00:00 2001 From: joecryptotoo <80373433+joecryptotoo@users.noreply.github.com> Date: Thu, 22 Jun 2023 16:28:48 -0700 Subject: [PATCH 02/14] docker ignore plugins too --- .dockerignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.dockerignore b/.dockerignore index 2bcdfd92b..e5b067a78 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,2 @@ models/ +plugins/ From c4bafe455a9d2f56ed8eb3c1e5fb88c43613d1ee Mon Sep 17 00:00:00 2001 From: Joe Crypto Date: Fri, 23 Jun 2023 01:18:34 +0000 Subject: [PATCH 03/14] added tunnel --- Dockerfile-webserver => Dockerfile | 16 ++++++++-------- Dockerfile-llmserver | 21 --------------------- docker-compose.yml | 26 +++++++++++++++++++++----- 3 files changed, 29 insertions(+), 34 deletions(-) rename Dockerfile-webserver => Dockerfile (83%) delete mode 100644 Dockerfile-llmserver diff --git a/Dockerfile-webserver b/Dockerfile similarity index 83% rename from Dockerfile-webserver rename to Dockerfile index bd6aa73dd..3b6d7ef92 100644 --- a/Dockerfile-webserver +++ b/Dockerfile @@ -1,23 +1,23 @@ FROM nvidia/cuda:11.8.0-devel-ubuntu22.04 +WORKDIR /app + RUN apt-get update && apt-get install -y \ git \ python3 \ pip - -WORKDIR /app - -COPY . /app - - # upgrade pip RUN pip3 install --upgrade pip +COPY ./requirements.txt /app/requirements.txt + RUN pip install --no-cache-dir -r requirements.txt RUN python3 -m spacy download zh_core_web_sm -EXPOSE 7860 -CMD ["python3", "pilot/server/webserver.py"] +COPY . /app + +EXPOSE 7860 +EXPOSE 8000 \ No newline at end of file diff --git a/Dockerfile-llmserver b/Dockerfile-llmserver deleted file mode 100644 index c36567381..000000000 --- a/Dockerfile-llmserver +++ /dev/null @@ -1,21 +0,0 @@ -FROM nvidia/cuda:11.8.0-devel-ubuntu22.04 - -RUN apt-get update && apt-get install -y \ - git \ - python3 \ - pip - - -WORKDIR /app - -COPY . /app - - -# upgrade pip -RUN pip3 install --upgrade pip - -RUN pip install --no-cache-dir -r requirements.txt - -EXPOSE 8000 - -CMD ["python3", "pilot/server/llmserver.py"] diff --git a/docker-compose.yml b/docker-compose.yml index 1f8dc9f52..9f17e160f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,11 +16,16 @@ services: webserver: build: context: . - dockerfile: Dockerfile-webserver + dockerfile: Dockerfile + command: python3 pilot/server/webserver.py environment: - MODEL_SERVER=http://llmserver:8000 - LOCAL_DB_HOST=db - WEB_SERVER_PORT=7860 + - ALLOWLISTED_PLUGINS=db_dashboard + depends_on: + - db + - llmserver volumes: - ./models:/app/models - ./plugins:/app/plugins @@ -28,16 +33,19 @@ services: env_file: - .env.template ports: - - 7860:7860 + - 7860:7860/tcp expose: - - 7860 + - 7860/tcp restart: unless-stopped llmserver: build: context: . - dockerfile: Dockerfile-llmserver + dockerfile: Dockerfile + command: python3 pilot/server/llmserver.py environment: - LOCAL_DB_HOST=db + depends_on: + - db volumes: - ./models:/app/models env_file: @@ -52,7 +60,15 @@ services: - driver: nvidia device_ids: ['0'] capabilities: [gpu] - + tunnel: + image: cloudflare/cloudflared:latest + container_name: cloudflared-tunnel + restart: unless-stopped + environment: + - TUNNEL_URL=http://webserver:7860 + command: tunnel --no-autoupdate + depends_on: + - webserver volumes: From 1af3ce475646349532213f75ea5cea7577e21242 Mon Sep 17 00:00:00 2001 From: Joe Crypto Date: Fri, 23 Jun 2023 01:20:44 +0000 Subject: [PATCH 04/14] added plugins to gitignore --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 359f7a03d..7eac46640 100644 --- a/.gitignore +++ b/.gitignore @@ -28,7 +28,9 @@ sdist/ var/ wheels/ -models/* +models/ +plugins/ + pip-wheel-metadata/ share/python-wheels/ *.egg-info/ From 192b28948022ad510cf4f02fb2aabf9f6726749e Mon Sep 17 00:00:00 2001 From: csunny Date: Sun, 25 Jun 2023 23:05:50 +0800 Subject: [PATCH 05/14] feat: add chatglm2-6b support --- docs/getting_started/getting_started.md | 1 + docs/modules/llms.md | 6 ++++++ pilot/configs/model_config.py | 1 + 3 files changed, 8 insertions(+) diff --git a/docs/getting_started/getting_started.md b/docs/getting_started/getting_started.md index d082a0c75..33653f248 100644 --- a/docs/getting_started/getting_started.md +++ b/docs/getting_started/getting_started.md @@ -38,6 +38,7 @@ Once the environment is installed, we have to create a new folder "models" in th git clone https://huggingface.co/Tribbiani/vicuna-13b git clone https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2 git clone https://huggingface.co/GanymedeNil/text2vec-large-chinese +git clone https://huggingface.co/THUDM/chatglm2-6b ``` The model files are large and will take a long time to download. During the download, let's configure the .env file, which needs to be copied and created from the .env.template diff --git a/docs/modules/llms.md b/docs/modules/llms.md index 217961a51..bec64313e 100644 --- a/docs/modules/llms.md +++ b/docs/modules/llms.md @@ -17,6 +17,12 @@ if you want use other model, such as chatglm-6b, you just need update .env confi ``` LLM_MODEL=chatglm-6b ``` +or chatglm2-6b, which is the second-generation version of the open-source bilingual (Chinese-English) chat model ChatGLM-6B. +``` +LLM_MODEL=chatglm2-6b +``` + + ## Run Model with cpu. we alse support smaller models, like gpt4all. you can use it with cpu/mps(M1/M2), Download from [gpt4all model](https://gpt4all.io/models/ggml-gpt4all-j-v1.3-groovy.bin) diff --git a/pilot/configs/model_config.py b/pilot/configs/model_config.py index f6d59e4e1..2f44fc520 100644 --- a/pilot/configs/model_config.py +++ b/pilot/configs/model_config.py @@ -39,6 +39,7 @@ LLM_MODEL_CONFIG = { "codet5p-2b": os.path.join(MODEL_PATH, "codet5p-2b"), "chatglm-6b-int4": os.path.join(MODEL_PATH, "chatglm-6b-int4"), "chatglm-6b": os.path.join(MODEL_PATH, "chatglm-6b"), + "chatglm2-6b": os.path.join(MODEL_PATH, "chatglm2-6b"), "text2vec-base": os.path.join(MODEL_PATH, "text2vec-base-chinese"), "guanaco-33b-merged": os.path.join(MODEL_PATH, "guanaco-33b-merged"), "falcon-40b": os.path.join(MODEL_PATH, "falcon-40b"), From d983a69d1674de10e829baf20dbf756746a330db Mon Sep 17 00:00:00 2001 From: csunny Date: Sun, 25 Jun 2023 23:07:41 +0800 Subject: [PATCH 06/14] feat: support chatglm2-6b --- docs/conf.py | 2 +- docs/locales/zh_CN/LC_MESSAGES/modules/llms.po | 2 +- setup.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index e00f95f06..04800c71e 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -14,7 +14,7 @@ project = "DB-GPT" copyright = "2023, csunny" author = "csunny" -version = "👏👏 0.2.2" +version = "👏👏 0.2.3" html_title = project + " " + version # -- General configuration --------------------------------------------------- diff --git a/docs/locales/zh_CN/LC_MESSAGES/modules/llms.po b/docs/locales/zh_CN/LC_MESSAGES/modules/llms.po index e230efde5..7462da33f 100644 --- a/docs/locales/zh_CN/LC_MESSAGES/modules/llms.po +++ b/docs/locales/zh_CN/LC_MESSAGES/modules/llms.po @@ -6,7 +6,7 @@ #, fuzzy msgid "" msgstr "" -"Project-Id-Version: DB-GPT 0.1.0\n" +"Project-Id-Version: DB-GPT 0.2.3\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2023-06-14 22:33+0800\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" diff --git a/setup.py b/setup.py index b0732aeda..46dea861b 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ def parse_requirements(file_name: str) -> List[str]: setuptools.setup( name="DB-GPT", packages=find_packages(), - version="0.2.2", + version="0.2.3", author="csunny", author_email="cfqcsunny@gmail.com", description="DB-GPT is an experimental open-source project that uses localized GPT large models to interact with your data and environment." From c19a7b12e155676f29ebe42775e27cc2a174772c Mon Sep 17 00:00:00 2001 From: csunny Date: Sun, 25 Jun 2023 23:23:37 +0800 Subject: [PATCH 07/14] docs: update readme for new llm support --- README.md | 3 ++- README.zh.md | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 41084d2c9..75adc94df 100644 --- a/README.md +++ b/README.md @@ -21,10 +21,11 @@ As large models are released and iterated upon, they are becoming increasingly i DB-GPT is an experimental open-source project that uses localized GPT large models to interact with your data and environment. With this solution, you can be assured that there is no risk of data leakage, and your data is 100% private and secure. ## News +- [2023/06/25]🔥support chatglm2-6b model. [documents](https://db-gpt.readthedocs.io/en/latest/modules/llms.html) - [2023/06/14] support gpt4all model, which can run at M1/M2, or cpu machine. [documents](https://db-gpt.readthedocs.io/en/latest/modules/llms.html) - [2023/06/01]🔥 On the basis of the Vicuna-13B basic model, task chain calls are implemented through plugins. For example, the implementation of creating a database with a single sentence.[demo](./assets/auto_plugin.gif) - [2023/06/01]🔥 QLoRA guanaco(7b, 13b, 33b) support. -- [2023/05/28]🔥 Learning from crawling data from the Internet [demo](./assets/chaturl_en.gif) +- [2023/05/28] Learning from crawling data from the Internet [demo](./assets/chaturl_en.gif) - [2023/05/21] Generate SQL and execute it automatically. [demo](./assets/auto_sql_en.gif) - [2023/05/15] Chat with documents. [demo](./assets/new_knownledge_en.gif) - [2023/05/06] SQL generation and diagnosis. [demo](./assets/demo_en.gif) diff --git a/README.zh.md b/README.zh.md index 544fca460..612011db2 100644 --- a/README.zh.md +++ b/README.zh.md @@ -23,6 +23,7 @@ DB-GPT 是一个开源的以数据库为基础的GPT实验项目,使用本地 ## 最新发布 +- [2023/06/25]🔥 支持ChatGLM2-6B模型。 [使用文档](https://db-gpt.readthedocs.io/projects/db-gpt-docs-zh-cn/zh_CN/latest/modules/llms.html) - [2023/06/14]🔥 支持gpt4all模型,可以在M1/M2 或者CPU机器上运行。 [使用文档](https://db-gpt.readthedocs.io/projects/db-gpt-docs-zh-cn/zh_CN/latest/modules/llms.html) - [2023/06/01]🔥 在Vicuna-13B基础模型的基础上,通过插件实现任务链调用。例如单句创建数据库的实现. - [2023/06/01]🔥 QLoRA guanaco(原驼)支持, 支持4090运行33B From aa4115ef67b6e8e3902d0628814d33936a6be823 Mon Sep 17 00:00:00 2001 From: "magic.chen" Date: Sun, 25 Jun 2023 23:29:43 +0800 Subject: [PATCH 08/14] Update model_config.py --- pilot/configs/model_config.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pilot/configs/model_config.py b/pilot/configs/model_config.py index 2f44fc520..30124461d 100644 --- a/pilot/configs/model_config.py +++ b/pilot/configs/model_config.py @@ -40,6 +40,7 @@ LLM_MODEL_CONFIG = { "chatglm-6b-int4": os.path.join(MODEL_PATH, "chatglm-6b-int4"), "chatglm-6b": os.path.join(MODEL_PATH, "chatglm-6b"), "chatglm2-6b": os.path.join(MODEL_PATH, "chatglm2-6b"), + "chatglm2-6b-int4": os.path.join(MODEL_PATH, "chatglm2-6b-int4"), "text2vec-base": os.path.join(MODEL_PATH, "text2vec-base-chinese"), "guanaco-33b-merged": os.path.join(MODEL_PATH, "guanaco-33b-merged"), "falcon-40b": os.path.join(MODEL_PATH, "falcon-40b"), From b41be465ad45e3854e79f8a56c5fb92f1e3ec769 Mon Sep 17 00:00:00 2001 From: staneyffer Date: Mon, 26 Jun 2023 18:13:31 +0800 Subject: [PATCH 09/14] fix: documents chat not working with chatglm2-6b --- pilot/model/llm_out/chatglm_llm.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pilot/model/llm_out/chatglm_llm.py b/pilot/model/llm_out/chatglm_llm.py index 690be0f06..299adbf2a 100644 --- a/pilot/model/llm_out/chatglm_llm.py +++ b/pilot/model/llm_out/chatglm_llm.py @@ -54,7 +54,12 @@ def chatglm_generate_stream( try: query = messages[-2].split("human:")[1] except IndexError: - query = messages[-3].split("human:")[1] + # fix doc qa: https://github.com/csunny/DB-GPT/issues/274 + doc_qa_message = messages[-2] + if "system:" in doc_qa_message: + query = doc_qa_message.split("system:")[1] + else: + query = messages[-3].split("human:")[1] print("Query Message: ", query) # output = "" # i = 0 From f4c3707d8a333998a958ba38b998c697a2b7d31b Mon Sep 17 00:00:00 2001 From: aries_ckt <916701291@qq.com> Date: Tue, 27 Jun 2023 22:24:58 +0800 Subject: [PATCH 10/14] fix:rename knowledge_init.py rename knowledge_init.py --- tools/{knowlege_init.py => knowledge_init.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tools/{knowlege_init.py => knowledge_init.py} (100%) diff --git a/tools/knowlege_init.py b/tools/knowledge_init.py similarity index 100% rename from tools/knowlege_init.py rename to tools/knowledge_init.py From a4493b747279dbe218cc22564538280bfb0b61c6 Mon Sep 17 00:00:00 2001 From: Data Hamal <5611929+huangzhuxing@users.noreply.github.com> Date: Wed, 28 Jun 2023 00:52:45 +0800 Subject: [PATCH 11/14] Update base.py fix function __extract_json slef --> self --- pilot/out_parser/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pilot/out_parser/base.py b/pilot/out_parser/base.py index 96ddf64a0..bfe95adda 100644 --- a/pilot/out_parser/base.py +++ b/pilot/out_parser/base.py @@ -120,7 +120,7 @@ class BaseOutputParser(ABC): else: raise ValueError("Model server error!code=" + respObj_ex["error_code"]) - def __extract_json(slef, s): + def __extract_json(self, s): i = s.index("{") count = 1 # 当前所在嵌套深度,即还没闭合的'{'个数 for j, c in enumerate(s[i + 1 :], start=i + 1): From a032054188488e0d3f1b439fdd3297bc934e9084 Mon Sep 17 00:00:00 2001 From: "magic.chen" Date: Wed, 28 Jun 2023 12:59:52 +0800 Subject: [PATCH 12/14] docs: Update README.md update discord invite info --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 41084d2c9..5c1736f58 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@

-[**简体中文**](README.zh.md) |[**Discord**](https://discord.gg/hmGPnMSb) |[**Documents**](https://db-gpt.readthedocs.io/en/latest/)|[**Wechat**](https://github.com/csunny/DB-GPT/blob/main/README.zh.md#%E8%81%94%E7%B3%BB%E6%88%91%E4%BB%AC) +[**简体中文**](README.zh.md) |[**Discord**](https://discord.gg/4BNdxm5d) |[**Documents**](https://db-gpt.readthedocs.io/en/latest/)|[**Wechat**](https://github.com/csunny/DB-GPT/blob/main/README.zh.md#%E8%81%94%E7%B3%BB%E6%88%91%E4%BB%AC) @@ -149,7 +149,7 @@ This project is standing on the shoulders of giants and is not going to work wit The MIT License (MIT) ## Contact Information -We are working on building a community, if you have any ideas about building the community, feel free to contact us. [Discord](https://discord.gg/hmGPnMSb) +We are working on building a community, if you have any ideas about building the community, feel free to contact us. [Discord](https://discord.gg/4BNdxm5d) [![Star History Chart](https://api.star-history.com/svg?repos=csunny/DB-GPT)](https://star-history.com/#csunny/DB-GPT) From 6fdeff9a0a76a89bd75ae958e1f61c38f09d2ce4 Mon Sep 17 00:00:00 2001 From: aries_ckt <916701291@qq.com> Date: Fri, 30 Jun 2023 15:02:18 +0800 Subject: [PATCH 13/14] fix:knowledge_init.py multi document cannot search answser 1.rebuild knowledge_init.py Close #285 --- pilot/source_embedding/source_embedding.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pilot/source_embedding/source_embedding.py b/pilot/source_embedding/source_embedding.py index 3d881fcdf..75e42dfbf 100644 --- a/pilot/source_embedding/source_embedding.py +++ b/pilot/source_embedding/source_embedding.py @@ -33,9 +33,7 @@ class SourceEmbedding(ABC): self.vector_store_config = vector_store_config self.embedding_args = embedding_args self.embeddings = vector_store_config["embeddings"] - self.vector_client = VectorStoreConnector( - CFG.VECTOR_STORE_TYPE, vector_store_config - ) + @abstractmethod @register @@ -59,11 +57,17 @@ class SourceEmbedding(ABC): @register def index_to_store(self, docs): """index to vector store""" + self.vector_client = VectorStoreConnector( + CFG.VECTOR_STORE_TYPE, self.vector_store_config + ) self.vector_client.load_document(docs) @register def similar_search(self, doc, topk): """vector store similarity_search""" + self.vector_client = VectorStoreConnector( + CFG.VECTOR_STORE_TYPE, self.vector_store_config + ) try: ans = self.vector_client.similar_search(doc, topk) except NotEnoughElementsException: @@ -71,6 +75,9 @@ class SourceEmbedding(ABC): return ans def vector_name_exist(self): + self.vector_client = VectorStoreConnector( + CFG.VECTOR_STORE_TYPE, self.vector_store_config + ) return self.vector_client.vector_name_exists() def source_embedding(self): From f4aa58a95407a64b22400f20bff39a352f616daa Mon Sep 17 00:00:00 2001 From: aries_ckt <916701291@qq.com> Date: Fri, 30 Jun 2023 15:04:33 +0800 Subject: [PATCH 14/14] style:format code --- pilot/source_embedding/knowledge_embedding.py | 1 + pilot/source_embedding/source_embedding.py | 1 - tools/knowledge_init.py | 9 ++++++--- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pilot/source_embedding/knowledge_embedding.py b/pilot/source_embedding/knowledge_embedding.py index 97b515897..d8ec85ae3 100644 --- a/pilot/source_embedding/knowledge_embedding.py +++ b/pilot/source_embedding/knowledge_embedding.py @@ -51,6 +51,7 @@ class KnowledgeEmbedding: self.knowledge_embedding_client.index_to_store(docs) def read(self): + self.knowledge_embedding_client = self.init_knowledge_embedding() return self.knowledge_embedding_client.read_batch() def init_knowledge_embedding(self): diff --git a/pilot/source_embedding/source_embedding.py b/pilot/source_embedding/source_embedding.py index 75e42dfbf..372e35c22 100644 --- a/pilot/source_embedding/source_embedding.py +++ b/pilot/source_embedding/source_embedding.py @@ -34,7 +34,6 @@ class SourceEmbedding(ABC): self.embedding_args = embedding_args self.embeddings = vector_store_config["embeddings"] - @abstractmethod @register def read(self) -> List[ABC]: diff --git a/tools/knowledge_init.py b/tools/knowledge_init.py index c9a0c5457..74c62b90a 100644 --- a/tools/knowledge_init.py +++ b/tools/knowledge_init.py @@ -25,17 +25,20 @@ class LocalKnowledgeInit: def knowledge_persist(self, file_path): """knowledge persist""" + docs = [] + embedding_engine = None for root, _, files in os.walk(file_path, topdown=False): for file in files: filename = os.path.join(root, file) - # docs = self._load_file(filename) ke = KnowledgeEmbedding( file_path=filename, model_name=self.model_name, vector_store_config=self.vector_store_config, ) - client = ke.init_knowledge_embedding() - client.source_embedding() + embedding_engine = ke.init_knowledge_embedding() + doc = ke.read() + docs.extend(doc) + embedding_engine.index_to_store(docs) if __name__ == "__main__":