除了界面化的使用之外,本项目也提供了丰富的命令行工具。 可以实现模型部署,服务部署与启停,知识库操作(查看、删除、文档加载),调试与问题定位等多种能力。

下面对相关的命令行工具进行一个系统的使用介绍。

前置准备

在使用dbgpt命令之前,首先需要完成项目的安装。 详细的安装教程可以参考: 源码安装

使用

命令行提供了多种能力,我们可以通过如下命令查看, 如图所示,我们即可看到dbgpt的命令列表,分别有installknowledgemodelstartstoptrace

  1. ~ dbgpt --help
  2. Already connect 'dbgpt'
  3. Usage: dbgpt [OPTIONS] COMMAND [ARGS]...
  4. Options:
  5. --log-level TEXT Log level
  6. --version Show the version and exit.
  7. --help Show this message and exit.
  8. Commands:
  9. install Install dependencies, plugins, etc.
  10. knowledge Knowledge command line tool
  11. model Clients that manage model serving
  12. start Start specific server.
  13. stop Stop specific server.
  14. trace Analyze and visualize trace spans.

安装命令

install命令提供了各种依赖包、插件的安装使用。

:::danger ⚠️ 注: 当前插件重构中,相关功能下个版本开放。

:::

知识库命令

knowledge 命令主要提供了知识库相关的操作,当前主要的命令有deletelistload

  1. ~ dbgpt knowledge --help
  2. Already connect 'dbgpt'
  3. Usage: dbgpt knowledge [OPTIONS] COMMAND [ARGS]...
  4. Knowledge command line tool
  5. Options:
  6. --address TEXT Address of the Api server(If not set, try to read from
  7. environment variable: API_ADDRESS). [default:
  8. http://127.0.0.1:5000]
  9. --help Show this message and exit.
  10. Commands:
  11. delete Delete your knowledge space or document in space
  12. list List knowledge space
  13. load Load your local documents to DB-GPT

load

load 指知识库文档加载,可以通过load命令批量加载知识库文档。

  1. ~ dbgpt knowledge load --help
  2. Already connect 'dbgpt'
  3. Usage: dbgpt knowledge load [OPTIONS]
  4. Load your local documents to DB-GPT
  5. Options:
  6. --space_name TEXT Your knowledge space name [default: default]
  7. --vector_store_type TEXT Vector store type. [default: Chroma]
  8. --local_doc_path TEXT Your document directory or document file path.
  9. [default: /Users/magic/workspace/github/eosphoros-
  10. ai/DB-GPT/pilot/datasets]
  11. --skip_wrong_doc Skip wrong document.
  12. --overwrite Overwrite existing document(they has same name).
  13. --max_workers INTEGER The maximum number of threads that can be used to
  14. upload document.
  15. --pre_separator TEXT Preseparator, this separator is used for pre-
  16. splitting before the document is actually split by
  17. the text splitter. Preseparator are not included
  18. in the vectorized text.
  19. --separator TEXT This is the document separator. Currently, only
  20. one separator is supported.
  21. --chunk_size INTEGER Maximum size of chunks to split.
  22. --chunk_overlap INTEGER Overlap in characters between chunks.
  23. --help Show this message and exit.

命令行使用 - 图1

list

list 命令主要是展示知识库相关的信息。 如展示知识空间文档内容Chunk内容等。

  1. ~ dbgpt knowledge list --help
  2. Already connect 'dbgpt'
  3. Usage: dbgpt knowledge list [OPTIONS]
  4. List knowledge space
  5. Options:
  6. --space_name TEXT Your knowledge space name. If None, list all
  7. spaces
  8. --doc_id INTEGER Your document id in knowledge space. If Not
  9. None, list all chunks in current document
  10. --page INTEGER The page for every query [default: 1]
  11. --page_size INTEGER The page size for every query [default: 20]
  12. --show_content Query the document content of chunks
  13. --output [text|html|csv|latex|json]
  14. The output format
  15. --help Show this message and exit.

delete

删除命令支持知识库与文档的删除。可以通过dbgpt knowledge delete --help 查看相关的命令细节

  1. ~ dbgpt knowledge delete --help
  2. Already connect 'dbgpt'
  3. Usage: dbgpt knowledge delete [OPTIONS]
  4. Delete your knowledge space or document in space
  5. Options:
  6. --space_name TEXT Your knowledge space name [default: default]
  7. --doc_name TEXT The document name you want to delete. If doc_name is
  8. None, this command will delete the whole space.
  9. -y Confirm your choice
  10. --help Show this message and exit.

命令行使用 - 图2

模型命令

model相关命令主要在多模型部署时使用,关于模型集群部署可以查看集群部署模式

  1. ~ dbgpt model --help
  2. Already connect 'dbgpt'
  3. Usage: dbgpt model [OPTIONS] COMMAND [ARGS]...
  4. Clients that manage model serving
  5. Options:
  6. --address TEXT Address of the Model Controller to connect to. Just support
  7. light deploy model, If the environment variable
  8. CONTROLLER_ADDRESS is configured, read from the environment
  9. variable
  10. --help Show this message and exit.
  11. Commands:
  12. chat Interact with your bot from the command line
  13. list List model instances
  14. restart Restart model instances
  15. start Start model instances
  16. stop Stop model instances

chat

通过chat命令可以实现与模型在命令行窗口对话。

  1. ~ dbgpt model chat --help
  2. Already connect 'dbgpt'
  3. Usage: dbgpt model chat [OPTIONS]
  4. Interact with your bot from the command line
  5. Options:
  6. --model_name TEXT The name of model [required]
  7. --system TEXT System prompt
  8. --help Show this message and exit.

list

通过list命令可以查看当前模型列表

  1. ~ dbgpt model list --help
  2. Already connect 'dbgpt'
  3. Usage: dbgpt model list [OPTIONS]
  4. List model instances
  5. Options:
  6. --model_name TEXT The name of model
  7. --model_type TEXT The type of model
  8. --help Show this message and exit.

restart

通过restart命令可以重启模型

  1. ~ dbgpt model restart --help
  2. Already connect 'dbgpt'
  3. Usage: dbgpt model restart [OPTIONS]
  4. Restart model instances
  5. Options:
  6. --model_name TEXT The name of model [required]
  7. --model_type TEXT The type of model
  8. --help Show this message and exit.

start

start命令主要负责模型启动

  1. ~ dbgpt model start --help
  2. Already connect 'dbgpt'
  3. Usage: dbgpt model start [OPTIONS]
  4. Start model instances
  5. Options:
  6. --model_name TEXT The model name to deploy [required]
  7. --model_path TEXT The model path to deploy
  8. --host TEXT The remote host to deploy model [default:
  9. 30.183.153.197]
  10. --port INTEGER The remote port to deploy model [default: 5000]
  11. --worker_type TEXT Worker type [default: llm]
  12. --device TEXT Device to run model. If None, the device is
  13. automatically determined
  14. --model_type TEXT Model type: huggingface, llama.cpp, proxy and
  15. vllm [default: huggingface]
  16. --prompt_template TEXT Prompt template. If None, the prompt template is
  17. automatically determined from model path,
  18. supported template: zero_shot,vicuna_v1.1,llama-
  19. 2,codellama,alpaca,baichuan-chat,internlm-chat
  20. --max_context_size INTEGER Maximum context size [default: 4096]
  21. --num_gpus INTEGER The number of gpus you expect to use, if it is
  22. empty, use all of them as much as possible
  23. --max_gpu_memory TEXT The maximum memory limit of each GPU, only valid
  24. in multi-GPU configuration
  25. --cpu_offloading CPU offloading
  26. --load_8bit 8-bit quantization
  27. --load_4bit 4-bit quantization
  28. --quant_type TEXT Quantization datatypes, `fp4` (four bit float)
  29. and `nf4` (normal four bit float), only valid
  30. when load_4bit=True [default: nf4]
  31. --use_double_quant Nested quantization, only valid when
  32. load_4bit=True [default: True]
  33. --compute_dtype TEXT Model compute type
  34. --trust_remote_code Trust remote code [default: True]
  35. --verbose Show verbose output.
  36. --help Show this message and exit.

stop

stop命令主要负责模型停止

  1. ~ dbgpt model stop --help
  2. Already connect 'dbgpt'
  3. Usage: dbgpt model stop [OPTIONS]
  4. Stop model instances
  5. Options:
  6. --model_name TEXT The name of model [required]
  7. --model_type TEXT The type of model
  8. --host TEXT The remote host to stop model [required]
  9. --port INTEGER The remote port to stop model [required]
  10. --help Show this message and exit.

命令行使用 - 图3

启动/停止命令

dbgpt startdbgpt stop相关命令是一组服务注册发现相关的接口。 分别有 apiservercontrollerworker 以及webserver

  1. ~ dbgpt start --help
  2. Already connect 'dbgpt'
  3. Usage: dbgpt start [OPTIONS] COMMAND [ARGS]...
  4. Start specific server.
  5. Options:
  6. --help Show this message and exit.
  7. Commands:
  8. apiserver Start apiserver
  9. controller Start model controller
  10. webserver Start webserver(dbgpt_server.py)
  11. worker Start model worker

apiserver

通过 dbgpt start apiserver 可以启动模型的api服务,默认启动端口8100

  1. ~ dbgpt start apiserver --help
  2. Already connect 'dbgpt'
  3. Usage: dbgpt start apiserver [OPTIONS]
  4. Start apiserver
  5. Options:
  6. --host TEXT Model API server deploy host [default: 0.0.0.0]
  7. --port INTEGER Model API server deploy port [default: 8100]
  8. --daemon Run Model API server in background
  9. --controller_addr TEXT The Model controller address to connect
  10. [default: http://127.0.0.1:8000]
  11. --api_keys TEXT Optional list of comma separated API keys
  12. --log_level TEXT Logging level
  13. --log_file TEXT The filename to store log [default:
  14. dbgpt_model_apiserver.log]
  15. --tracer_file TEXT The filename to store tracer span records
  16. [default: dbgpt_model_apiserver_tracer.jsonl]
  17. --tracer_storage_cls TEXT The storage class to storage tracer span records
  18. --help Show this message and exit.
  19. # 启动apiserver
  20. ~ dbgpt start apiserver
  21. Already connect 'dbgpt'
  22. 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>
  23. 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>
  24. 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>
  25. INFO: Started server process [95201]
  26. INFO: Waiting for application startup.
  27. INFO: Application startup complete.
  28. INFO: Uvicorn running on http://0.0.0.0:8100 (Press CTRL+C to quit)
  29. INFO: 127.0.0.1:56638 - "GET /docs HTTP/1.1" 200 OK
  30. INFO: 127.0.0.1:56665 - "GET /openapi.json HTTP/1.1" 200 OK
  31. ^CINFO: Shutting down
  32. INFO: Waiting for application shutdown.
  33. INFO: Application shutdown complete.
  34. INFO: Finished server process [95201]

controller

通过dbgpt start controller可以启动管控服务,默认启动端口8000

  1. ~ dbgpt start --help
  2. Already connect 'dbgpt'
  3. Usage: dbgpt start [OPTIONS] COMMAND [ARGS]...
  4. Start specific server.
  5. Options:
  6. --help Show this message and exit.
  7. Commands:
  8. apiserver Start apiserver
  9. controller Start model controller
  10. webserver Start webserver(dbgpt_server.py)
  11. worker Start model worker
  12. (dbgpt_env) magic@B-4TMH9N3X-2120 ~ % dbgpt start controller
  13. Already connect 'dbgpt'
  14. INFO: Started server process [96797]
  15. INFO: Waiting for application startup.
  16. INFO: Application startup complete.
  17. 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进行访问

  1. ~ dbgpt start webserver --help
  2. Already connect 'dbgpt'
  3. Usage: dbgpt start webserver [OPTIONS]
  4. Start webserver(dbgpt_server.py)
  5. Options:
  6. --host TEXT Webserver deploy host [default: 0.0.0.0]
  7. --port INTEGER Webserver deploy port [default: 5000]
  8. --daemon Run Webserver in background
  9. --controller_addr TEXT The Model controller address to connect. If None,
  10. read model controller address from environment
  11. key `MODEL_SERVER`.
  12. --model_name TEXT The default model name to use. If None, read
  13. model name from environment key `LLM_MODEL`.
  14. --share Whether to create a publicly shareable link for
  15. the interface. Creates an SSH tunnel to make your
  16. UI accessible from anywhere.
  17. --remote_embedding Whether to enable remote embedding models. If it
  18. is True, you need to start a embedding model
  19. through `dbgpt start worker --worker_type
  20. text2vec --model_name xxx --model_path xxx`
  21. --log_level TEXT Logging level
  22. --light enable light mode
  23. --log_file TEXT The filename to store log [default:
  24. dbgpt_webserver.log]
  25. --tracer_file TEXT The filename to store tracer span records
  26. [default: dbgpt_webserver_tracer.jsonl]
  27. --tracer_storage_cls TEXT The storage class to storage tracer span records
  28. --disable_alembic_upgrade Whether to disable alembic to initialize and
  29. upgrade database metadata
  30. --help Show this message and exit.

命令行使用 - 图4

worker

dbgpt start worker主要用于启动工作模型,详细的使用可见: 集群部署

调试(Debugging)

dbgpt 项目提供了丰富的debug命令,详细的使用参见: 调试(Debugging)