Skip to content

Commit ac72bb0

Browse files
committed
Merge remote-tracking branch 'main-com/main' into fix_issue2590
2 parents 2991c7e + 0245cfd commit ac72bb0

File tree

55 files changed

+1550
-264
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1550
-264
lines changed

.pre-commit-config.yaml

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,22 @@ repos:
2020
stages: [commit]
2121
pass_filenames: false
2222
args: []
23-
- id: python-test-doc
24-
name: Python Doc Test
25-
entry: make test-doc
26-
language: system
27-
exclude: '^dbgpt/app/static/|^web/'
28-
types: [python]
29-
stages: [commit]
30-
pass_filenames: false
31-
args: []
32-
- id: python-lint-mypy
33-
name: Python Lint mypy
34-
entry: make mypy
35-
language: system
36-
exclude: '^dbgpt/app/static/|^web/'
37-
types: [python]
38-
stages: [commit]
39-
pass_filenames: false
40-
args: []
41-
23+
# - id: python-test-doc
24+
# name: Python Doc Test
25+
# entry: make test-doc
26+
# language: system
27+
# exclude: '^dbgpt/app/static/|^web/'
28+
# types: [python]
29+
# stages: [commit]
30+
# pass_filenames: false
31+
# args: []
32+
# - id: python-lint-mypy
33+
# name: Python Lint mypy
34+
# entry: make mypy
35+
# language: system
36+
# exclude: '^dbgpt/app/static/|^web/'
37+
# types: [python]
38+
# stages: [commit]
39+
# pass_filenames: false
40+
# args: []
41+
#

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ test: $(VENV)/.testenv ## Run unit tests
9191
.PHONY: test-doc
9292
test-doc: $(VENV)/.testenv ## Run doctests
9393
# -k "not test_" skips tests that are not doctests.
94-
$(VENV_BIN)/pytest --doctest-modules -k "not test_" dbgpt/core
94+
$(VENV_BIN)/pytest --doctest-modules -k "not test_" packages
9595

9696
.PHONY: mypy
9797
mypy: $(VENV)/.testenv ## Run mypy checks

configs/dbgpt-proxy-siliconflow-mysql.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ provider = "proxy/siliconflow"
3333
api_key = "${env:SILICONFLOW_API_KEY}"
3434

3535
[[models.embeddings]]
36-
name = "BAAI/bge-large-zh-v1.5"
37-
provider = "proxy/openai"
38-
api_url = "https://api.siliconflow.cn/v1/embeddings"
36+
name = "BAAI/bge-m3"
37+
provider = "proxy/siliconflow"
3938
api_key = "${env:SILICONFLOW_API_KEY}"
4039

4140
[[models.rerankers]]

docker/compose_examples/ha-cluster-docker-compose.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,25 @@ services:
154154
restart: unless-stopped
155155
networks:
156156
- dbgptnet
157+
apiserver:
158+
image: eosphorosai/dbgpt-openai:latest
159+
command: dbgpt start apiserver -c /root/configs/ha-model-cluster.toml
160+
environment:
161+
- CONTROLLER_ADDR=http://controller-1:8000,http://controller-2:8000
162+
depends_on:
163+
- controller-1
164+
- controller-2
165+
- llm-worker
166+
- embedding-worker
167+
volumes:
168+
- ../../:/app
169+
- ./conf/ha-model-cluster.toml:/root/configs/ha-model-cluster.toml
170+
ports:
171+
- 8100:8100/tcp
172+
restart: unless-stopped
173+
networks:
174+
- dbgptnet
175+
ipc: host
157176
volumes:
158177
dbgpt-init-scripts:
159178
dbgpt-myql-db:

docs/docs/api/chat.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import TabItem from '@theme/TabItem';
2222
values={[
2323
{label: 'Curl', value: 'curl'},
2424
{label: 'Python', value: 'python'},
25+
{label: 'Python(OpenAI SDK)', value: 'openai-sdk'},
2526
]
2627
}>
2728

@@ -54,8 +55,40 @@ async for data in client.chat_stream(
5455
print(data)
5556
```
5657
</TabItem>
58+
59+
<TabItem value="openai-sdk">
60+
61+
```python
62+
from openai import OpenAI
63+
DBGPT_API_KEY = "dbgpt"
64+
65+
client = OpenAI(
66+
api_key=DBGPT_API_KEY,
67+
base_url="http://localhost:5670/api/v2"
68+
)
69+
response = client.chat.completions.create(
70+
model="gpt-4o",
71+
messages=[
72+
{
73+
"role": "user",
74+
"content": "Hello",
75+
},
76+
],
77+
extra_body={
78+
"chat_mode": "chat_normal",
79+
},
80+
stream=True,
81+
max_tokens=2048,
82+
)
83+
84+
for chunk in response:
85+
delta_content = chunk.choices[0].delta.content
86+
print(delta_content, end="", flush=True)
87+
```
88+
</TabItem>
5789
</Tabs>
5890

91+
5992
### Chat Completion Stream Response
6093
```commandline
6194
data: {"id": "chatcmpl-ba6fb52e-e5b2-11ee-b031-acde48001122", "model": "gpt-4o", "choices": [{"index": 0, "delta": {"role": "assistant", "content": "Hello"}}]}
@@ -110,6 +143,8 @@ from dbgpt_client import Client
110143
DBGPT_API_KEY = "dbgpt"
111144
client = Client(api_key=DBGPT_API_KEY)
112145
response = await client.chat(model="gpt-4o" ,messages="hello")
146+
print(response)
147+
await client.aclose()
113148
```
114149
</TabItem>
115150
</Tabs>

docs/docs/api/datasource.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import TabItem from '@theme/TabItem';
2121
values={[
2222
{label: 'Curl', value: 'curl'},
2323
{label: 'Python', value: 'python'},
24+
{label: 'Python(OpenAI SDK)', value: 'openai-sdk'},
2425
]
2526
}>
2627

@@ -56,6 +57,40 @@ res = client.chat(
5657
)
5758
```
5859
</TabItem>
60+
61+
<TabItem value="openai-sdk">
62+
63+
```python
64+
from openai import OpenAI
65+
66+
DBGPT_API_KEY = "dbgpt"
67+
DB_NAME="{your_db_name}"
68+
69+
client = OpenAI(
70+
api_key=DBGPT_API_KEY,
71+
base_url="http://localhost:5670/api/v2"
72+
)
73+
response = client.chat.completions.create(
74+
model="gpt-4o",
75+
messages=[
76+
{
77+
"role": "user",
78+
"content": "Hello",
79+
},
80+
],
81+
extra_body={
82+
"chat_mode": "chat_data",
83+
"chat_param": DB_NAME,
84+
},
85+
stream=True,
86+
max_tokens=2048,
87+
)
88+
89+
for chunk in response:
90+
delta_content = chunk.choices[0].delta.content
91+
print(delta_content, end="", flush=True)
92+
```
93+
</TabItem>
5994
</Tabs>
6095

6196
#### Chat Completion Response

docs/docs/api/flow.md

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import TabItem from '@theme/TabItem';
2121
values={[
2222
{label: 'Curl', value: 'curl'},
2323
{label: 'Python', value: 'python'},
24+
{label: 'Python(OpenAI SDK)', value: 'openai-sdk'},
2425
]
2526
}>
2627

@@ -34,7 +35,7 @@ curl -X POST "http://localhost:5670/api/v2/chat/completions" \
3435
-H "Authorization: Bearer $DBGPT_API_KEY" \
3536
-H "accept: application/json" \
3637
-H "Content-Type: application/json" \
37-
-d "{\"messages\":\"Hello\",\"model\":\"chatgpt_proxyllm\", \"chat_mode\": \"chat_flow\", \"chat_param\": \"$FLOW_ID\"}"
38+
-d "{\"messages\":\"Hello\",\"model\":\"gpt-4o\", \"chat_mode\": \"chat_flow\", \"chat_param\": \"$FLOW_ID\"}"
3839

3940
```
4041
</TabItem>
@@ -50,18 +51,53 @@ FLOW_ID="{YOUR_FLOW_ID}"
5051
client = Client(api_key=DBGPT_API_KEY)
5152
async for data in client.chat_stream(
5253
messages="Introduce AWEL",
53-
model="chatgpt_proxyllm",
54+
model="gpt-4o",
5455
chat_mode="chat_flow",
5556
chat_param=FLOW_ID
5657
):
5758
print(data)
5859
```
5960
</TabItem>
61+
62+
63+
<TabItem value="openai-sdk">
64+
65+
```python
66+
from openai import OpenAI
67+
68+
DBGPT_API_KEY = "dbgpt"
69+
FLOW_ID="{YOUR_FLOW_ID}"
70+
71+
client = OpenAI(
72+
api_key=DBGPT_API_KEY,
73+
base_url="http://localhost:5670/api/v2"
74+
)
75+
response = client.chat.completions.create(
76+
model="gpt-4o",
77+
messages=[
78+
{
79+
"role": "user",
80+
"content": "Hello",
81+
},
82+
],
83+
extra_body={
84+
"chat_mode": "chat_flow",
85+
"chat_param": FLOW_ID,
86+
},
87+
stream=True,
88+
max_tokens=2048,
89+
)
90+
91+
for chunk in response:
92+
delta_content = chunk.choices[0].delta.content
93+
print(delta_content, end="", flush=True)
94+
```
95+
</TabItem>
6096
</Tabs>
6197

6298
#### Chat Completion Stream Response
6399
```commandline
64-
data: {"id": "579f8862-fc4b-481e-af02-a127e6d036c8", "created": 1710918094, "model": "chatgpt_proxyllm", "choices": [{"index": 0, "delta": {"role": "assistant", "content": "\n\n"}}]}
100+
data: {"id": "579f8862-fc4b-481e-af02-a127e6d036c8", "created": 1710918094, "model": "gpt-4o", "choices": [{"index": 0, "delta": {"role": "assistant", "content": "\n\n"}}]}
65101
```
66102
### Create Flow
67103

docs/docs/api/introduction.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This is the introduction to the DB-GPT API documentation. You can interact with the API through HTTP requests from any language, via our official Python Client bindings.
44

5-
# Authentication
5+
## Authentication
66
The DB-GPT API uses API keys for authentication. Visit your API Keys page to retrieve the API key you'll use in your requests.
77

88
Production requests must be routed through your own backend server where your API key can be securely loaded from an environment variable or key management service.
@@ -34,10 +34,18 @@ API_KEYS - The list of API keys that are allowed to access the API. Each of the
3434
API_KEYS=dbgpt
3535
```
3636

37-
## Installation
37+
## Using the DB-GPT official Python Client
38+
3839
If you use Python, you should install the official DB-GPT Client package from PyPI:
3940

4041
```bash
41-
pip install "dbgpt[client]>=0.5.2"
42+
pip install "dbgpt-client>=0.7.1rc0"
4243
```
4344

45+
## Using the OpenAI Python SDK
46+
47+
In some chat cases, you can use the OpenAI Python SDK to interact with the DB-GPT API. The DB-GPT API is compatible with the OpenAI API.
48+
49+
```bash
50+
pip install openai
51+
```

docs/docs/api/knowledge.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import TabItem from '@theme/TabItem';
2121
values={[
2222
{label: 'Curl', value: 'curl'},
2323
{label: 'Python', value: 'python'},
24+
{label: 'Python(OpenAI SDK)', value: 'openai-sdk'},
2425
]
2526
}>
2627

@@ -57,6 +58,41 @@ async for data in client.chat_stream(
5758
print(data)
5859
```
5960
</TabItem>
61+
62+
63+
<TabItem value="openai-sdk">
64+
65+
```python
66+
from openai import OpenAI
67+
68+
DBGPT_API_KEY = "dbgpt"
69+
SPACE_NAME="{YOUR_SPACE_NAME}"
70+
71+
client = OpenAI(
72+
api_key=DBGPT_API_KEY,
73+
base_url="http://localhost:5670/api/v2"
74+
)
75+
response = client.chat.completions.create(
76+
model="gpt-4o",
77+
messages=[
78+
{
79+
"role": "user",
80+
"content": "Hello",
81+
},
82+
],
83+
extra_body={
84+
"chat_mode": "chat_knowledge",
85+
"chat_param": SPACE_NAME,
86+
},
87+
stream=True,
88+
max_tokens=2048,
89+
)
90+
91+
for chunk in response:
92+
delta_content = chunk.choices[0].delta.content
93+
print(delta_content, end="", flush=True)
94+
```
95+
</TabItem>
6096
</Tabs>
6197

6298
#### Chat Completion Response

docs/docs/application/advanced_tutorial/api.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ In the DB-GPT project, we defined a service-oriented multi-model management fram
1313

1414
```python
1515
import openai
16-
openai.api_key = "EMPTY"
17-
openai.api_base = "http://127.0.0.1:8100/api/v1"
18-
model = "vicuna-13b-v1.5"
16+
model = "Qwen/QwQ-32B"
1917

20-
completion = openai.ChatCompletion.create(
18+
client = openai.OpenAI(
19+
api_key="EMPTY",
20+
base_url="http://127.0.0.1:8100/api/v1",
21+
)
22+
completion = client.chat.completions.create(
2123
model=model,
2224
messages=[{"role": "user", "content": "hello"}]
2325
)

0 commit comments

Comments
 (0)