DB-GPT项目目前也提供了各种API以供使用。 目前API主要分为两类。 1. 模型API 2. 应用服务层API
模型API主要是指DB-GPT适配了各类模型,统一封装为兼容OpenAI SDK输出的模型。 服务层API是指DB-GPT服务层暴露出的API,下面对两者的使用做一个简要介绍。
模型API
在DB-GPT项目中,我们定义了服务化的多模型管理框架(SMMF), 通过SMMF的能力,我们可以部署多种模型,这些模型都是通过服务的方式对外提供服务。 为了让客户端可以实现无缝切换,我们统一支持了OpenAI SDK的标准。
- 详细使用教程: OpenAI SDK 调用本地多模型
Example: 以下是一个通过openai SDK调用的例子。
import openai
openai.api_key = "EMPTY"
openai.api_base = "http://127.0.0.1:8100/api/v1"
model = "vicuna-13b-v1.5"
completion = openai.ChatCompletion.create(
model=model,
messages=[{"role": "user", "content": "hello"}]
)
# print the completion
print(completion.choices[0].message.content)
应用服务层API
服务层API指的是启动webserver
之后,5000端口暴露的API,主要偏应用层。 按类别分可以分为如下几个部分。
:::color2
说明: 启动webserver之后,打开 http://127.0.0.1:5000/docs
即可查看详情
关于服务层API,早期在策略上,我们保持最小可用开放的原则。 稳定对外暴露的API都会带版本信息,如
- /api/v1
- /api/v2
因为整个领域的快速发展,不同版本的API在兼容性上,不会考虑全兼容。在后续的新版本API中,对于不兼容的API,我们会在文档中给出说明。
:::
- 对话相关(Chat API)
- 编辑相关(Editor API)
- 模型管理(LLM Manage API)
知识库(Knowledge API)Prompt(Prompt API)- Agent(Agent API)
- AWEL(AWEL API)
- 默认(Default API)
下面分别对每个API进行说明。
API
Chat API
api/v1/chat/db/list
api/v1/chat/db/add
api/v1/chat/db/edit
api/v1/chat/db/delete
api/v1/chat/db/test/connect
api/v1/chat/db/summary
api/v1/chat/db/support/type
api/v1/chat/dialogue/list
api/v1/chat/dialogue/scenes
api/v1/chat/dialogue/new
api/v1/chat/mode/params/list
api/v1/chat/mode/params/file/load
api/v1/chat/dialogue/delete
api/v1/chat/dialogue/messages
api/v1/chat/prepare
api/v1/chat/completions
Editor API
api/v1/editor/db/tables
api/v1/editor/sql/rounds
api/v1/editor/sql
api/v1/editor/sql/run
api/v1/sql/editor/submit
api/v1/editor/chart/list
api/v1/editor/chart/info
api/v1/editor/chart/run
api/v1/chart/editor/submit
Model
api/v1/model/types
api/v1/model/supports
LLM Manage
api/v1/worker/model/params
api/v1/worker/model/list
api/v1/worker/model/stop
api/v1/worker/model/start
api/worker/generate_stream
api/worker/generate
api/worker/embeddings
api/worker/apply
api/worker/parameter/descriptions
api/worker/models/supports
api/worker/models/startup
api/worker/models/shutdown
api/controller/models
api/controller/heartbeat
Agent
api/v1/agent/hub/update
api/v1/agent/query
api/v1/agent/my
api/v1/agent/install
api/v1/agent/uninstall
api/v1/personal/agent/upload
AWEL
api/v1/awel/trigger/examples/simple_rag
api/v1/awel/trigger/examples/simple_chat
api/v1/awel/trigger/examples/hello
:::
更详细的接口参数,可以通过http://127.0.0.1:5000/docs
查看