多模型服务的调用兼容了OpenAI接口,可以通过OpenAI SDK直接调用DB-GPT中部署好的模型。
:::color1 ⚠️ 在使用此项目前,首先要部署好模型服务,可以通过集群部署教程来部署。
:::
启动apiserver
部署好模型服务之后,需要启动API Server,默认情况下模型API Server使用8100端口进行启动
dbgpt start apiserver --controller_addr http://127.0.0.1:8100 --api_keys EMPTY
验证
cURL验证
apiserver启动之后,即可验证服务调用,首先我们看看通过curl来进行验证。
:::success 列出模型列表
:::
curl http://127.0.0.1:8100/api/v1/models \-H "Authorization: Bearer EMPTY" \-H "Content-Type: application/json"
:::success 对话
:::
curl http://127.0.0.1:8100/api/v1/chat/completions \-H "Authorization: Bearer EMPTY" \-H "Content-Type: application/json" \-d '{"model": "vicuna-13b-v1.5", "messages": [{"role": "user", "content": "hello"}]}'
通过OpenAI SDK进行验证
import openaiopenai.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 completionprint(completion.choices[0].message.content)
