Skip to main content
Version: dev

Datasource

Get started with the Datasource API

Chat Datasource

POST /api/v2/chat/completions

Examples

Chat Datasource

from dbgpt.client import Client

DBGPT_API_KEY = "dbgpt"
DB_NAME="{your_db_name}"

client = Client(api_key=DBGPT_API_KEY)
res = client.chat(
messages="show space datas limit 5",
model="chatgpt_proxyllm",
chat_mode="chat_data",
chat_param=DB_NAME
)

Chat Completion Response

{
"id": "2bb80fdd-e47e-4083-8bc9-7ca66ee0931b",
"object": "chat.completion",
"created": 1711509733,
"model": "chatgpt_proxyllm",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "The user wants to display information about knowledge spaces with a limit of 5 results.\\n<chart-view content=\"{\"type\": \"response_table\", \"sql\": \"SELECT * FROM knowledge_space LIMIT 5\", \"data\": [{\"id\": 5, \"name\": \"frfrw\", \"vector_type\": \"Chroma\", \"desc\": \"eee\", \"owner\": \"eee\", \"context\": null, \"gmt_created\": \"2024-01-02T13:29:52\", \"gmt_modified\": \"2024-01-02T13:29:52\", \"description\": null}, {\"id\": 7, \"name\": \"acc\", \"vector_type\": \"Chroma\", \"desc\": \"dede\", \"owner\": \"dede\", \"context\": null, \"gmt_created\": \"2024-01-02T13:47:01\", \"gmt_modified\": \"2024-01-02T13:47:01\", \"description\": null}, {\"id\": 8, \"name\": \"bcc\", \"vector_type\": \"Chroma\", \"desc\": \"dede\", \"owner\": \"dede\", \"context\": null, \"gmt_created\": \"2024-01-02T14:22:02\", \"gmt_modified\": \"2024-01-02T14:22:02\", \"description\": null}, {\"id\": 9, \"name\": \"dede\", \"vector_type\": \"Chroma\", \"desc\": \"dede\", \"owner\": \"dede\", \"context\": null, \"gmt_created\": \"2024-01-02T14:36:18\", \"gmt_modified\": \"2024-01-02T14:36:18\", \"description\": null}, {\"id\": 10, \"name\": \"qqq\", \"vector_type\": \"Chroma\", \"desc\": \"dede\", \"owner\": \"dede\", \"context\": null, \"gmt_created\": \"2024-01-02T14:40:56\", \"gmt_modified\": \"2024-01-02T14:40:56\", \"description\": null}]}\" />"
},
"finish_reason": null
}
],
"usage": {
"prompt_tokens": 0,
"total_tokens": 0,
"completion_tokens": 0
}
}

Create Datasource

POST /api/v2/serve/datasources

Request body

Request Datasource Object

Response body

Return Datasource Object

Update Datasource

PUT /api/v2/serve/datasources

Request body

Request Datasource Object

Response body

Return Datasource Object

Delete Datasource

DELETE /api/v2/serve/datasources
DBGPT_API_KEY=dbgpt
DATASOURCE_ID={YOUR_DATASOURCE_ID}

curl -X DELETE "http://localhost:5670/api/v2/serve/datasources/$DATASOURCE_ID" \
-H "Authorization: Bearer $DBGPT_API_KEY" \

Delete Parameters


datasource_id string Required

datasource id


Response body

Return Datasource Object

Get Datasource

GET /api/v2/serve/datasources/{datasource_id}
DBGPT_API_KEY=dbgpt
DATASOURCE_ID={YOUR_DATASOURCE_ID}

curl -X GET "http://localhost:5670/api/v2/serve/datasources/$DATASOURCE_ID" -H "Authorization: Bearer $DBGPT_API_KEY"

Query Parameters


datasource_id string Required

datasource id


Response body

Return Datasource Object

List Datasource

GET /api/v2/serve/datasources
DBGPT_API_KEY=dbgpt

curl -X GET "http://localhost:5670/api/v2/serve/datasources" -H "Authorization: Bearer $DBGPT_API_KEY"

Response body

Return Datasource Object

The Datasource Object


id string

The unique id for the datasource.


db_name string

The Database name


db_type string

Database type, e.g. sqlite, mysql, etc.


db_path string

File path for file-based database.


db_host string

Database host.


db_port object

Database port.


db_user string

Database user.


db_pwd string

Database password.


comment string

Comment for the database.