除了界面化的使用之外,本项目也提供了丰富的命令行工具。 可以实现模型部署,服务部署与启停,知识库操作(查看、删除、文档加载),调试与问题定位等多种能力。
下面对相关的命令行工具进行一个系统的使用介绍。
前置准备
在使用dbgpt命令之前,首先需要完成项目的安装。 详细的安装教程可以参考: 源码安装
使用
命令行提供了多种能力,我们可以通过如下命令查看, 如图所示,我们即可看到dbgpt的命令列表,分别有install、knowledge、model、start、stop、trace
~ dbgpt --helpAlready connect 'dbgpt'Usage: dbgpt [OPTIONS] COMMAND [ARGS]...Options:--log-level TEXT Log level--version Show the version and exit.--help Show this message and exit.Commands:install Install dependencies, plugins, etc.knowledge Knowledge command line toolmodel Clients that manage model servingstart Start specific server.stop Stop specific server.trace Analyze and visualize trace spans.
安装命令
install命令提供了各种依赖包、插件的安装使用。
:::danger ⚠️ 注: 当前插件重构中,相关功能下个版本开放。
:::
知识库命令
knowledge 命令主要提供了知识库相关的操作,当前主要的命令有delete、list、load
~ dbgpt knowledge --helpAlready connect 'dbgpt'Usage: dbgpt knowledge [OPTIONS] COMMAND [ARGS]...Knowledge command line toolOptions:--address TEXT Address of the Api server(If not set, try to read fromenvironment variable: API_ADDRESS). [default:http://127.0.0.1:5000]--help Show this message and exit.Commands:delete Delete your knowledge space or document in spacelist List knowledge spaceload Load your local documents to DB-GPT
load
load 指知识库文档加载,可以通过load命令批量加载知识库文档。
~ dbgpt knowledge load --helpAlready connect 'dbgpt'Usage: dbgpt knowledge load [OPTIONS]Load your local documents to DB-GPTOptions:--space_name TEXT Your knowledge space name [default: default]--vector_store_type TEXT Vector store type. [default: Chroma]--local_doc_path TEXT Your document directory or document file path.[default: /Users/magic/workspace/github/eosphoros-ai/DB-GPT/pilot/datasets]--skip_wrong_doc Skip wrong document.--overwrite Overwrite existing document(they has same name).--max_workers INTEGER The maximum number of threads that can be used toupload document.--pre_separator TEXT Preseparator, this separator is used for pre-splitting before the document is actually split bythe text splitter. Preseparator are not includedin the vectorized text.--separator TEXT This is the document separator. Currently, onlyone separator is supported.--chunk_size INTEGER Maximum size of chunks to split.--chunk_overlap INTEGER Overlap in characters between chunks.--help Show this message and exit.

list
list 命令主要是展示知识库相关的信息。 如展示知识空间、文档内容、Chunk内容等。
~ dbgpt knowledge list --helpAlready connect 'dbgpt'Usage: dbgpt knowledge list [OPTIONS]List knowledge spaceOptions:--space_name TEXT Your knowledge space name. If None, list allspaces--doc_id INTEGER Your document id in knowledge space. If NotNone, list all chunks in current document--page INTEGER The page for every query [default: 1]--page_size INTEGER The page size for every query [default: 20]--show_content Query the document content of chunks--output [text|html|csv|latex|json]The output format--help Show this message and exit.
delete
删除命令支持知识库与文档的删除。可以通过dbgpt knowledge delete --help 查看相关的命令细节
~ dbgpt knowledge delete --helpAlready connect 'dbgpt'Usage: dbgpt knowledge delete [OPTIONS]Delete your knowledge space or document in spaceOptions:--space_name TEXT Your knowledge space name [default: default]--doc_name TEXT The document name you want to delete. If doc_name isNone, this command will delete the whole space.-y Confirm your choice--help Show this message and exit.

模型命令
model相关命令主要在多模型部署时使用,关于模型集群部署可以查看集群部署模式
~ dbgpt model --helpAlready connect 'dbgpt'Usage: dbgpt model [OPTIONS] COMMAND [ARGS]...Clients that manage model servingOptions:--address TEXT Address of the Model Controller to connect to. Just supportlight deploy model, If the environment variableCONTROLLER_ADDRESS is configured, read from the environmentvariable--help Show this message and exit.Commands:chat Interact with your bot from the command linelist List model instancesrestart Restart model instancesstart Start model instancesstop Stop model instances
chat
通过chat命令可以实现与模型在命令行窗口对话。
~ dbgpt model chat --helpAlready connect 'dbgpt'Usage: dbgpt model chat [OPTIONS]Interact with your bot from the command lineOptions:--model_name TEXT The name of model [required]--system TEXT System prompt--help Show this message and exit.
list
通过list命令可以查看当前模型列表
~ dbgpt model list --helpAlready connect 'dbgpt'Usage: dbgpt model list [OPTIONS]List model instancesOptions:--model_name TEXT The name of model--model_type TEXT The type of model--help Show this message and exit.
restart
通过restart命令可以重启模型
~ dbgpt model restart --helpAlready connect 'dbgpt'Usage: dbgpt model restart [OPTIONS]Restart model instancesOptions:--model_name TEXT The name of model [required]--model_type TEXT The type of model--help Show this message and exit.
start
start命令主要负责模型启动
~ dbgpt model start --helpAlready connect 'dbgpt'Usage: dbgpt model start [OPTIONS]Start model instancesOptions:--model_name TEXT The model name to deploy [required]--model_path TEXT The model path to deploy--host TEXT The remote host to deploy model [default:30.183.153.197]--port INTEGER The remote port to deploy model [default: 5000]--worker_type TEXT Worker type [default: llm]--device TEXT Device to run model. If None, the device isautomatically determined--model_type TEXT Model type: huggingface, llama.cpp, proxy andvllm [default: huggingface]--prompt_template TEXT Prompt template. If None, the prompt template isautomatically determined from model path,supported template: zero_shot,vicuna_v1.1,llama-2,codellama,alpaca,baichuan-chat,internlm-chat--max_context_size INTEGER Maximum context size [default: 4096]--num_gpus INTEGER The number of gpus you expect to use, if it isempty, use all of them as much as possible--max_gpu_memory TEXT The maximum memory limit of each GPU, only validin multi-GPU configuration--cpu_offloading CPU offloading--load_8bit 8-bit quantization--load_4bit 4-bit quantization--quant_type TEXT Quantization datatypes, `fp4` (four bit float)and `nf4` (normal four bit float), only validwhen load_4bit=True [default: nf4]--use_double_quant Nested quantization, only valid whenload_4bit=True [default: True]--compute_dtype TEXT Model compute type--trust_remote_code Trust remote code [default: True]--verbose Show verbose output.--help Show this message and exit.
stop
stop命令主要负责模型停止
~ dbgpt model stop --helpAlready connect 'dbgpt'Usage: dbgpt model stop [OPTIONS]Stop model instancesOptions:--model_name TEXT The name of model [required]--model_type TEXT The type of model--host TEXT The remote host to stop model [required]--port INTEGER The remote port to stop model [required]--help Show this message and exit.

启动/停止命令
dbgpt start 与 dbgpt stop相关命令是一组服务注册发现相关的接口。 分别有 apiserver、controller、worker 以及webserver
~ dbgpt start --helpAlready connect 'dbgpt'Usage: dbgpt start [OPTIONS] COMMAND [ARGS]...Start specific server.Options:--help Show this message and exit.Commands:apiserver Start apiservercontroller Start model controllerwebserver Start webserver(dbgpt_server.py)worker Start model worker
apiserver
通过 dbgpt start apiserver 可以启动模型的api服务,默认启动端口8100
~ dbgpt start apiserver --helpAlready connect 'dbgpt'Usage: dbgpt start apiserver [OPTIONS]Start apiserverOptions:--host TEXT Model API server deploy host [default: 0.0.0.0]--port INTEGER Model API server deploy port [default: 8100]--daemon Run Model API server in background--controller_addr TEXT The Model controller address to connect[default: http://127.0.0.1:8000]--api_keys TEXT Optional list of comma separated API keys--log_level TEXT Logging level--log_file TEXT The filename to store log [default:dbgpt_model_apiserver.log]--tracer_file TEXT The filename to store tracer span records[default: dbgpt_model_apiserver_tracer.jsonl]--tracer_storage_cls TEXT The storage class to storage tracer span records--help Show this message and exit.# 启动apiserver~ dbgpt start apiserverAlready connect 'dbgpt'2023-12-07 14:35:21 B-4TMH9N3X-2120.local pilot.component[95201] INFO Register component with name dbgpt_model_registry and instance: <pilot.model.cluster.controller.controller.ModelRegistryClient object at 0x28f4e0c70>2023-12-07 14:35:21 B-4TMH9N3X-2120.local pilot.component[95201] INFO Register component with name dbgpt_worker_manager_factory and instance: <pilot.model.cluster.worker.manager._DefaultWorkerManagerFactory object at 0x28f4e2110>2023-12-07 14:35:21 B-4TMH9N3X-2120.local pilot.component[95201] INFO Register component with name dbgpt_model_api_server and instance: <pilot.model.cluster.apiserver.api.APIServer object at 0x28f4e2170>INFO: Started server process [95201]INFO: Waiting for application startup.INFO: Application startup complete.INFO: Uvicorn running on http://0.0.0.0:8100 (Press CTRL+C to quit)INFO: 127.0.0.1:56638 - "GET /docs HTTP/1.1" 200 OKINFO: 127.0.0.1:56665 - "GET /openapi.json HTTP/1.1" 200 OK^CINFO: Shutting downINFO: Waiting for application shutdown.INFO: Application shutdown complete.INFO: Finished server process [95201]
controller
通过dbgpt start controller可以启动管控服务,默认启动端口8000
~ dbgpt start --helpAlready connect 'dbgpt'Usage: dbgpt start [OPTIONS] COMMAND [ARGS]...Start specific server.Options:--help Show this message and exit.Commands:apiserver Start apiservercontroller Start model controllerwebserver Start webserver(dbgpt_server.py)worker Start model worker(dbgpt_env) magic@B-4TMH9N3X-2120 ~ % dbgpt start controllerAlready connect 'dbgpt'INFO: Started server process [96797]INFO: Waiting for application startup.INFO: Application startup complete.INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
webserver
通过dbgpt start webserver 可以启动前端服务,默认端口 5000, 通过 http://127.0.0.1:5000进行访问
~ dbgpt start webserver --helpAlready connect 'dbgpt'Usage: dbgpt start webserver [OPTIONS]Start webserver(dbgpt_server.py)Options:--host TEXT Webserver deploy host [default: 0.0.0.0]--port INTEGER Webserver deploy port [default: 5000]--daemon Run Webserver in background--controller_addr TEXT The Model controller address to connect. If None,read model controller address from environmentkey `MODEL_SERVER`.--model_name TEXT The default model name to use. If None, readmodel name from environment key `LLM_MODEL`.--share Whether to create a publicly shareable link forthe interface. Creates an SSH tunnel to make yourUI accessible from anywhere.--remote_embedding Whether to enable remote embedding models. If itis True, you need to start a embedding modelthrough `dbgpt start worker --worker_typetext2vec --model_name xxx --model_path xxx`--log_level TEXT Logging level--light enable light mode--log_file TEXT The filename to store log [default:dbgpt_webserver.log]--tracer_file TEXT The filename to store tracer span records[default: dbgpt_webserver_tracer.jsonl]--tracer_storage_cls TEXT The storage class to storage tracer span records--disable_alembic_upgrade Whether to disable alembic to initialize andupgrade database metadata--help Show this message and exit.

worker
dbgpt start worker主要用于启动工作模型,详细的使用可见: 集群部署
调试(Debugging)
dbgpt 项目提供了丰富的debug命令,详细的使用参见: 调试(Debugging)
