From 33506b062ba05740066f4bb151bbf6f83766aad9 Mon Sep 17 00:00:00 2001 From: FangYin Cheng Date: Wed, 20 Sep 2023 17:31:56 +0800 Subject: [PATCH] feat(core): Multi-module dependency splitting --- .github/release-drafter.yml | 10 ++ .gitignore | 2 + README.md | 2 +- README.zh.md | 2 +- docker/base/Dockerfile | 12 +- docker/base/build_image.sh | 47 ++++++- .../install/cluster/vms/index.md | 2 +- docs/getting_started/install/deploy/deploy.md | 2 +- docs/getting_started/install/llm/llm.rst | 2 +- pilot/common/plugins.py | 9 +- pilot/configs/config.py | 14 ++- pilot/configs/model_config.py | 22 ++-- pilot/embedding_engine/embedding_engine.py | 9 +- pilot/embedding_engine/markdown_embedding.py | 1 - pilot/embedding_engine/source_embedding.py | 8 +- pilot/model/cluster/worker/default_worker.py | 29 +++-- pilot/model/cluster/worker/manager.py | 6 +- pilot/model/proxy/llms/bard.py | 3 +- .../chat_excel/excel_learning/chat.py | 3 - pilot/scene/chat_knowledge/v1/chat.py | 25 ++-- pilot/server/knowledge/_cli/knowledge_cli.py | 2 +- .../static/chunks/79.e75d7ee2dd885405.js | 2 +- .../chunks/pages/index-d5aba6bbbc1d8aaa.js | 2 +- pilot/summary/db_summary_client.py | 5 +- pilot/vector_store/chroma_store.py | 18 ++- requirements.txt | 84 ------------- ...-requirements.txt => dev-requirements.txt} | 6 +- setup.py | 117 ++++++++++++++---- 28 files changed, 253 insertions(+), 193 deletions(-) delete mode 100644 requirements.txt rename requirements/{test-requirements.txt => dev-requirements.txt} (58%) diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml index d13cf203a..c2177125e 100644 --- a/.github/release-drafter.yml +++ b/.github/release-drafter.yml @@ -76,6 +76,16 @@ autolabeler: # feat(connection): Support xxxx # fix(connection): Fix xxx - '/^(build|chore|ci|depr|docs|feat|fix|perf|refactor|release|test)\(.*connection.*\)/' + - label: core + title: + # feat(core): Support xxxx + # fix(core): Fix xxx + - '/^(build|chore|ci|depr|docs|feat|fix|perf|refactor|release|test)\(.*core.*\)/' + - label: web + title: + # feat(web): Support xxxx + # fix(web): Fix xxx + - '/^(build|chore|ci|depr|docs|feat|fix|perf|refactor|release|test)\(.*web.*\)/' - label: build title: - '/^build/' diff --git a/.gitignore b/.gitignore index 55e18c91f..d9fbfd59b 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,8 @@ sdist/ var/ wheels/ models/ +# Soft link +models plugins/ pip-wheel-metadata/ diff --git a/README.md b/README.md index 882570c21..ba01184c9 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ Currently, we have released multiple key features, which are listed below to dem - Unified vector storage/indexing of knowledge base - Support for unstructured data such as PDF, TXT, Markdown, CSV, DOC, PPT, and WebURL - Multi LLMs Support, Supports multiple large language models, currently supporting - - 🔥 InternLM(7b) + - 🔥 InternLM(7b,20b) - 🔥 Baichuan2(7b,13b) - 🔥 Vicuna-v1.5(7b,13b) - 🔥 llama-2(7b,13b,70b) diff --git a/README.zh.md b/README.zh.md index abebc1c9e..5da2e9b22 100644 --- a/README.zh.md +++ b/README.zh.md @@ -119,7 +119,7 @@ DB-GPT 是一个开源的以数据库为基础的GPT实验项目,使用本地 - 非结构化数据支持包括PDF、MarkDown、CSV、WebURL - 多模型支持 - 支持多种大语言模型, 当前已支持如下模型: - - 🔥 InternLM(7b) + - 🔥 InternLM(7b,20b) - 🔥 Baichuan2(7b,13b) - 🔥 Vicuna-v1.5(7b,13b) - 🔥 llama-2(7b,13b,70b) diff --git a/docker/base/Dockerfile b/docker/base/Dockerfile index 3abd04909..7c6bbf598 100644 --- a/docker/base/Dockerfile +++ b/docker/base/Dockerfile @@ -11,10 +11,12 @@ ARG LANGUAGE="en" ARG PIP_INDEX_URL="https://pypi.org/simple" ENV PIP_INDEX_URL=$PIP_INDEX_URL +ARG DB_GPT_INSTALL_MODEL="default" +ENV DB_GPT_INSTALL_MODEL=$DB_GPT_INSTALL_MODEL + RUN mkdir -p /app # COPY only requirements.txt first to leverage Docker cache -COPY ./requirements.txt /app/requirements.txt COPY ./setup.py /app/setup.py COPY ./README.md /app/README.md @@ -26,9 +28,9 @@ WORKDIR /app # RUN pip3 install -i $PIP_INDEX_URL ".[all]" RUN pip3 install --upgrade pip -i $PIP_INDEX_URL \ - && pip3 install -i $PIP_INDEX_URL . \ - # && pip3 install -i $PIP_INDEX_URL ".[llama_cpp]" \ - && (if [ "${LANGUAGE}" = "zh" ]; \ + && pip3 install -i $PIP_INDEX_URL ".[$DB_GPT_INSTALL_MODEL]" + +RUN (if [ "${LANGUAGE}" = "zh" ]; \ # language is zh, download zh_core_web_sm from github then wget https://github.com/explosion/spacy-models/releases/download/zh_core_web_sm-3.5.0/zh_core_web_sm-3.5.0-py3-none-any.whl -O /tmp/zh_core_web_sm-3.5.0-py3-none-any.whl \ && pip3 install /tmp/zh_core_web_sm-3.5.0-py3-none-any.whl -i $PIP_INDEX_URL \ @@ -58,4 +60,4 @@ RUN (if [ "${LOAD_EXAMPLES}" = "true" ]; \ ENV PYTHONPATH "/app:$PYTHONPATH" EXPOSE 5000 -CMD ["python3", "pilot/server/dbgpt_server.py"] \ No newline at end of file +CMD ["dbgpt", "start", "webserver"] \ No newline at end of file diff --git a/docker/base/build_image.sh b/docker/base/build_image.sh index 03a3185c4..9ecd9db9d 100755 --- a/docker/base/build_image.sh +++ b/docker/base/build_image.sh @@ -4,14 +4,21 @@ SCRIPT_LOCATION=$0 cd "$(dirname "$SCRIPT_LOCATION")" WORK_DIR=$(pwd) -BASE_IMAGE="nvidia/cuda:11.8.0-runtime-ubuntu22.04" +BASE_IMAGE_DEFAULT="nvidia/cuda:11.8.0-runtime-ubuntu22.04" +BASE_IMAGE_DEFAULT_CPU="ubuntu:22.04" + +BASE_IMAGE=$BASE_IMAGE_DEFAULT IMAGE_NAME="eosphorosai/dbgpt" +IMAGE_NAME_ARGS="" + # zh: https://pypi.tuna.tsinghua.edu.cn/simple PIP_INDEX_URL="https://pypi.org/simple" # en or zh LANGUAGE="en" BUILD_LOCAL_CODE="false" LOAD_EXAMPLES="true" +BUILD_NETWORK="" +DB_GPT_INSTALL_MODEL="default" usage () { echo "USAGE: $0 [--base-image nvidia/cuda:11.8.0-runtime-ubuntu22.04] [--image-name db-gpt]" @@ -21,6 +28,8 @@ usage () { echo " [--language en or zh] You language, default: en" echo " [--build-local-code true or false] Whether to use the local project code to package the image, default: false" echo " [--load-examples true or false] Whether to load examples to default database default: true" + echo " [--network network name] The network of docker build" + echo " [--install-mode mode name] Installation mode name, default: default, If you completely use openai's service, you can set the mode name to 'openai'" echo " [-h|--help] Usage message" } @@ -33,7 +42,7 @@ while [[ $# -gt 0 ]]; do shift # past value ;; -n|--image-name) - IMAGE_NAME="$2" + IMAGE_NAME_ARGS="$2" shift # past argument shift # past value ;; @@ -57,6 +66,20 @@ while [[ $# -gt 0 ]]; do shift shift ;; + --network) + BUILD_NETWORK=" --network $2 " + shift # past argument + shift # past value + ;; + -h|--help) + help="true" + shift + ;; + --install-mode) + DB_GPT_INSTALL_MODEL="$2" + shift # past argument + shift # past value + ;; -h|--help) help="true" shift @@ -73,11 +96,29 @@ if [[ $help ]]; then exit 0 fi -docker build \ +if [ "$DB_GPT_INSTALL_MODEL" != "default" ]; then + IMAGE_NAME="$IMAGE_NAME-$DB_GPT_INSTALL_MODEL" + echo "install mode is not 'default', set image name to: ${IMAGE_NAME}" +fi + +if [ -z "$IMAGE_NAME_ARGS" ]; then + if [ "$DB_GPT_INSTALL_MODEL" == "openai" ]; then + # Use cpu image + BASE_IMAGE=$BASE_IMAGE_DEFAULT_CPU + fi +else + # User input image is not empty + BASE_IMAGE=$IMAGE_NAME_ARGS +fi + +echo "Begin build docker image, base image: ${BASE_IMAGE}, target image name: ${IMAGE_NAME}" + +docker build $BUILD_NETWORK \ --build-arg BASE_IMAGE=$BASE_IMAGE \ --build-arg PIP_INDEX_URL=$PIP_INDEX_URL \ --build-arg LANGUAGE=$LANGUAGE \ --build-arg BUILD_LOCAL_CODE=$BUILD_LOCAL_CODE \ --build-arg LOAD_EXAMPLES=$LOAD_EXAMPLES \ + --build-arg DB_GPT_INSTALL_MODEL=$DB_GPT_INSTALL_MODEL \ -f Dockerfile \ -t $IMAGE_NAME $WORK_DIR/../../ diff --git a/docs/getting_started/install/cluster/vms/index.md b/docs/getting_started/install/cluster/vms/index.md index 03b5b0293..fc8f777c5 100644 --- a/docs/getting_started/install/cluster/vms/index.md +++ b/docs/getting_started/install/cluster/vms/index.md @@ -6,7 +6,7 @@ Local cluster deployment **Installing Command-Line Tool** -All operations below are performed using the `dbgpt` command. To use the `dbgpt` command, you need to install the DB-GPT project with `pip install -e .`. Alternatively, you can use `python pilot/scripts/cli_scripts.py` as a substitute for the `dbgpt` command. +All operations below are performed using the `dbgpt` command. To use the `dbgpt` command, you need to install the DB-GPT project with `pip install -e ".[default]"`. Alternatively, you can use `python pilot/scripts/cli_scripts.py` as a substitute for the `dbgpt` command. ### Launch Model Controller diff --git a/docs/getting_started/install/deploy/deploy.md b/docs/getting_started/install/deploy/deploy.md index 2f2880fb2..df116a47c 100644 --- a/docs/getting_started/install/deploy/deploy.md +++ b/docs/getting_started/install/deploy/deploy.md @@ -49,7 +49,7 @@ For the entire installation process of DB-GPT, we use the miniconda3 virtual env python>=3.10 conda create -n dbgpt_env python=3.10 conda activate dbgpt_env -pip install -e . +pip install -e ".[default]" ``` Before use DB-GPT Knowledge ```bash diff --git a/docs/getting_started/install/llm/llm.rst b/docs/getting_started/install/llm/llm.rst index 28b66378a..c20d19c89 100644 --- a/docs/getting_started/install/llm/llm.rst +++ b/docs/getting_started/install/llm/llm.rst @@ -6,7 +6,7 @@ DB-GPT provides a management and deployment solution for multiple models. This c Multi LLMs Support, Supports multiple large language models, currently supporting - - 🔥 InternLM(7b) + - 🔥 InternLM(7b,20b) - 🔥 Baichuan2(7b,13b) - 🔥 Vicuna-v1.5(7b,13b) - 🔥 llama-2(7b,13b,70b) diff --git a/pilot/common/plugins.py b/pilot/common/plugins.py index 3ee5f4ac2..517dc800a 100644 --- a/pilot/common/plugins.py +++ b/pilot/common/plugins.py @@ -1,4 +1,5 @@ """加载组件""" +from __future__ import annotations import json import os @@ -8,17 +9,19 @@ import requests import threading import datetime from pathlib import Path -from typing import List +from typing import List, TYPE_CHECKING from urllib.parse import urlparse from zipimport import zipimporter import requests -from auto_gpt_plugin_template import AutoGPTPluginTemplate from pilot.configs.config import Config from pilot.configs.model_config import PLUGINS_DIR from pilot.logs import logger +if TYPE_CHECKING: + from auto_gpt_plugin_template import AutoGPTPluginTemplate + def inspect_zip_for_modules(zip_path: str, debug: bool = False) -> list[str]: """ @@ -115,7 +118,7 @@ def load_native_plugins(cfg: Config): t.start() -def scan_plugins(cfg: Config, debug: bool = False) -> List[AutoGPTPluginTemplate]: +def scan_plugins(cfg: Config, debug: bool = False) -> List["AutoGPTPluginTemplate"]: """Scan the plugins directory for plugins and loads them. Args: diff --git a/pilot/configs/config.py b/pilot/configs/config.py index 5d256a8e5..5dde6ff99 100644 --- a/pilot/configs/config.py +++ b/pilot/configs/config.py @@ -1,11 +1,16 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- +from __future__ import annotations import os -from typing import List +from typing import List, Optional, TYPE_CHECKING from pilot.singleton import Singleton +if TYPE_CHECKING: + from auto_gpt_plugin_template import AutoGPTPluginTemplate + from pilot.component import SystemApp + class Config(metaclass=Singleton): """Configuration class to store the state of bools for different scripts access""" @@ -99,9 +104,8 @@ class Config(metaclass=Singleton): self.message_dir = os.getenv("MESSAGE_HISTORY_DIR", "../../message") ### The associated configuration parameters of the plug-in control the loading and use of the plug-in - from auto_gpt_plugin_template import AutoGPTPluginTemplate - self.plugins: List[AutoGPTPluginTemplate] = [] + self.plugins: List["AutoGPTPluginTemplate"] = [] self.plugins_openai = [] self.plugins_auto_load = os.getenv("AUTO_LOAD_PLUGIN", "True") == "True" @@ -189,9 +193,7 @@ class Config(metaclass=Singleton): ### Log level self.DBGPT_LOG_LEVEL = os.getenv("DBGPT_LOG_LEVEL", "INFO") - from pilot.component import SystemApp - - self.SYSTEM_APP: SystemApp = None + self.SYSTEM_APP: Optional["SystemApp"] = None def set_debug_mode(self, value: bool) -> None: """Set the debug mode value""" diff --git a/pilot/configs/model_config.py b/pilot/configs/model_config.py index e513cf898..c70a0912e 100644 --- a/pilot/configs/model_config.py +++ b/pilot/configs/model_config.py @@ -23,15 +23,18 @@ os.chdir(new_directory) def get_device() -> str: - import torch + try: + import torch - return ( - "cuda" - if torch.cuda.is_available() - else "mps" - if torch.backends.mps.is_available() - else "cpu" - ) + return ( + "cuda" + if torch.cuda.is_available() + else "mps" + if torch.backends.mps.is_available() + else "cpu" + ) + except ModuleNotFoundError: + return "cpu" LLM_MODEL_CONFIG = { @@ -70,8 +73,9 @@ LLM_MODEL_CONFIG = { "wizardlm-13b": os.path.join(MODEL_PATH, "WizardLM-13B-V1.2"), "llama-cpp": os.path.join(MODEL_PATH, "ggml-model-q4_0.bin"), # https://huggingface.co/internlm/internlm-chat-7b-v1_1, 7b vs 7b-v1.1: https://github.com/InternLM/InternLM/issues/288 - "internlm-7b": os.path.join(MODEL_PATH, "internlm-chat-7b-v1_1"), + "internlm-7b": os.path.join(MODEL_PATH, "internlm-chat-7b"), "internlm-7b-8k": os.path.join(MODEL_PATH, "internlm-chat-7b-8k"), + "internlm-20b": os.path.join(MODEL_PATH, "internlm-20b-chat"), } EMBEDDING_MODEL_CONFIG = { diff --git a/pilot/embedding_engine/embedding_engine.py b/pilot/embedding_engine/embedding_engine.py index 27f94eeee..77d1a6667 100644 --- a/pilot/embedding_engine/embedding_engine.py +++ b/pilot/embedding_engine/embedding_engine.py @@ -1,6 +1,5 @@ from typing import Optional -from chromadb.errors import NotEnoughElementsException from langchain.text_splitter import TextSplitter from pilot.embedding_engine.embedding_factory import ( @@ -69,10 +68,10 @@ class EmbeddingEngine: vector_client = VectorStoreConnector( self.vector_store_config["vector_store_type"], self.vector_store_config ) - try: - ans = vector_client.similar_search(text, topk) - except NotEnoughElementsException: - ans = vector_client.similar_search(text, 1) + # https://github.com/chroma-core/chroma/issues/657 + ans = vector_client.similar_search(text, topk) + # except NotEnoughElementsException: + # ans = vector_client.similar_search(text, 1) return ans def vector_exist(self): diff --git a/pilot/embedding_engine/markdown_embedding.py b/pilot/embedding_engine/markdown_embedding.py index 946b13a89..1adb732bf 100644 --- a/pilot/embedding_engine/markdown_embedding.py +++ b/pilot/embedding_engine/markdown_embedding.py @@ -1,6 +1,5 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -import os from typing import List, Optional import markdown diff --git a/pilot/embedding_engine/source_embedding.py b/pilot/embedding_engine/source_embedding.py index 36df75b19..24bae97b2 100644 --- a/pilot/embedding_engine/source_embedding.py +++ b/pilot/embedding_engine/source_embedding.py @@ -3,7 +3,6 @@ from abc import ABC, abstractmethod from typing import Dict, List, Optional -from chromadb.errors import NotEnoughElementsException from langchain.text_splitter import TextSplitter from pilot.vector_store.connector import VectorStoreConnector @@ -71,10 +70,9 @@ class SourceEmbedding(ABC): self.vector_client = VectorStoreConnector( self.vector_store_config["vector_store_type"], self.vector_store_config ) - try: - ans = self.vector_client.similar_search(doc, topk) - except NotEnoughElementsException: - ans = self.vector_client.similar_search(doc, 1) + # https://github.com/chroma-core/chroma/issues/657 + ans = self.vector_client.similar_search(doc, topk) + # ans = self.vector_client.similar_search(doc, 1) return ans def vector_name_exist(self): diff --git a/pilot/model/cluster/worker/default_worker.py b/pilot/model/cluster/worker/default_worker.py index cb7686566..2078c55e7 100644 --- a/pilot/model/cluster/worker/default_worker.py +++ b/pilot/model/cluster/worker/default_worker.py @@ -1,5 +1,4 @@ import logging -import platform from typing import Dict, Iterator, List from pilot.configs.model_config import get_device @@ -12,7 +11,7 @@ from pilot.server.chat_adapter import get_llm_chat_adapter, BaseChatAdpter from pilot.utils.model_utils import _clear_torch_cache from pilot.utils.parameter_utils import EnvArgumentParser -logger = logging.getLogger("model_worker") +logger = logging.getLogger(__name__) class DefaultModelWorker(ModelWorker): @@ -91,8 +90,13 @@ class DefaultModelWorker(ModelWorker): _clear_torch_cache(self._model_params.device) def generate_stream(self, params: Dict) -> Iterator[ModelOutput]: - import torch + torch_imported = False + try: + import torch + torch_imported = True + except ImportError: + pass try: # params adaptation params, model_context = self.llm_chat_adapter.model_adaptation( @@ -117,16 +121,17 @@ class DefaultModelWorker(ModelWorker): ) yield model_output print(f"\n\nfull stream output:\n{previous_response}") - except torch.cuda.CudaError: - model_output = ModelOutput( - text="**GPU OutOfMemory, Please Refresh.**", error_code=0 - ) - yield model_output except Exception as e: - model_output = ModelOutput( - text=f"**LLMServer Generate Error, Please CheckErrorInfo.**: {e}", - error_code=0, - ) + # Check if the exception is a torch.cuda.CudaError and if torch was imported. + if torch_imported and isinstance(e, torch.cuda.CudaError): + model_output = ModelOutput( + text="**GPU OutOfMemory, Please Refresh.**", error_code=0 + ) + else: + model_output = ModelOutput( + text=f"**LLMServer Generate Error, Please CheckErrorInfo.**: {e}", + error_code=0, + ) yield model_output def generate(self, params: Dict) -> ModelOutput: diff --git a/pilot/model/cluster/worker/manager.py b/pilot/model/cluster/worker/manager.py index 2576c6a21..49c582a07 100644 --- a/pilot/model/cluster/worker/manager.py +++ b/pilot/model/cluster/worker/manager.py @@ -5,6 +5,7 @@ import os import sys import random import time +import logging from concurrent.futures import ThreadPoolExecutor from dataclasses import asdict from typing import Awaitable, Callable, Dict, Iterator, List, Optional @@ -12,7 +13,6 @@ from typing import Awaitable, Callable, Dict, Iterator, List, Optional from fastapi import APIRouter, FastAPI from fastapi.responses import StreamingResponse from pilot.component import SystemApp -from pilot.configs.model_config import LOGDIR from pilot.model.base import ( ModelInstance, ModelOutput, @@ -30,15 +30,13 @@ from pilot.model.cluster.manager_base import ( WorkerManagerFactory, ) from pilot.model.cluster.base import * -from pilot.utils import build_logger from pilot.utils.parameter_utils import ( EnvArgumentParser, ParameterDescription, _dict_to_command_args, ) -logger = build_logger("model_worker", LOGDIR + "/model_worker.log") - +logger = logging.getLogger(__name__) RegisterFunc = Callable[[WorkerRunData], Awaitable[None]] DeregisterFunc = Callable[[WorkerRunData], Awaitable[None]] diff --git a/pilot/model/proxy/llms/bard.py b/pilot/model/proxy/llms/bard.py index 7590547f9..4903c6ab0 100644 --- a/pilot/model/proxy/llms/bard.py +++ b/pilot/model/proxy/llms/bard.py @@ -1,4 +1,3 @@ -import bardapi import requests from typing import List from pilot.scene.base_message import ModelMessage, ModelMessageRoleType @@ -52,6 +51,8 @@ def bard_generate_stream( else: yield f"bard proxy url request failed!, response = {str(response)}" else: + import bardapi + response = bardapi.core.Bard(proxy_api_key).get_answer("\n".join(msgs)) if response is not None and response.get("content") is not None: diff --git a/pilot/scene/chat_data/chat_excel/excel_learning/chat.py b/pilot/scene/chat_data/chat_excel/excel_learning/chat.py index 96338589c..c7eb82584 100644 --- a/pilot/scene/chat_data/chat_excel/excel_learning/chat.py +++ b/pilot/scene/chat_data/chat_excel/excel_learning/chat.py @@ -10,9 +10,6 @@ from pilot.scene.base_chat import BaseChat from pilot.scene.base import ChatScene from pilot.common.sql_database import Database from pilot.configs.config import Config -from pilot.common.markdown_text import ( - generate_htm_table, -) from pilot.scene.chat_data.chat_excel.excel_learning.prompt import prompt from pilot.scene.chat_data.chat_excel.excel_reader import ExcelReader from pilot.json_utils.utilities import DateTimeEncoder diff --git a/pilot/scene/chat_knowledge/v1/chat.py b/pilot/scene/chat_knowledge/v1/chat.py index 3b9bacb99..230ae1523 100644 --- a/pilot/scene/chat_knowledge/v1/chat.py +++ b/pilot/scene/chat_knowledge/v1/chat.py @@ -1,7 +1,5 @@ from typing import Dict -from chromadb.errors import NoIndexException - from pilot.scene.base_chat import BaseChat from pilot.scene.base import ChatScene from pilot.configs.config import Config @@ -59,22 +57,19 @@ class ChatKnowledge(BaseChat): ) def generate_input_values(self): - try: - if self.space_context: - self.prompt_template.template_define = self.space_context["prompt"][ - "scene" - ] - self.prompt_template.template = self.space_context["prompt"]["template"] - docs = self.knowledge_embedding_client.similar_search( - self.current_user_input, self.top_k - ) - context = [d.page_content for d in docs] - context = context[: self.max_token] - input_values = {"context": context, "question": self.current_user_input} - except NoIndexException: + if self.space_context: + self.prompt_template.template_define = self.space_context["prompt"]["scene"] + self.prompt_template.template = self.space_context["prompt"]["template"] + docs = self.knowledge_embedding_client.similar_search( + self.current_user_input, self.top_k + ) + if not docs: raise ValueError( "you have no knowledge space, please add your knowledge space" ) + context = [d.page_content for d in docs] + context = context[: self.max_token] + input_values = {"context": context, "question": self.current_user_input} return input_values @property diff --git a/pilot/server/knowledge/_cli/knowledge_cli.py b/pilot/server/knowledge/_cli/knowledge_cli.py index e970ec1e6..9e9640dd5 100644 --- a/pilot/server/knowledge/_cli/knowledge_cli.py +++ b/pilot/server/knowledge/_cli/knowledge_cli.py @@ -71,7 +71,7 @@ def load( skip_wrong_doc: bool, max_workers: int, ): - """Load you local knowledge to DB-GPT""" + """Load your local knowledge to DB-GPT""" from pilot.server.knowledge._cli.knowledge_client import knowledge_init knowledge_init( diff --git a/pilot/server/static/_next/static/chunks/79.e75d7ee2dd885405.js b/pilot/server/static/_next/static/chunks/79.e75d7ee2dd885405.js index f225f6f03..86d078b37 100644 --- a/pilot/server/static/_next/static/chunks/79.e75d7ee2dd885405.js +++ b/pilot/server/static/_next/static/chunks/79.e75d7ee2dd885405.js @@ -1 +1 @@ -(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[79],{39156:function(e,l,a){"use strict";a.d(l,{Z:function(){return x}});var n=a(85893),t=a(41118),c=a(30208),r=a(40911),s=a(75227),i=a(67294);function o(e){let{chart:l}=e,a=(0,i.useRef)(null),o=(0,i.useRef)({chart:null});return(0,i.useEffect)(()=>{a.current&&(o.current.chart&&o.current.chart.destroy(),o.current.chart=new s.sg(a.current,{data:l.values,xField:"name",yField:"value",seriesField:"type",legend:{position:"bottom"},animation:{appear:{animation:"wave-in",duration:3e3}}}),o.current.chart.render())},[l.values]),(0,n.jsx)("div",{className:"flex-1 min-w-0",children:(0,n.jsx)(t.Z,{className:"h-full",sx:{background:"transparent"},children:(0,n.jsxs)(c.Z,{className:"h-full",children:[(0,n.jsx)(r.ZP,{gutterBottom:!0,component:"div",children:l.chart_name}),(0,n.jsx)(r.ZP,{gutterBottom:!0,level:"body3",children:l.chart_desc}),(0,n.jsx)("div",{className:"h-[300px]",ref:a})]})})})}function d(e){let{chart:l}=e,a=(0,i.useRef)(null),o=(0,i.useRef)({chart:null});return(0,i.useEffect)(()=>{a.current&&(o.current.chart&&o.current.chart.destroy(),o.current.chart=new s.x1(a.current,{data:l.values,xField:"name",yField:"value",seriesField:"type",smooth:!0,area:{style:{fillOpacity:.15}},legend:{position:"bottom"},animation:{appear:{animation:"wave-in",duration:3e3}}}),o.current.chart.render())},[l.values]),(0,n.jsx)("div",{className:"flex-1 min-w-0",children:(0,n.jsx)(t.Z,{className:"h-full",sx:{background:"transparent"},children:(0,n.jsxs)(c.Z,{className:"h-full",children:[(0,n.jsx)(r.ZP,{gutterBottom:!0,component:"div",children:l.chart_name}),(0,n.jsx)(r.ZP,{gutterBottom:!0,level:"body3",children:l.chart_desc}),(0,n.jsx)("div",{className:"h-[300px]",ref:a})]})})})}var u=a(61685),m=a(96486);function h(e){var l,a;let{chart:s}=e,i=(0,m.groupBy)(s.values,"type");return(0,n.jsx)("div",{className:"flex-1 min-w-0",children:(0,n.jsx)(t.Z,{className:"h-full overflow-auto",sx:{background:"transparent"},children:(0,n.jsxs)(c.Z,{className:"h-full",children:[(0,n.jsx)(r.ZP,{gutterBottom:!0,component:"div",children:s.chart_name}),"\xb7",(0,n.jsx)(r.ZP,{gutterBottom:!0,level:"body3",children:s.chart_desc}),(0,n.jsx)("div",{className:"flex-1",children:(0,n.jsxs)(u.Z,{"aria-label":"basic table",stripe:"odd",hoverRow:!0,borderAxis:"bothBetween",children:[(0,n.jsx)("thead",{children:(0,n.jsx)("tr",{children:Object.keys(i).map(e=>(0,n.jsx)("th",{children:e},e))})}),(0,n.jsx)("tbody",{children:null===(l=Object.values(i))||void 0===l?void 0:null===(a=l[0])||void 0===a?void 0:a.map((e,l)=>{var a;return(0,n.jsx)("tr",{children:null===(a=Object.keys(i))||void 0===a?void 0:a.map(e=>{var a;return(0,n.jsx)("td",{children:(null==i?void 0:null===(a=i[e])||void 0===a?void 0:a[l].value)||""},e)})},l)})})]})})]})})})}var x=function(e){let{chartsData:l}=e,a=(0,i.useMemo)(()=>{if(l){let e=[],a=null==l?void 0:l.filter(e=>"IndicatorValue"===e.chart_type);a.length>0&&e.push({charts:a,type:"IndicatorValue"});let n=null==l?void 0:l.filter(e=>"IndicatorValue"!==e.chart_type),t=n.length,c=0;return[[0],[1],[2],[1,2],[1,3],[2,1,2],[2,1,3],[3,1,3],[3,2,3]][t].forEach(l=>{if(l>0){let a=n.slice(c,c+l);c+=l,e.push({charts:a})}}),e}},[l]);return(0,n.jsx)(n.Fragment,{children:l&&(0,n.jsx)("div",{className:"w-full",children:(0,n.jsx)("div",{className:"flex flex-col gap-3 h-full",children:null==a?void 0:a.map((e,l)=>(0,n.jsx)("div",{className:"".concat((null==e?void 0:e.type)!=="IndicatorValue"?"flex gap-3":""),children:e.charts.map(e=>"IndicatorValue"===e.chart_type?(0,n.jsx)("div",{className:"flex flex-row gap-3",children:e.values.map(e=>(0,n.jsx)("div",{className:"flex-1",children:(0,n.jsx)(t.Z,{sx:{background:"transparent"},children:(0,n.jsxs)(c.Z,{className:"justify-around",children:[(0,n.jsx)(r.ZP,{gutterBottom:!0,component:"div",children:e.name}),(0,n.jsx)(r.ZP,{children:e.value})]})})},e.name))},e.chart_uid):"LineChart"===e.chart_type?(0,n.jsx)(d,{chart:e},e.chart_uid):"BarChart"===e.chart_type?(0,n.jsx)(o,{chart:e},e.chart_uid):"Table"===e.chart_type?(0,n.jsx)(h,{chart:e},e.chart_uid):void 0)},"chart_row_".concat(l)))})})})}},79716:function(e,l,a){"use strict";a.d(l,{Z:function(){return j}});var n=a(85893),t=a(67294),c=a(2453),r=a(39778),s=a(66803),i=a(71577),o=a(49591),d=a(88484),u=a(29158),m=a(50489),h=a(41468),x=function(e){var l;let{convUid:a,chatMode:x,onComplete:p,...b}=e,[g,v]=(0,t.useState)(!1),[f,j]=c.ZP.useMessage(),[y,_]=(0,t.useState)([]),[w,N]=(0,t.useState)(),[Z,C]=(0,t.useState)(),{model:P}=(0,t.useContext)(h.p),k=async e=>{var l;if(!e){c.ZP.error("Please select the *.(csv|xlsx|xls) file");return}if(!/\.(csv|xlsx|xls)$/.test(null!==(l=e.file.name)&&void 0!==l?l:"")){c.ZP.error("File type must be csv, xlsx or xls");return}_([e.file])},B=async()=>{v(!0),C("normal");try{let e=new FormData;e.append("doc_file",y[0]),f.open({content:"Uploading ".concat(y[0].name),type:"loading",duration:0});let[l]=await (0,m.Vx)((0,m.qn)({convUid:a,chatMode:x,data:e,model:P,config:{timeout:36e5,onUploadProgress:e=>{let l=Math.ceil(e.loaded/(e.total||0)*100);N(l)}}}));if(l)return;c.ZP.success("success"),C("success"),null==p||p()}catch(e){C("exception"),c.ZP.error((null==e?void 0:e.message)||"Upload Error")}finally{v(!1),f.destroy()}};return(0,n.jsx)(n.Fragment,{children:(0,n.jsxs)("div",{className:"flex items-start gap-2",children:[j,(0,n.jsx)(r.Z,{placement:"topLeft",title:"Files cannot be changed after upload",children:(0,n.jsx)(s.default,{disabled:g,className:"mr-1",beforeUpload:()=>!1,fileList:y,name:"file",accept:".csv,.xlsx,.xls",multiple:!1,onChange:k,showUploadList:{showDownloadIcon:!1,showPreviewIcon:!1,showRemoveIcon:!1},itemRender:()=>(0,n.jsx)(n.Fragment,{}),...b,children:(0,n.jsx)(i.ZP,{className:"flex justify-center items-center dark:bg-[#4e4f56] dark:text-gray-200",disabled:g,icon:(0,n.jsx)(o.Z,{}),children:"Select File"})})}),(0,n.jsx)(i.ZP,{type:"primary",loading:g,className:"flex justify-center items-center dark:text-white",disabled:!y.length,icon:(0,n.jsx)(d.Z,{}),onClick:B,children:g?100===w?"Analysis":"Uploading":"Upload"}),!!y.length&&(0,n.jsxs)("div",{className:"mt-2 text-gray-500 text-sm flex items-center",children:[(0,n.jsx)(u.Z,{className:"mr-2"}),(0,n.jsx)("span",{children:null===(l=y[0])||void 0===l?void 0:l.name})]})]})})},p=function(e){let{onComplete:l}=e,{currentDialogue:a,scene:c,chatId:r}=(0,t.useContext)(h.p);return"chat_excel"!==c?null:(0,n.jsx)("div",{className:"max-w-md h-full relative",children:a?(0,n.jsxs)("div",{className:"flex overflow-hidden rounded",children:[(0,n.jsx)("div",{className:"flex items-center justify-center px-3 py-2 bg-gray-600",children:(0,n.jsx)(u.Z,{className:"text-white"})}),(0,n.jsx)("div",{className:"bg-gray-100 px-3 py-2 text-xs rounded-tr rounded-br dark:text-gray-800 truncate",children:a.select_param})]}):(0,n.jsx)(x,{convUid:r,chatMode:c,onComplete:l})})},b=a(25709),g=a(43927);function v(){let{isContract:e,setIsContract:l,scene:a}=(0,t.useContext)(h.p),c=a&&["chat_with_db_execute","chat_dashboard"].includes(a);return c?(0,n.jsx)("div",{className:"leading-[3rem] text-right h-12 flex justify-center",children:(0,n.jsx)("div",{className:"flex items-center cursor-pointer",children:(0,n.jsxs)("div",{className:"relative w-56 h-10 mx-auto p-2 flex justify-center items-center bg-[#ece9e0] rounded-3xl model-tab dark:text-violet-600 z-10 ".concat(e?"editor-tab":""),children:[(0,n.jsxs)("div",{className:"z-10 w-[50%] text-center cursor-pointer",onClick:()=>{l(!1)},children:[(0,n.jsx)("span",{children:"Preview"}),(0,n.jsx)(g.Z,{className:"ml-1"})]}),(0,n.jsxs)("div",{className:"z-10 w-[50%] text-center cursor-pointer",onClick:()=>{l(!0)},children:[(0,n.jsx)("span",{children:"Editor"}),(0,n.jsx)(b.Z,{className:"ml-1"})]})]})})}):null}a(23293);var f=a(81799),j=function(e){let{refreshHistory:l,modelChange:a}=e,{refreshDialogList:c,model:r}=(0,t.useContext)(h.p);return(0,n.jsxs)("div",{className:"w-full py-4 flex items-center justify-center border-b border-gray-100 gap-5",children:[(0,n.jsx)(f.Z,{size:"sm",onChange:a}),(0,n.jsx)(p,{onComplete:()=>{null==c||c(),null==l||l()}}),(0,n.jsx)(v,{})]})}},81799:function(e,l,a){"use strict";a.d(l,{A:function(){return x}});var n=a(85893),t=a(41468),c=a(14986),r=a(30322),s=a(94184),i=a.n(s),o=a(25675),d=a.n(o),u=a(67294),m=a(67421);let h={proxyllm:{label:"Proxy LLM",icon:"/models/chatgpt.png"},"flan-t5-base":{label:"flan-t5-base",icon:"/models/google.png"},"vicuna-13b":{label:"vicuna-13b",icon:"/models/vicuna.jpeg"},"vicuna-7b":{label:"vicuna-7b",icon:"/models/vicuna.jpeg"},"vicuna-13b-v1.5":{label:"vicuna-13b-v1.5",icon:"/models/vicuna.jpeg"},"vicuna-7b-v1.5":{label:"vicuna-7b-v1.5",icon:"/models/vicuna.jpeg"},"codegen2-1b":{label:"codegen2-1B",icon:"/models/vicuna.jpeg"},"codet5p-2b":{label:"codet5p-2b",icon:"/models/vicuna.jpeg"},"chatglm-6b-int4":{label:"chatglm-6b-int4",icon:"/models/chatglm.png"},"chatglm-6b":{label:"chatglm-6b",icon:"/models/chatglm.png"},"chatglm2-6b":{label:"chatglm2-6b",icon:"/models/chatglm.png"},"chatglm2-6b-int4":{label:"chatglm2-6b-int4",icon:"/models/chatglm.png"},"guanaco-33b-merged":{label:"guanaco-33b-merged",icon:"/models/huggingface.svg"},"falcon-40b":{label:"falcon-40b",icon:"/models/falcon.jpeg"},"gorilla-7b":{label:"gorilla-7b",icon:"/models/gorilla.png"},"gptj-6b":{label:"ggml-gpt4all-j-v1.3-groovy.bin",icon:""},chatgpt_proxyllm:{label:"chatgpt_proxyllm",icon:"/models/chatgpt.png"},bard_proxyllm:{label:"bard_proxyllm",icon:"/models/bard.gif"},claude_proxyllm:{label:"claude_proxyllm",icon:"/models/claude.png"},wenxin_proxyllm:{label:"wenxin_proxyllm",icon:""},tongyi_proxyllm:{label:"tongyi_proxyllm",icon:"/models/qwen2.png"},zhipu_proxyllm:{label:"zhipu_proxyllm",icon:"/models/zhipu.png"},"llama-2-7b":{label:"Llama-2-7b-chat-hf",icon:"/models/llama.jpg"},"llama-2-13b":{label:"Llama-2-13b-chat-hf",icon:"/models/llama.jpg"},"llama-2-70b":{label:"Llama-2-70b-chat-hf",icon:"/models/llama.jpg"},"baichuan-13b":{label:"Baichuan-13B-Chat",icon:"/models/baichuan.png"},"baichuan-7b":{label:"baichuan-7b",icon:"/models/baichuan.png"},"baichuan2-7b":{label:"Baichuan2-7B-Chat",icon:"/models/baichuan.png"},"baichuan2-13b":{label:"Baichuan2-13B-Chat",icon:"/models/baichuan.png"},"wizardlm-13b":{label:"WizardLM-13B-V1.2",icon:"/models/wizardlm.png"},"llama-cpp":{label:"ggml-model-q4_0.bin",icon:"/models/huggingface.svg"}};function x(e){var l;return e?(0,n.jsx)(d(),{className:"rounded-full mr-2 border border-gray-200 object-contain bg-white",width:24,height:24,src:null===(l=h[e])||void 0===l?void 0:l.icon,alt:"llm"}):null}l.Z=function(e){let{size:l,onChange:a}=e,{t:s}=(0,m.$G)(),{modelList:o,model:d,scene:p}=(0,u.useContext)(t.p);return!o||o.length<=0?null:(0,n.jsx)("div",{className:i()({"w-48":"sm"===l||"md"===l||!l,"w-60":"lg"===l}),children:(0,n.jsx)(c.Z,{size:l||"sm",placeholder:s("choose_model"),value:d||"",renderValue:function(e){return e?(0,n.jsxs)(n.Fragment,{children:[x(e.value),e.label]}):null},onChange:(e,l)=>{l&&(null==a||a(l))},children:o.map(e=>{var l;return(0,n.jsxs)(r.Z,{value:e,children:[x(e),(null===(l=h[e])||void 0===l?void 0:l.label)||e]},"model_".concat(e))})})})}},99513:function(e,l,a){"use strict";a.d(l,{Z:function(){return o}});var n=a(85893),t=a(63764),c=a(94184),r=a.n(c),s=a(67294),i=a(36782);function o(e){let{className:l,value:a,language:c="mysql",onChange:o,thoughts:d}=e,u=(0,s.useMemo)(()=>"mysql"!==c?a:d&&d.length>0?(0,i.WU)("-- ".concat(d," \n").concat(a)):(0,i.WU)(a),[a,d]);return(0,n.jsx)(t.ZP,{className:r()(l),value:u,language:c,onChange:o,theme:"vs-dark",options:{minimap:{enabled:!1},wordWrap:"on"}})}},23293:function(){}}]); \ No newline at end of file +(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[79],{39156:function(e,l,a){"use strict";a.d(l,{Z:function(){return x}});var n=a(85893),t=a(41118),c=a(30208),r=a(40911),s=a(75227),i=a(67294);function o(e){let{chart:l}=e,a=(0,i.useRef)(null),o=(0,i.useRef)({chart:null});return(0,i.useEffect)(()=>{a.current&&(o.current.chart&&o.current.chart.destroy(),o.current.chart=new s.sg(a.current,{data:l.values,xField:"name",yField:"value",seriesField:"type",legend:{position:"bottom"},animation:{appear:{animation:"wave-in",duration:3e3}}}),o.current.chart.render())},[l.values]),(0,n.jsx)("div",{className:"flex-1 min-w-0",children:(0,n.jsx)(t.Z,{className:"h-full",sx:{background:"transparent"},children:(0,n.jsxs)(c.Z,{className:"h-full",children:[(0,n.jsx)(r.ZP,{gutterBottom:!0,component:"div",children:l.chart_name}),(0,n.jsx)(r.ZP,{gutterBottom:!0,level:"body3",children:l.chart_desc}),(0,n.jsx)("div",{className:"h-[300px]",ref:a})]})})})}function d(e){let{chart:l}=e,a=(0,i.useRef)(null),o=(0,i.useRef)({chart:null});return(0,i.useEffect)(()=>{a.current&&(o.current.chart&&o.current.chart.destroy(),o.current.chart=new s.x1(a.current,{data:l.values,xField:"name",yField:"value",seriesField:"type",smooth:!0,area:{style:{fillOpacity:.15}},legend:{position:"bottom"},animation:{appear:{animation:"wave-in",duration:3e3}}}),o.current.chart.render())},[l.values]),(0,n.jsx)("div",{className:"flex-1 min-w-0",children:(0,n.jsx)(t.Z,{className:"h-full",sx:{background:"transparent"},children:(0,n.jsxs)(c.Z,{className:"h-full",children:[(0,n.jsx)(r.ZP,{gutterBottom:!0,component:"div",children:l.chart_name}),(0,n.jsx)(r.ZP,{gutterBottom:!0,level:"body3",children:l.chart_desc}),(0,n.jsx)("div",{className:"h-[300px]",ref:a})]})})})}var u=a(61685),m=a(96486);function h(e){var l,a;let{chart:s}=e,i=(0,m.groupBy)(s.values,"type");return(0,n.jsx)("div",{className:"flex-1 min-w-0",children:(0,n.jsx)(t.Z,{className:"h-full overflow-auto",sx:{background:"transparent"},children:(0,n.jsxs)(c.Z,{className:"h-full",children:[(0,n.jsx)(r.ZP,{gutterBottom:!0,component:"div",children:s.chart_name}),"\xb7",(0,n.jsx)(r.ZP,{gutterBottom:!0,level:"body3",children:s.chart_desc}),(0,n.jsx)("div",{className:"flex-1",children:(0,n.jsxs)(u.Z,{"aria-label":"basic table",stripe:"odd",hoverRow:!0,borderAxis:"bothBetween",children:[(0,n.jsx)("thead",{children:(0,n.jsx)("tr",{children:Object.keys(i).map(e=>(0,n.jsx)("th",{children:e},e))})}),(0,n.jsx)("tbody",{children:null===(l=Object.values(i))||void 0===l?void 0:null===(a=l[0])||void 0===a?void 0:a.map((e,l)=>{var a;return(0,n.jsx)("tr",{children:null===(a=Object.keys(i))||void 0===a?void 0:a.map(e=>{var a;return(0,n.jsx)("td",{children:(null==i?void 0:null===(a=i[e])||void 0===a?void 0:a[l].value)||""},e)})},l)})})]})})]})})})}var x=function(e){let{chartsData:l}=e,a=(0,i.useMemo)(()=>{if(l){let e=[],a=null==l?void 0:l.filter(e=>"IndicatorValue"===e.chart_type);a.length>0&&e.push({charts:a,type:"IndicatorValue"});let n=null==l?void 0:l.filter(e=>"IndicatorValue"!==e.chart_type),t=n.length,c=0;return[[0],[1],[2],[1,2],[1,3],[2,1,2],[2,1,3],[3,1,3],[3,2,3]][t].forEach(l=>{if(l>0){let a=n.slice(c,c+l);c+=l,e.push({charts:a})}}),e}},[l]);return(0,n.jsx)(n.Fragment,{children:l&&(0,n.jsx)("div",{className:"w-full",children:(0,n.jsx)("div",{className:"flex flex-col gap-3 h-full",children:null==a?void 0:a.map((e,l)=>(0,n.jsx)("div",{className:"".concat((null==e?void 0:e.type)!=="IndicatorValue"?"flex gap-3":""),children:e.charts.map(e=>"IndicatorValue"===e.chart_type?(0,n.jsx)("div",{className:"flex flex-row gap-3",children:e.values.map(e=>(0,n.jsx)("div",{className:"flex-1",children:(0,n.jsx)(t.Z,{sx:{background:"transparent"},children:(0,n.jsxs)(c.Z,{className:"justify-around",children:[(0,n.jsx)(r.ZP,{gutterBottom:!0,component:"div",children:e.name}),(0,n.jsx)(r.ZP,{children:e.value})]})})},e.name))},e.chart_uid):"LineChart"===e.chart_type?(0,n.jsx)(d,{chart:e},e.chart_uid):"BarChart"===e.chart_type?(0,n.jsx)(o,{chart:e},e.chart_uid):"Table"===e.chart_type?(0,n.jsx)(h,{chart:e},e.chart_uid):void 0)},"chart_row_".concat(l)))})})})}},79716:function(e,l,a){"use strict";a.d(l,{Z:function(){return j}});var n=a(85893),t=a(67294),c=a(2453),r=a(39778),s=a(66803),i=a(71577),o=a(49591),d=a(88484),u=a(29158),m=a(50489),h=a(41468),x=function(e){var l;let{convUid:a,chatMode:x,onComplete:p,...b}=e,[g,v]=(0,t.useState)(!1),[f,j]=c.ZP.useMessage(),[y,_]=(0,t.useState)([]),[w,N]=(0,t.useState)(),[Z,C]=(0,t.useState)(),{model:P}=(0,t.useContext)(h.p),k=async e=>{var l;if(!e){c.ZP.error("Please select the *.(csv|xlsx|xls) file");return}if(!/\.(csv|xlsx|xls)$/.test(null!==(l=e.file.name)&&void 0!==l?l:"")){c.ZP.error("File type must be csv, xlsx or xls");return}_([e.file])},B=async()=>{v(!0),C("normal");try{let e=new FormData;e.append("doc_file",y[0]),f.open({content:"Uploading ".concat(y[0].name),type:"loading",duration:0});let[l]=await (0,m.Vx)((0,m.qn)({convUid:a,chatMode:x,data:e,model:P,config:{timeout:36e5,onUploadProgress:e=>{let l=Math.ceil(e.loaded/(e.total||0)*100);N(l)}}}));if(l)return;c.ZP.success("success"),C("success"),null==p||p()}catch(e){C("exception"),c.ZP.error((null==e?void 0:e.message)||"Upload Error")}finally{v(!1),f.destroy()}};return(0,n.jsx)(n.Fragment,{children:(0,n.jsxs)("div",{className:"flex items-start gap-2",children:[j,(0,n.jsx)(r.Z,{placement:"topLeft",title:"Files cannot be changed after upload",children:(0,n.jsx)(s.default,{disabled:g,className:"mr-1",beforeUpload:()=>!1,fileList:y,name:"file",accept:".csv,.xlsx,.xls",multiple:!1,onChange:k,showUploadList:{showDownloadIcon:!1,showPreviewIcon:!1,showRemoveIcon:!1},itemRender:()=>(0,n.jsx)(n.Fragment,{}),...b,children:(0,n.jsx)(i.ZP,{className:"flex justify-center items-center dark:bg-[#4e4f56] dark:text-gray-200",disabled:g,icon:(0,n.jsx)(o.Z,{}),children:"Select File"})})}),(0,n.jsx)(i.ZP,{type:"primary",loading:g,className:"flex justify-center items-center dark:text-white",disabled:!y.length,icon:(0,n.jsx)(d.Z,{}),onClick:B,children:g?100===w?"Analysis":"Uploading":"Upload"}),!!y.length&&(0,n.jsxs)("div",{className:"mt-2 text-gray-500 text-sm flex items-center",children:[(0,n.jsx)(u.Z,{className:"mr-2"}),(0,n.jsx)("span",{children:null===(l=y[0])||void 0===l?void 0:l.name})]})]})})},p=function(e){let{onComplete:l}=e,{currentDialogue:a,scene:c,chatId:r}=(0,t.useContext)(h.p);return"chat_excel"!==c?null:(0,n.jsx)("div",{className:"max-w-md h-full relative",children:a?(0,n.jsxs)("div",{className:"flex overflow-hidden rounded",children:[(0,n.jsx)("div",{className:"flex items-center justify-center px-3 py-2 bg-gray-600",children:(0,n.jsx)(u.Z,{className:"text-white"})}),(0,n.jsx)("div",{className:"bg-gray-100 px-3 py-2 text-xs rounded-tr rounded-br dark:text-gray-800 truncate",children:a.select_param})]}):(0,n.jsx)(x,{convUid:r,chatMode:c,onComplete:l})})},b=a(25709),g=a(43927);function v(){let{isContract:e,setIsContract:l,scene:a}=(0,t.useContext)(h.p),c=a&&["chat_with_db_execute","chat_dashboard"].includes(a);return c?(0,n.jsx)("div",{className:"leading-[3rem] text-right h-12 flex justify-center",children:(0,n.jsx)("div",{className:"flex items-center cursor-pointer",children:(0,n.jsxs)("div",{className:"relative w-56 h-10 mx-auto p-2 flex justify-center items-center bg-[#ece9e0] rounded-3xl model-tab dark:text-violet-600 z-10 ".concat(e?"editor-tab":""),children:[(0,n.jsxs)("div",{className:"z-10 w-[50%] text-center cursor-pointer",onClick:()=>{l(!1)},children:[(0,n.jsx)("span",{children:"Preview"}),(0,n.jsx)(g.Z,{className:"ml-1"})]}),(0,n.jsxs)("div",{className:"z-10 w-[50%] text-center cursor-pointer",onClick:()=>{l(!0)},children:[(0,n.jsx)("span",{children:"Editor"}),(0,n.jsx)(b.Z,{className:"ml-1"})]})]})})}):null}a(23293);var f=a(81799),j=function(e){let{refreshHistory:l,modelChange:a}=e,{refreshDialogList:c,model:r}=(0,t.useContext)(h.p);return(0,n.jsxs)("div",{className:"w-full py-4 flex items-center justify-center border-b border-gray-100 gap-5",children:[(0,n.jsx)(f.Z,{size:"sm",onChange:a}),(0,n.jsx)(p,{onComplete:()=>{null==c||c(),null==l||l()}}),(0,n.jsx)(v,{})]})}},81799:function(e,l,a){"use strict";a.d(l,{A:function(){return x}});var n=a(85893),t=a(41468),c=a(14986),r=a(30322),s=a(94184),i=a.n(s),o=a(25675),d=a.n(o),u=a(67294),m=a(67421);let h={proxyllm:{label:"Proxy LLM",icon:"/models/chatgpt.png"},"flan-t5-base":{label:"flan-t5-base",icon:"/models/google.png"},"internlm-20b":{label:"internlm-20b",icon:"/models/internlm.jpg"},"internlm-7b":{label:"internlm-7b",icon:"/models/internlm.jpg"},"vicuna-13b":{label:"vicuna-13b",icon:"/models/vicuna.jpeg"},"vicuna-7b":{label:"vicuna-7b",icon:"/models/vicuna.jpeg"},"vicuna-13b-v1.5":{label:"vicuna-13b-v1.5",icon:"/models/vicuna.jpeg"},"vicuna-7b-v1.5":{label:"vicuna-7b-v1.5",icon:"/models/vicuna.jpeg"},"codegen2-1b":{label:"codegen2-1B",icon:"/models/vicuna.jpeg"},"codet5p-2b":{label:"codet5p-2b",icon:"/models/vicuna.jpeg"},"chatglm-6b-int4":{label:"chatglm-6b-int4",icon:"/models/chatglm.png"},"chatglm-6b":{label:"chatglm-6b",icon:"/models/chatglm.png"},"chatglm2-6b":{label:"chatglm2-6b",icon:"/models/chatglm.png"},"chatglm2-6b-int4":{label:"chatglm2-6b-int4",icon:"/models/chatglm.png"},"guanaco-33b-merged":{label:"guanaco-33b-merged",icon:"/models/huggingface.svg"},"falcon-40b":{label:"falcon-40b",icon:"/models/falcon.jpeg"},"gorilla-7b":{label:"gorilla-7b",icon:"/models/gorilla.png"},"gptj-6b":{label:"ggml-gpt4all-j-v1.3-groovy.bin",icon:""},chatgpt_proxyllm:{label:"chatgpt_proxyllm",icon:"/models/chatgpt.png"},bard_proxyllm:{label:"bard_proxyllm",icon:"/models/bard.gif"},claude_proxyllm:{label:"claude_proxyllm",icon:"/models/claude.png"},wenxin_proxyllm:{label:"wenxin_proxyllm",icon:""},tongyi_proxyllm:{label:"tongyi_proxyllm",icon:"/models/qwen2.png"},zhipu_proxyllm:{label:"zhipu_proxyllm",icon:"/models/zhipu.png"},"llama-2-7b":{label:"Llama-2-7b-chat-hf",icon:"/models/llama.jpg"},"llama-2-13b":{label:"Llama-2-13b-chat-hf",icon:"/models/llama.jpg"},"llama-2-70b":{label:"Llama-2-70b-chat-hf",icon:"/models/llama.jpg"},"baichuan-13b":{label:"Baichuan-13B-Chat",icon:"/models/baichuan.png"},"baichuan-7b":{label:"baichuan-7b",icon:"/models/baichuan.png"},"baichuan2-7b":{label:"Baichuan2-7B-Chat",icon:"/models/baichuan.png"},"baichuan2-13b":{label:"Baichuan2-13B-Chat",icon:"/models/baichuan.png"},"wizardlm-13b":{label:"WizardLM-13B-V1.2",icon:"/models/wizardlm.png"},"llama-cpp":{label:"ggml-model-q4_0.bin",icon:"/models/huggingface.svg"}};function x(e){var l;return e?(0,n.jsx)(d(),{className:"rounded-full mr-2 border border-gray-200 object-contain bg-white",width:24,height:24,src:null===(l=h[e])||void 0===l?void 0:l.icon,alt:"llm"}):null}l.Z=function(e){let{size:l,onChange:a}=e,{t:s}=(0,m.$G)(),{modelList:o,model:d,scene:p}=(0,u.useContext)(t.p);return!o||o.length<=0?null:(0,n.jsx)("div",{className:i()({"w-48":"sm"===l||"md"===l||!l,"w-60":"lg"===l}),children:(0,n.jsx)(c.Z,{size:l||"sm",placeholder:s("choose_model"),value:d||"",renderValue:function(e){return e?(0,n.jsxs)(n.Fragment,{children:[x(e.value),e.label]}):null},onChange:(e,l)=>{l&&(null==a||a(l))},children:o.map(e=>{var l;return(0,n.jsxs)(r.Z,{value:e,children:[x(e),(null===(l=h[e])||void 0===l?void 0:l.label)||e]},"model_".concat(e))})})})}},99513:function(e,l,a){"use strict";a.d(l,{Z:function(){return o}});var n=a(85893),t=a(63764),c=a(94184),r=a.n(c),s=a(67294),i=a(36782);function o(e){let{className:l,value:a,language:c="mysql",onChange:o,thoughts:d}=e,u=(0,s.useMemo)(()=>"mysql"!==c?a:d&&d.length>0?(0,i.WU)("-- ".concat(d," \n").concat(a)):(0,i.WU)(a),[a,d]);return(0,n.jsx)(t.ZP,{className:r()(l),value:u,language:c,onChange:o,theme:"vs-dark",options:{minimap:{enabled:!1},wordWrap:"on"}})}},23293:function(){}}]); \ No newline at end of file diff --git a/pilot/server/static/_next/static/chunks/pages/index-d5aba6bbbc1d8aaa.js b/pilot/server/static/_next/static/chunks/pages/index-d5aba6bbbc1d8aaa.js index dcc69dc08..c69568af9 100644 --- a/pilot/server/static/_next/static/chunks/pages/index-d5aba6bbbc1d8aaa.js +++ b/pilot/server/static/_next/static/chunks/pages/index-d5aba6bbbc1d8aaa.js @@ -1 +1 @@ -(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[405],{52254:function(i,e,l){"use strict";l.d(e,{Z:function(){return f}});var a=l(63366),n=l(87462),o=l(67294),t=l(86010),r=l(14142),c=l(94780),s=l(74312),d=l(20407),m=l(26821);function v(i){return(0,m.d6)("MuiDivider",i)}(0,m.sI)("MuiDivider",["root","horizontal","vertical","insetContext","insetNone"]);var u=l(30220),g=l(85893);let h=["className","children","component","inset","orientation","role","slots","slotProps"],b=i=>{let{orientation:e,inset:l}=i,a={root:["root",e,l&&`inset${(0,r.Z)(l)}`]};return(0,c.Z)(a,v,{})},p=(0,s.Z)("hr",{name:"JoyDivider",slot:"Root",overridesResolver:(i,e)=>e.root})(({theme:i,ownerState:e})=>(0,n.Z)({"--Divider-thickness":"1px","--Divider-lineColor":i.vars.palette.divider},"none"===e.inset&&{"--_Divider-inset":"0px"},"context"===e.inset&&{"--_Divider-inset":"var(--Divider-inset, 0px)"},{margin:"initial",marginInline:"vertical"===e.orientation?"initial":"var(--_Divider-inset)",marginBlock:"vertical"===e.orientation?"var(--_Divider-inset)":"initial",position:"relative",alignSelf:"stretch",flexShrink:0},e.children?{"--Divider-gap":i.spacing(1),"--Divider-childPosition":"50%",display:"flex",flexDirection:"vertical"===e.orientation?"column":"row",alignItems:"center",whiteSpace:"nowrap",textAlign:"center",border:0,fontFamily:i.vars.fontFamily.body,fontSize:i.vars.fontSize.sm,"&::before, &::after":{position:"relative",inlineSize:"vertical"===e.orientation?"var(--Divider-thickness)":"initial",blockSize:"vertical"===e.orientation?"initial":"var(--Divider-thickness)",backgroundColor:"var(--Divider-lineColor)",content:'""'},"&::before":{marginInlineEnd:"vertical"===e.orientation?"initial":"min(var(--Divider-childPosition) * 999, var(--Divider-gap))",marginBlockEnd:"vertical"===e.orientation?"min(var(--Divider-childPosition) * 999, var(--Divider-gap))":"initial",flexBasis:"var(--Divider-childPosition)"},"&::after":{marginInlineStart:"vertical"===e.orientation?"initial":"min((100% - var(--Divider-childPosition)) * 999, var(--Divider-gap))",marginBlockStart:"vertical"===e.orientation?"min((100% - var(--Divider-childPosition)) * 999, var(--Divider-gap))":"initial",flexBasis:"calc(100% - var(--Divider-childPosition))"}}:{border:"none",listStyle:"none",backgroundColor:"var(--Divider-lineColor)",inlineSize:"vertical"===e.orientation?"var(--Divider-thickness)":"initial",blockSize:"vertical"===e.orientation?"initial":"var(--Divider-thickness)"})),x=o.forwardRef(function(i,e){let l=(0,d.Z)({props:i,name:"JoyDivider"}),{className:o,children:r,component:c=null!=r?"div":"hr",inset:s,orientation:m="horizontal",role:v="hr"!==c?"separator":void 0,slots:x={},slotProps:f={}}=l,y=(0,a.Z)(l,h),j=(0,n.Z)({},l,{inset:s,role:v,orientation:m,component:c}),_=b(j),D=(0,n.Z)({},y,{component:c,slots:x,slotProps:f}),[w,Z]=(0,u.Z)("root",{ref:e,className:(0,t.Z)(_.root,o),elementType:p,externalForwardedProps:D,ownerState:j,additionalProps:(0,n.Z)({as:c,role:v},"separator"===v&&"vertical"===m&&{"aria-orientation":"vertical"})});return(0,g.jsx)(w,(0,n.Z)({},Z,{children:r}))});x.muiName="Divider";var f=x},76043:function(i,e,l){"use strict";var a=l(67294);let n=a.createContext(void 0);e.Z=n},48312:function(i,e,l){(window.__NEXT_P=window.__NEXT_P||[]).push(["/",function(){return l(57464)}])},81799:function(i,e,l){"use strict";l.d(e,{A:function(){return g}});var a=l(85893),n=l(41468),o=l(14986),t=l(30322),r=l(94184),c=l.n(r),s=l(25675),d=l.n(s),m=l(67294),v=l(67421);let u={proxyllm:{label:"Proxy LLM",icon:"/models/chatgpt.png"},"flan-t5-base":{label:"flan-t5-base",icon:"/models/google.png"},"vicuna-13b":{label:"vicuna-13b",icon:"/models/vicuna.jpeg"},"vicuna-7b":{label:"vicuna-7b",icon:"/models/vicuna.jpeg"},"vicuna-13b-v1.5":{label:"vicuna-13b-v1.5",icon:"/models/vicuna.jpeg"},"vicuna-7b-v1.5":{label:"vicuna-7b-v1.5",icon:"/models/vicuna.jpeg"},"codegen2-1b":{label:"codegen2-1B",icon:"/models/vicuna.jpeg"},"codet5p-2b":{label:"codet5p-2b",icon:"/models/vicuna.jpeg"},"chatglm-6b-int4":{label:"chatglm-6b-int4",icon:"/models/chatglm.png"},"chatglm-6b":{label:"chatglm-6b",icon:"/models/chatglm.png"},"chatglm2-6b":{label:"chatglm2-6b",icon:"/models/chatglm.png"},"chatglm2-6b-int4":{label:"chatglm2-6b-int4",icon:"/models/chatglm.png"},"guanaco-33b-merged":{label:"guanaco-33b-merged",icon:"/models/huggingface.svg"},"falcon-40b":{label:"falcon-40b",icon:"/models/falcon.jpeg"},"gorilla-7b":{label:"gorilla-7b",icon:"/models/gorilla.png"},"gptj-6b":{label:"ggml-gpt4all-j-v1.3-groovy.bin",icon:""},chatgpt_proxyllm:{label:"chatgpt_proxyllm",icon:"/models/chatgpt.png"},bard_proxyllm:{label:"bard_proxyllm",icon:"/models/bard.gif"},claude_proxyllm:{label:"claude_proxyllm",icon:"/models/claude.png"},wenxin_proxyllm:{label:"wenxin_proxyllm",icon:""},tongyi_proxyllm:{label:"tongyi_proxyllm",icon:"/models/qwen2.png"},zhipu_proxyllm:{label:"zhipu_proxyllm",icon:"/models/zhipu.png"},"llama-2-7b":{label:"Llama-2-7b-chat-hf",icon:"/models/llama.jpg"},"llama-2-13b":{label:"Llama-2-13b-chat-hf",icon:"/models/llama.jpg"},"llama-2-70b":{label:"Llama-2-70b-chat-hf",icon:"/models/llama.jpg"},"baichuan-13b":{label:"Baichuan-13B-Chat",icon:"/models/baichuan.png"},"baichuan-7b":{label:"baichuan-7b",icon:"/models/baichuan.png"},"baichuan2-7b":{label:"Baichuan2-7B-Chat",icon:"/models/baichuan.png"},"baichuan2-13b":{label:"Baichuan2-13B-Chat",icon:"/models/baichuan.png"},"wizardlm-13b":{label:"WizardLM-13B-V1.2",icon:"/models/wizardlm.png"},"llama-cpp":{label:"ggml-model-q4_0.bin",icon:"/models/huggingface.svg"}};function g(i){var e;return i?(0,a.jsx)(d(),{className:"rounded-full mr-2 border border-gray-200 object-contain bg-white",width:24,height:24,src:null===(e=u[i])||void 0===e?void 0:e.icon,alt:"llm"}):null}e.Z=function(i){let{size:e,onChange:l}=i,{t:r}=(0,v.$G)(),{modelList:s,model:d,scene:h}=(0,m.useContext)(n.p);return!s||s.length<=0?null:(0,a.jsx)("div",{className:c()({"w-48":"sm"===e||"md"===e||!e,"w-60":"lg"===e}),children:(0,a.jsx)(o.Z,{size:e||"sm",placeholder:r("choose_model"),value:d||"",renderValue:function(i){return i?(0,a.jsxs)(a.Fragment,{children:[g(i.value),i.label]}):null},onChange:(i,e)=>{e&&(null==l||l(e))},children:s.map(i=>{var e;return(0,a.jsxs)(t.Z,{value:i,children:[g(i),(null===(e=u[i])||void 0===e?void 0:e.label)||i]},"model_".concat(i))})})})}},57464:function(i,e,l){"use strict";l.r(e);var a=l(85893),n=l(577),o=l(67294),t=l(48665),r=l(52254),c=l(11842),s=l(47556),d=l(75913),m=l(14553),v=l(24339),u=l(87536),g=l(39332),h=l(25675),b=l.n(h),p=l(50489),x=l(81799),f=l(41468);e.default=()=>{let i=(0,g.useRouter)(),[e,l]=(0,o.useState)(!1),{model:h,setModel:y}=(0,o.useContext)(f.p),j=(0,u.cI)(),{data:_}=(0,n.Z)(async()=>{let[,i]=await (0,p.Vx)((0,p.CU)());return null!=i?i:[]}),D=async e=>{let{query:a}=e;try{l(!0),j.reset();let[,e]=await (0,p.Vx)((0,p.sW)({chat_mode:"chat_normal"}));(null==e?void 0:e.conv_uid)&&i.push("/chat?id=".concat(null==e?void 0:e.conv_uid).concat(h?"&model=".concat(h):"","&initMessage=").concat(a))}catch(i){}finally{l(!1)}};return(0,a.jsx)(a.Fragment,{children:(0,a.jsxs)("div",{className:"mx-auto h-full justify-center flex max-w-3xl flex-col gap-8 px-5 pt-6",children:[(0,a.jsx)(t.Z,{className:"flex justify-center py-4",children:(0,a.jsx)(x.Z,{size:"lg",onChange:i=>{y(i)}})}),(0,a.jsx)("div",{className:"my-0 mx-auto",children:(0,a.jsx)(b(),{src:"/LOGO.png",alt:"Revolutionizing Database Interactions with Private LLM Technology",width:856,height:160,className:"w-full",unoptimized:!0})}),(0,a.jsx)("div",{className:"grid gap-8 lg:grid-cols-3",children:(0,a.jsxs)("div",{className:"lg:col-span-3",children:[(0,a.jsx)(r.Z,{className:"text-[#878c93]",children:"Quick Start"}),(0,a.jsx)(t.Z,{className:"grid rounded-xl gap-2 lg:grid-cols-3 lg:gap-6",sx:{["& .".concat(c.Z.root)]:{color:"var(--joy-palette-primary-solidColor)",backgroundColor:"var(--joy-palette-primary-solidBg)",height:"52px","&: hover":{backgroundColor:"var(--joy-palette-primary-solidHoverBg)"}},["& .".concat(c.Z.disabled)]:{cursor:"not-allowed",pointerEvents:"unset",color:"var(--joy-palette-primary-plainColor)",backgroundColor:"var(--joy-palette-primary-softDisabledBg)","&: hover":{backgroundColor:"var(--joy-palette-primary-softDisabledBg)"}}},children:null==_?void 0:_.map(e=>(0,a.jsx)(s.Z,{disabled:null==e?void 0:e.show_disable,size:"md",variant:"solid",className:"text-base rounded-none",onClick:async()=>{let[,l]=await (0,p.Vx)((0,p.sW)({chat_mode:"chat_normal"}));(null==l?void 0:l.conv_uid)&&i.push("/chat?id=".concat(l.conv_uid).concat(h?"&model=".concat(h):"","&scene=").concat(e.chat_scene))},children:e.scene_name},e.chat_scene))})]})}),(0,a.jsx)("div",{className:"mt-6 mb-[10%] pointer-events-none inset-x-0 bottom-0 z-0 mx-auto flex w-full max-w-3xl flex-col items-center justify-center max-md:border-t xl:max-w-4xl [&>*]:pointer-events-auto",children:(0,a.jsx)("form",{style:{maxWidth:"100%",width:"100%",position:"relative",display:"flex",marginTop:"auto",overflow:"visible",background:"none",justifyContent:"center",marginLeft:"auto",marginRight:"auto",height:"52px"},onSubmit:i=>{j.handleSubmit(D)(i)},children:(0,a.jsx)(d.ZP,{sx:{width:"100%"},variant:"outlined",placeholder:"Ask anything",endDecorator:(0,a.jsx)(m.ZP,{type:"submit",disabled:e,children:(0,a.jsx)(v.Z,{})}),...j.register("query")})})})]})})}}},function(i){i.O(0,[913,66,707,774,888,179],function(){return i(i.s=48312)}),_N_E=i.O()}]); \ No newline at end of file +(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[405],{52254:function(i,e,l){"use strict";l.d(e,{Z:function(){return f}});var a=l(63366),n=l(87462),o=l(67294),t=l(86010),r=l(14142),c=l(94780),s=l(74312),d=l(20407),m=l(26821);function v(i){return(0,m.d6)("MuiDivider",i)}(0,m.sI)("MuiDivider",["root","horizontal","vertical","insetContext","insetNone"]);var u=l(30220),g=l(85893);let h=["className","children","component","inset","orientation","role","slots","slotProps"],b=i=>{let{orientation:e,inset:l}=i,a={root:["root",e,l&&`inset${(0,r.Z)(l)}`]};return(0,c.Z)(a,v,{})},p=(0,s.Z)("hr",{name:"JoyDivider",slot:"Root",overridesResolver:(i,e)=>e.root})(({theme:i,ownerState:e})=>(0,n.Z)({"--Divider-thickness":"1px","--Divider-lineColor":i.vars.palette.divider},"none"===e.inset&&{"--_Divider-inset":"0px"},"context"===e.inset&&{"--_Divider-inset":"var(--Divider-inset, 0px)"},{margin:"initial",marginInline:"vertical"===e.orientation?"initial":"var(--_Divider-inset)",marginBlock:"vertical"===e.orientation?"var(--_Divider-inset)":"initial",position:"relative",alignSelf:"stretch",flexShrink:0},e.children?{"--Divider-gap":i.spacing(1),"--Divider-childPosition":"50%",display:"flex",flexDirection:"vertical"===e.orientation?"column":"row",alignItems:"center",whiteSpace:"nowrap",textAlign:"center",border:0,fontFamily:i.vars.fontFamily.body,fontSize:i.vars.fontSize.sm,"&::before, &::after":{position:"relative",inlineSize:"vertical"===e.orientation?"var(--Divider-thickness)":"initial",blockSize:"vertical"===e.orientation?"initial":"var(--Divider-thickness)",backgroundColor:"var(--Divider-lineColor)",content:'""'},"&::before":{marginInlineEnd:"vertical"===e.orientation?"initial":"min(var(--Divider-childPosition) * 999, var(--Divider-gap))",marginBlockEnd:"vertical"===e.orientation?"min(var(--Divider-childPosition) * 999, var(--Divider-gap))":"initial",flexBasis:"var(--Divider-childPosition)"},"&::after":{marginInlineStart:"vertical"===e.orientation?"initial":"min((100% - var(--Divider-childPosition)) * 999, var(--Divider-gap))",marginBlockStart:"vertical"===e.orientation?"min((100% - var(--Divider-childPosition)) * 999, var(--Divider-gap))":"initial",flexBasis:"calc(100% - var(--Divider-childPosition))"}}:{border:"none",listStyle:"none",backgroundColor:"var(--Divider-lineColor)",inlineSize:"vertical"===e.orientation?"var(--Divider-thickness)":"initial",blockSize:"vertical"===e.orientation?"initial":"var(--Divider-thickness)"})),x=o.forwardRef(function(i,e){let l=(0,d.Z)({props:i,name:"JoyDivider"}),{className:o,children:r,component:c=null!=r?"div":"hr",inset:s,orientation:m="horizontal",role:v="hr"!==c?"separator":void 0,slots:x={},slotProps:f={}}=l,y=(0,a.Z)(l,h),j=(0,n.Z)({},l,{inset:s,role:v,orientation:m,component:c}),_=b(j),D=(0,n.Z)({},y,{component:c,slots:x,slotProps:f}),[w,Z]=(0,u.Z)("root",{ref:e,className:(0,t.Z)(_.root,o),elementType:p,externalForwardedProps:D,ownerState:j,additionalProps:(0,n.Z)({as:c,role:v},"separator"===v&&"vertical"===m&&{"aria-orientation":"vertical"})});return(0,g.jsx)(w,(0,n.Z)({},Z,{children:r}))});x.muiName="Divider";var f=x},76043:function(i,e,l){"use strict";var a=l(67294);let n=a.createContext(void 0);e.Z=n},48312:function(i,e,l){(window.__NEXT_P=window.__NEXT_P||[]).push(["/",function(){return l(57464)}])},81799:function(i,e,l){"use strict";l.d(e,{A:function(){return g}});var a=l(85893),n=l(41468),o=l(14986),t=l(30322),r=l(94184),c=l.n(r),s=l(25675),d=l.n(s),m=l(67294),v=l(67421);let u={proxyllm:{label:"Proxy LLM",icon:"/models/chatgpt.png"},"internlm-7b":{label:"internlm-7b",icon:"/models/internlm.jpg"},"internlm-20b":{label:"internlm-20b",icon:"/models/internlm.jpg"},"flan-t5-base":{label:"flan-t5-base",icon:"/models/google.png"},"vicuna-13b":{label:"vicuna-13b",icon:"/models/vicuna.jpeg"},"vicuna-7b":{label:"vicuna-7b",icon:"/models/vicuna.jpeg"},"vicuna-13b-v1.5":{label:"vicuna-13b-v1.5",icon:"/models/vicuna.jpeg"},"vicuna-7b-v1.5":{label:"vicuna-7b-v1.5",icon:"/models/vicuna.jpeg"},"codegen2-1b":{label:"codegen2-1B",icon:"/models/vicuna.jpeg"},"codet5p-2b":{label:"codet5p-2b",icon:"/models/vicuna.jpeg"},"chatglm-6b-int4":{label:"chatglm-6b-int4",icon:"/models/chatglm.png"},"chatglm-6b":{label:"chatglm-6b",icon:"/models/chatglm.png"},"chatglm2-6b":{label:"chatglm2-6b",icon:"/models/chatglm.png"},"chatglm2-6b-int4":{label:"chatglm2-6b-int4",icon:"/models/chatglm.png"},"guanaco-33b-merged":{label:"guanaco-33b-merged",icon:"/models/huggingface.svg"},"falcon-40b":{label:"falcon-40b",icon:"/models/falcon.jpeg"},"gorilla-7b":{label:"gorilla-7b",icon:"/models/gorilla.png"},"gptj-6b":{label:"ggml-gpt4all-j-v1.3-groovy.bin",icon:""},chatgpt_proxyllm:{label:"chatgpt_proxyllm",icon:"/models/chatgpt.png"},bard_proxyllm:{label:"bard_proxyllm",icon:"/models/bard.gif"},claude_proxyllm:{label:"claude_proxyllm",icon:"/models/claude.png"},wenxin_proxyllm:{label:"wenxin_proxyllm",icon:""},tongyi_proxyllm:{label:"tongyi_proxyllm",icon:"/models/qwen2.png"},zhipu_proxyllm:{label:"zhipu_proxyllm",icon:"/models/zhipu.png"},"llama-2-7b":{label:"Llama-2-7b-chat-hf",icon:"/models/llama.jpg"},"llama-2-13b":{label:"Llama-2-13b-chat-hf",icon:"/models/llama.jpg"},"llama-2-70b":{label:"Llama-2-70b-chat-hf",icon:"/models/llama.jpg"},"baichuan-13b":{label:"Baichuan-13B-Chat",icon:"/models/baichuan.png"},"baichuan-7b":{label:"baichuan-7b",icon:"/models/baichuan.png"},"baichuan2-7b":{label:"Baichuan2-7B-Chat",icon:"/models/baichuan.png"},"baichuan2-13b":{label:"Baichuan2-13B-Chat",icon:"/models/baichuan.png"},"wizardlm-13b":{label:"WizardLM-13B-V1.2",icon:"/models/wizardlm.png"},"llama-cpp":{label:"ggml-model-q4_0.bin",icon:"/models/huggingface.svg"}};function g(i){var e;return i?(0,a.jsx)(d(),{className:"rounded-full mr-2 border border-gray-200 object-contain bg-white",width:24,height:24,src:null===(e=u[i])||void 0===e?void 0:e.icon,alt:"llm"}):null}e.Z=function(i){let{size:e,onChange:l}=i,{t:r}=(0,v.$G)(),{modelList:s,model:d,scene:h}=(0,m.useContext)(n.p);return!s||s.length<=0?null:(0,a.jsx)("div",{className:c()({"w-48":"sm"===e||"md"===e||!e,"w-60":"lg"===e}),children:(0,a.jsx)(o.Z,{size:e||"sm",placeholder:r("choose_model"),value:d||"",renderValue:function(i){return i?(0,a.jsxs)(a.Fragment,{children:[g(i.value),i.label]}):null},onChange:(i,e)=>{e&&(null==l||l(e))},children:s.map(i=>{var e;return(0,a.jsxs)(t.Z,{value:i,children:[g(i),(null===(e=u[i])||void 0===e?void 0:e.label)||i]},"model_".concat(i))})})})}},57464:function(i,e,l){"use strict";l.r(e);var a=l(85893),n=l(577),o=l(67294),t=l(48665),r=l(52254),c=l(11842),s=l(47556),d=l(75913),m=l(14553),v=l(24339),u=l(87536),g=l(39332),h=l(25675),b=l.n(h),p=l(50489),x=l(81799),f=l(41468);e.default=()=>{let i=(0,g.useRouter)(),[e,l]=(0,o.useState)(!1),{model:h,setModel:y}=(0,o.useContext)(f.p),j=(0,u.cI)(),{data:_}=(0,n.Z)(async()=>{let[,i]=await (0,p.Vx)((0,p.CU)());return null!=i?i:[]}),D=async e=>{let{query:a}=e;try{l(!0),j.reset();let[,e]=await (0,p.Vx)((0,p.sW)({chat_mode:"chat_normal"}));(null==e?void 0:e.conv_uid)&&i.push("/chat?id=".concat(null==e?void 0:e.conv_uid).concat(h?"&model=".concat(h):"","&initMessage=").concat(a))}catch(i){}finally{l(!1)}};return(0,a.jsx)(a.Fragment,{children:(0,a.jsxs)("div",{className:"mx-auto h-full justify-center flex max-w-3xl flex-col gap-8 px-5 pt-6",children:[(0,a.jsx)(t.Z,{className:"flex justify-center py-4",children:(0,a.jsx)(x.Z,{size:"lg",onChange:i=>{y(i)}})}),(0,a.jsx)("div",{className:"my-0 mx-auto",children:(0,a.jsx)(b(),{src:"/LOGO.png",alt:"Revolutionizing Database Interactions with Private LLM Technology",width:856,height:160,className:"w-full",unoptimized:!0})}),(0,a.jsx)("div",{className:"grid gap-8 lg:grid-cols-3",children:(0,a.jsxs)("div",{className:"lg:col-span-3",children:[(0,a.jsx)(r.Z,{className:"text-[#878c93]",children:"Quick Start"}),(0,a.jsx)(t.Z,{className:"grid rounded-xl gap-2 lg:grid-cols-3 lg:gap-6",sx:{["& .".concat(c.Z.root)]:{color:"var(--joy-palette-primary-solidColor)",backgroundColor:"var(--joy-palette-primary-solidBg)",height:"52px","&: hover":{backgroundColor:"var(--joy-palette-primary-solidHoverBg)"}},["& .".concat(c.Z.disabled)]:{cursor:"not-allowed",pointerEvents:"unset",color:"var(--joy-palette-primary-plainColor)",backgroundColor:"var(--joy-palette-primary-softDisabledBg)","&: hover":{backgroundColor:"var(--joy-palette-primary-softDisabledBg)"}}},children:null==_?void 0:_.map(e=>(0,a.jsx)(s.Z,{disabled:null==e?void 0:e.show_disable,size:"md",variant:"solid",className:"text-base rounded-none",onClick:async()=>{let[,l]=await (0,p.Vx)((0,p.sW)({chat_mode:"chat_normal"}));(null==l?void 0:l.conv_uid)&&i.push("/chat?id=".concat(l.conv_uid).concat(h?"&model=".concat(h):"","&scene=").concat(e.chat_scene))},children:e.scene_name},e.chat_scene))})]})}),(0,a.jsx)("div",{className:"mt-6 mb-[10%] pointer-events-none inset-x-0 bottom-0 z-0 mx-auto flex w-full max-w-3xl flex-col items-center justify-center max-md:border-t xl:max-w-4xl [&>*]:pointer-events-auto",children:(0,a.jsx)("form",{style:{maxWidth:"100%",width:"100%",position:"relative",display:"flex",marginTop:"auto",overflow:"visible",background:"none",justifyContent:"center",marginLeft:"auto",marginRight:"auto",height:"52px"},onSubmit:i=>{j.handleSubmit(D)(i)},children:(0,a.jsx)(d.ZP,{sx:{width:"100%"},variant:"outlined",placeholder:"Ask anything",endDecorator:(0,a.jsx)(m.ZP,{type:"submit",disabled:e,children:(0,a.jsx)(v.Z,{})}),...j.register("query")})})})]})})}}},function(i){i.O(0,[913,66,707,774,888,179],function(){return i(i.s=48312)}),_N_E=i.O()}]); \ No newline at end of file diff --git a/pilot/summary/db_summary_client.py b/pilot/summary/db_summary_client.py index d4850ec08..0fea50061 100644 --- a/pilot/summary/db_summary_client.py +++ b/pilot/summary/db_summary_client.py @@ -170,8 +170,9 @@ class DBSummaryClient: def init_db_profile(self, db_summary_client, dbname, embeddings): from pilot.embedding_engine.string_embedding import StringEmbedding + vector_store_name = dbname + "_profile" profile_store_config = { - "vector_store_name": dbname + "_profile", + "vector_store_name": vector_store_name, "chroma_persist_path": KNOWLEDGE_UPLOAD_ROOT_PATH, "vector_store_type": CFG.VECTOR_STORE_TYPE, "embeddings": embeddings, @@ -190,6 +191,8 @@ class DBSummaryClient: ) docs.extend(embedding.read_batch()) embedding.index_to_store(docs) + else: + logger.info(f"Vector store name {vector_store_name} exist") logger.info("init db profile success...") diff --git a/pilot/vector_store/chroma_store.py b/pilot/vector_store/chroma_store.py index 59ac254b6..7b2866cae 100644 --- a/pilot/vector_store/chroma_store.py +++ b/pilot/vector_store/chroma_store.py @@ -2,6 +2,7 @@ import os from typing import Any from chromadb.config import Settings +from chromadb import PersistentClient from pilot.logs import logger from pilot.vector_store.base import VectorStoreBase @@ -18,15 +19,18 @@ class ChromaStore(VectorStoreBase): ctx["chroma_persist_path"], ctx["vector_store_name"] + ".vectordb" ) chroma_settings = Settings( - chroma_db_impl="duckdb+parquet", + # chroma_db_impl="duckdb+parquet", => deprecated configuration of Chroma persist_directory=self.persist_dir, anonymized_telemetry=False, ) + client = PersistentClient(path=self.persist_dir, settings=chroma_settings) + collection_metadata = {"hnsw:space": "cosine"} self.vector_store_client = Chroma( persist_directory=self.persist_dir, embedding_function=self.embeddings, - client_settings=chroma_settings, + # client_settings=chroma_settings, + client=client, collection_metadata=collection_metadata, ) @@ -35,9 +39,13 @@ class ChromaStore(VectorStoreBase): return self.vector_store_client.similarity_search(text, topk) def vector_name_exists(self): - return ( - os.path.exists(self.persist_dir) and len(os.listdir(self.persist_dir)) > 0 - ) + logger.info(f"Check persist_dir: {self.persist_dir}") + if not os.path.exists(self.persist_dir): + return False + files = os.listdir(self.persist_dir) + # Skip default file: chroma.sqlite3 + files = list(filter(lambda f: f != "chroma.sqlite3", files)) + return len(files) > 0 def load_document(self, documents): logger.info("ChromaStore load document") diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 9f58fc834..000000000 --- a/requirements.txt +++ /dev/null @@ -1,84 +0,0 @@ -# torch==2.0.0 -aiohttp==3.8.4 -aiosignal==1.3.1 -async-timeout==4.0.2 -attrs==22.2.0 -cchardet==2.1.7 -chardet==5.1.0 -# contourpy==1.0.7 -# cycler==0.11.0 -filelock==3.9.0 -fonttools==4.38.0 -frozenlist==1.3.3 -huggingface-hub==0.14.1 -importlib-resources==5.12.0 - -sqlparse==0.4.4 -# kiwisolver==1.4.4 -# matplotlib==3.7.1 -multidict==6.0.4 -packaging==23.0 -psutil==5.9.4 -# pycocotools==2.0.6 -# pyparsing==3.0.9 -python-dateutil==2.8.2 -pyyaml==6.0 -tokenizers==0.13.2 -tqdm==4.64.1 -transformers>=4.31.0 -transformers_stream_generator -# timm==0.6.13 -spacy==3.5.3 -webdataset==0.2.48 -yarl==1.8.2 -zipp==3.14.0 -omegaconf==2.3.0 -opencv-python==4.7.0.72 -iopath==0.1.10 -tenacity==8.2.2 -peft -# TODO remove pycocoevalcap -pycocoevalcap -cpm_kernels -umap-learn -# notebook -gradio==3.23 -gradio-client==0.0.8 -# wandb -# llama-index==0.5.27 - -# TODO move bitsandbytes to optional -# bitsandbytes -accelerate>=0.20.3 - -unstructured==0.6.3 -gpt4all==0.3.0 -diskcache==5.6.1 -seaborn -auto-gpt-plugin-template -pymdown-extensions -gTTS==2.3.1 -langchain>=0.0.286 -nltk -python-dotenv==1.0.0 - -vcrpy -chromadb==0.3.22 -markdown2 -colorama -playsound -distro -pypdf -weaviate-client -bardapi==0.1.29 - -# database - -# TODO moved to optional dependencies -pymysql -duckdb -duckdb-engine - -# cli -prettytable -cachetools \ No newline at end of file diff --git a/requirements/test-requirements.txt b/requirements/dev-requirements.txt similarity index 58% rename from requirements/test-requirements.txt rename to requirements/dev-requirements.txt index c2fb321a5..00865cb52 100644 --- a/requirements/test-requirements.txt +++ b/requirements/dev-requirements.txt @@ -1,4 +1,4 @@ -# Testing dependencies +# Testing and dev dependencies pytest asynctest pytest-asyncio @@ -7,4 +7,6 @@ pytest-cov pytest-integration pytest-mock pytest-recording -pytesseract==0.3.10 \ No newline at end of file +pytesseract==0.3.10 +# python code format +black \ No newline at end of file diff --git a/setup.py b/setup.py index 642a20c6d..64ae3e8b4 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,6 @@ from urllib.parse import urlparse, quote import re from pip._internal.utils.appdirs import user_cache_dir import shutil -import tempfile from setuptools import find_packages with open("README.md", mode="r", encoding="utf-8") as fh: @@ -74,7 +73,6 @@ def cache_package(package_url: str, package_name: str, is_windows: bool = False) local_path = os.path.join(cache_dir, filename) if not os.path.exists(local_path): - # temp_file, temp_path = tempfile.mkstemp() temp_path = local_path + ".tmp" if os.path.exists(temp_path): os.remove(temp_path) @@ -204,23 +202,16 @@ def torch_requires( torchvision_version: str = "0.15.1", torchaudio_version: str = "2.0.1", ): - torch_pkgs = [] + torch_pkgs = [ + f"torch=={torch_version}", + f"torchvision=={torchvision_version}", + f"torchaudio=={torchaudio_version}", + ] + torch_cuda_pkgs = [] os_type, _ = get_cpu_avx_support() - if os_type == OSType.DARWIN: - torch_pkgs = [ - f"torch=={torch_version}", - f"torchvision=={torchvision_version}", - f"torchaudio=={torchaudio_version}", - ] - else: + if os_type != OSType.DARWIN: cuda_version = get_cuda_version() - if not cuda_version: - torch_pkgs = [ - f"torch=={torch_version}", - f"torchvision=={torchvision_version}", - f"torchaudio=={torchaudio_version}", - ] - else: + if cuda_version: supported_versions = ["11.7", "11.8"] if cuda_version not in supported_versions: print( @@ -238,12 +229,16 @@ def torch_requires( torchvision_url_cached = cache_package( torchvision_url, "torchvision", os_type == OSType.WINDOWS ) - torch_pkgs = [ + + torch_cuda_pkgs = [ f"torch @ {torch_url_cached}", f"torchvision @ {torchvision_url_cached}", f"torchaudio=={torchaudio_version}", ] + setup_spec.extras["torch"] = torch_pkgs + setup_spec.extras["torch_cpu"] = torch_pkgs + setup_spec.extras["torch_cuda"] = torch_cuda_pkgs def llama_cpp_python_cuda_requires(): @@ -274,6 +269,57 @@ def llama_cpp_python_cuda_requires(): setup_spec.extras["llama_cpp"].append(f"llama_cpp_python_cuda @ {extra_index_url}") +def core_requires(): + """ + pip install db-gpt or pip install "db-gpt[core]" + """ + setup_spec.extras["core"] = [ + "aiohttp==3.8.4", + "chardet==5.1.0", + "importlib-resources==5.12.0", + "psutil==5.9.4", + "python-dotenv==1.0.0", + "colorama", + "prettytable", + "cachetools", + ] + + setup_spec.extras["framework"] = [ + "httpx", + "sqlparse==0.4.4", + "seaborn", + # https://github.com/eosphoros-ai/DB-GPT/issues/551 + "pandas==2.0.3", + "auto-gpt-plugin-template", + "gTTS==2.3.1", + "langchain>=0.0.286", + "SQLAlchemy", + "pymysql", + "duckdb", + "duckdb-engine", + "jsonschema", + # TODO move transformers to default + "transformers>=4.31.0", + ] + + +def knowledge_requires(): + """ + pip install "db-gpt[knowledge]" + """ + setup_spec.extras["knowledge"] = [ + "spacy==3.5.3", + # "chromadb==0.3.22", + "chromadb", + "markdown", + "bs4", + "python-pptx", + "python-docx", + "pypdf", + "python-multipart", + ] + + def llama_cpp_requires(): """ pip install "db-gpt[llama_cpp]" @@ -309,6 +355,7 @@ def all_vector_store_requires(): setup_spec.extras["vstore"] = [ "grpcio==1.47.5", # maybe delete it "pymilvus==2.2.1", + "weaviate-client", ] @@ -324,6 +371,31 @@ def openai_requires(): pip install "db-gpt[openai]" """ setup_spec.extras["openai"] = ["openai", "tiktoken"] + setup_spec.extras["openai"] += setup_spec.extras["framework"] + setup_spec.extras["openai"] += setup_spec.extras["knowledge"] + + +def gpt4all_requires(): + """ + pip install "db-gpt[gpt4all]" + """ + setup_spec.extras["gpt4all"] = ["gpt4all"] + + +def default_requires(): + """ + pip install "db-gpt[default]" + """ + setup_spec.extras["default"] = [ + "tokenizers==0.13.2", + "accelerate>=0.20.3", + "sentence-transformers", + "protobuf==3.20.3", + ] + setup_spec.extras["default"] += setup_spec.extras["framework"] + setup_spec.extras["default"] += setup_spec.extras["knowledge"] + setup_spec.extras["default"] += setup_spec.extras["torch"] + setup_spec.extras["default"] += setup_spec.extras["quantization"] def all_requires(): @@ -335,20 +407,23 @@ def all_requires(): def init_install_requires(): - setup_spec.install_requires += parse_requirements("requirements.txt") - setup_spec.install_requires += setup_spec.extras["torch"] - setup_spec.install_requires += setup_spec.extras["quantization"] + setup_spec.install_requires += setup_spec.extras["core"] print(f"Install requires: \n{','.join(setup_spec.install_requires)}") +core_requires() torch_requires() +knowledge_requires() llama_cpp_requires() quantization_requires() + all_vector_store_requires() all_datasource_requires() openai_requires() +gpt4all_requires() # must be last +default_requires() all_requires() init_install_requires()