Skip to content

Commit 3c7f1e4

Browse files
authored
Porting DBQnA to Text2Query (#2291)
Signed-off-by: Yi Yao <yi.a.yao@intel.com>
1 parent ba6ff93 commit 3c7f1e4

9 files changed

Lines changed: 83 additions & 55 deletions

File tree

DBQnA/docker_compose/amd/gpu/rocm/README.md

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@ This document outlines the deployment process for DBQnA application which helps
99

1010
This section describes how to quickly deploy and test the DBQnA service manually on AMD GPU (ROCm). The basic steps are:
1111

12-
1. [Access the Code](#access-the-code)
13-
2. [Generate a HuggingFace Access Token](#generate-a-huggingface-access-token)
14-
3. [Configure the Deployment Environment](#configure-the-deployment-environment)
15-
4. [Deploy the Service Using Docker Compose](#deploy-the-service-using-docker-compose)
16-
5. [Check the Deployment Status](#check-the-deployment-status)
17-
6. [Test the Pipeline](#test-the-pipeline)
18-
7. [Cleanup the Deployment](#cleanup-the-deployment)
12+
- [Example DBQnA Deployment on AMD GPU (ROCm)](#example-dbqna-deployment-on-amd-gpu-rocm)
13+
- [DBQnA Quick Start Deployment](#dbqna-quick-start-deployment)
14+
- [Access the Code](#access-the-code)
15+
- [Generate a HuggingFace Access Token](#generate-a-huggingface-access-token)
16+
- [Configure the Deployment Environment](#configure-the-deployment-environment)
17+
- [Deploy the Service Using Docker Compose](#deploy-the-service-using-docker-compose)
18+
- [Check the Deployment Status](#check-the-deployment-status)
19+
- [Test the Pipeline](#test-the-pipeline)
20+
- [Cleanup the Deployment](#cleanup-the-deployment)
21+
- [DBQnA Docker Compose Files](#dbqna-docker-compose-files)
22+
- [DBQnA Service Configuration for AMD GPUs](#dbqna-service-configuration-for-amd-gpus)
1923

2024
### Access the Code
2125

@@ -73,10 +77,11 @@ For the default deployment, the following 4 containers should be running.
7377
Once the DBQnA service are running, test the pipeline using the following command:
7478

7579
```bash
76-
curl http://${host_ip}:${DBQNA_TEXT_TO_SQL_PORT}/v1/texttosql \
80+
url="postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${host_ip}:5442/${POSTGRES_DB}"
81+
curl --connect-timeout 5 --max-time 120000 http://${host_ip}:9090/v1/text2query\
7782
-X POST \
78-
-d '{"input_text": "Find the total number of Albums.","conn_str": {"user": "'${POSTGRES_USER}'","password": "'${POSTGRES_PASSWORD}'","host": "'${host_ip}'", "port": "5442", "database": "'${POSTGRES_DB}'"}}' \
79-
-H 'Content-Type: application/json'
83+
-d '{"query": "Find the total number of Albums.","conn_type": "sql", "conn_url": "'${url}'", "conn_user": "'${POSTGRES_USER}'","conn_password": "'${POSTGRES_PASSWORD}'","conn_dialect": "postgresql" }' \
84+
-H 'Content-Type: application/json')
8085
```
8186

8287
### Cleanup the Deployment
@@ -97,7 +102,7 @@ The compose.yaml is default compose file using tgi as serving framework
97102
| ----------------- | -------------------------------------------------------- |
98103
| dbqna-tgi-service | ghcr.io/huggingface/text-generation-inference:2.4.1-rocm |
99104
| postgres | postgres:latest |
100-
| text2sql | opea/text2sql:latest |
105+
| text2sql | opea/text2query-sql:latest |
101106
| text2sql-react-ui | opea/text2sql-react-ui:latest |
102107

103108
## DBQnA Service Configuration for AMD GPUs
@@ -108,5 +113,5 @@ The table provides a comprehensive overview of the DBQnA service utilized across
108113
| ----------------- | -------------------------------------------------------- | -------- | --------------------------------------------------------------------------------------------------- |
109114
| dbqna-tgi-service | ghcr.io/huggingface/text-generation-inference:2.4.1-rocm | No | Specific to the TGI deployment, focuses on text generation inference using AMD GPU (ROCm) hardware. |
110115
| postgres | postgres:latest | No | Provides the relational database backend for storing and querying data used by the DBQnA pipeline. |
111-
| text2sql | opea/text2sql:latest | No | Handles text-to-SQL conversion tasks. |
116+
| text2sql | opea/text2query-sql:latest | No | Handles text-to-SQL conversion tasks. |
112117
| text2sql-react-ui | opea/text2sql-react-ui:latest | No | Provides the user interface for the DBQnA service. |

DBQnA/docker_compose/amd/gpu/rocm/compose.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,16 @@ services:
4747
- ./chinook.sql:/docker-entrypoint-initdb.d/chinook.sql
4848

4949
text2sql:
50-
image: opea/text2sql:latest
50+
image: opea/text2query-sql:latest
5151
container_name: text2sql
5252
ports:
53-
- "${DBQNA_TEXT_TO_SQL_PORT:-9090}:8080"
53+
- "${DBQNA_TEXT_TO_SQL_PORT:-9090}:9097"
5454
environment:
5555
TGI_LLM_ENDPOINT: ${DBQNA_TGI_LLM_ENDPOINT}
56+
TEXT2QUERY_COMPONENT_NAME: OPEA_TEXT2QUERY_SQL
57+
depends_on:
58+
- dbqna-tgi-service
59+
- postgres
5660

5761
text2sql-react-ui:
5862
image: opea/text2sql-react-ui:latest

DBQnA/docker_compose/intel/cpu/xeon/README.md

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@ This document outlines the deployment process for DBQnA application which helps
99

1010
This section describes how to quickly deploy and test the DBQnA service manually on Intel® Xeon® platform. The basic steps are:
1111

12-
1. [Access the Code](#access-the-code)
13-
2. [Generate a HuggingFace Access Token](#generate-a-huggingface-access-token)
14-
3. [Configure the Deployment Environment](#configure-the-deployment-environment)
15-
4. [Deploy the Service Using Docker Compose](#deploy-the-service-using-docker-compose)
16-
5. [Check the Deployment Status](#check-the-deployment-status)
17-
6. [Test the Pipeline](#test-the-pipeline)
18-
7. [Cleanup the Deployment](#cleanup-the-deployment)
12+
- [Example DBQnA Deployment on Intel® Xeon® Platform](#example-dbqna-deployment-on-intel-xeon-platform)
13+
- [DBQnA Quick Start Deployment](#dbqna-quick-start-deployment)
14+
- [Access the Code](#access-the-code)
15+
- [Generate a HuggingFace Access Token](#generate-a-huggingface-access-token)
16+
- [Configure the Deployment Environment](#configure-the-deployment-environment)
17+
- [Deploy the Service Using Docker Compose](#deploy-the-service-using-docker-compose)
18+
- [Check the Deployment Status](#check-the-deployment-status)
19+
- [Test the Pipeline](#test-the-pipeline)
20+
- [Cleanup the Deployment](#cleanup-the-deployment)
21+
- [DBQnA Docker Compose Files](#dbqna-docker-compose-files)
22+
- [DBQnA Service Configuration](#dbqna-service-configuration)
1923

2024
### Access the Code
2125

@@ -80,18 +84,19 @@ CONTAINER ID IMAGE
8084
2728db31368b opea/text2sql-react-ui:latest "nginx -g 'daemon of…" 9 minutes ago Up 9 minutes 0.0.0.0:5174->80/tcp, :::5174->80/tcp dbqna-xeon-react-ui-server
8185
0ab75b92c300 postgres:latest "docker-entrypoint.s…" 9 minutes ago Up 9 minutes 0.0.0.0:5442->5432/tcp, :::5442->5432/tcp postgres-container
8286
2662a69b515b ghcr.io/huggingface/text-generation-inference:2.4.0-intel-cpu "text-generation-lau…" 9 minutes ago Up 9 minutes 0.0.0.0:8008->80/tcp, :::8008->80/tcp tgi-service
83-
bb44512be80e opea/text2sql:latest "python opea_text2sq…" 9 minutes ago Up 9 minutes 0.0.0.0:9090->8080/tcp, :::9090->8080/tcp text2sql-service
87+
bb44512be80e opea/text2query-sql:latest "python opea_text2sq…" 9 minutes ago Up 9 minutes 0.0.0.0:9090->8080/tcp, :::9090->8080/tcp text2sql-service
8488
```
8589

8690
### Test the Pipeline
8791

8892
Once the DBQnA service are running, test the pipeline using the following command:
8993

9094
```bash
91-
curl http://${host_ip}:9090/v1/text2sql\
95+
url="postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${host_ip}:5442/${POSTGRES_DB}"
96+
curl --connect-timeout 5 --max-time 120000 http://${host_ip}:9090/v1/text2query\
9297
-X POST \
93-
-d '{"input_text": "Find the total number of Albums.","conn_str": {"user": "'${POSTGRES_USER}'","password": "'${POSTGRES_PASSWORD}'","host": "'${host_ip}'", "port": "5442", "database": "'${POSTGRES_DB}'"}}' \
94-
-H 'Content-Type: application/json'
98+
-d '{"query": "Find the total number of Albums.","conn_type": "sql", "conn_url": "'${url}'", "conn_user": "'${POSTGRES_USER}'","conn_password": "'${POSTGRES_PASSWORD}'","conn_dialect": "postgresql" }' \
99+
-H 'Content-Type: application/json')
95100
```
96101

97102
### Cleanup the Deployment
@@ -121,7 +126,7 @@ The compose.yaml is default compose file using tgi as serving framework
121126
| -------------------------- | ------------------------------------------------------------- |
122127
| tgi-service | ghcr.io/huggingface/text-generation-inference:2.4.0-intel-cpu |
123128
| postgres | postgres:latest |
124-
| text2sql | opea/text2sql:latest |
129+
| text2sql | opea/text2query-sql:latest |
125130
| dbqna-xeon-react-ui-server | opea/text2sql-react-ui:latest |
126131

127132
## DBQnA Service Configuration
@@ -132,5 +137,5 @@ The table provides a comprehensive overview of the DBQnA service utilized across
132137
| -------------------------- | ------------------------------------------------------------- | -------- | --------------------------------------------------------------------------------------------------- |
133138
| tgi-service | ghcr.io/huggingface/text-generation-inference:2.4.0-intel-cpu | No | Specific to the TGI deployment, focuses on text generation inference using AMD GPU (ROCm) hardware. |
134139
| postgres | postgres:latest | No | Provides the relational database backend for storing and querying data used by the DBQnA pipeline. |
135-
| text2sql | opea/text2sql:latest | No | Handles text-to-SQL conversion tasks. |
140+
| text2sql | opea/text2query-sql:latest | No | Handles text-to-SQL conversion tasks. |
136141
| dbqna-xeon-react-ui-server | opea/text2sql-react-ui:latest | No | Provides the user interface for the DBQnA service. |

DBQnA/docker_compose/intel/cpu/xeon/compose.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,16 @@ services:
3131
- ./chinook.sql:/docker-entrypoint-initdb.d/chinook.sql
3232

3333
text2sql-service:
34-
image: ${REGISTRY:-opea}/text2sql:${TAG:-latest}
34+
image: ${REGISTRY:-opea}/text2query-sql:${TAG:-latest}
3535
container_name: text2sql-service
3636
ports:
37-
- "${TEXT2SQL_PORT}:8080"
37+
- "${TEXT2SQL_PORT}:9097"
3838
environment:
3939
- TGI_LLM_ENDPOINT=${TGI_LLM_ENDPOINT}
40+
- TEXT2QUERY_COMPONENT_NAME=OPEA_TEXT2QUERY_SQL
41+
depends_on:
42+
- tgi-service
43+
- postgres
4044

4145
dbqna-xeon-react-ui-server:
4246
image: ${REGISTRY:-opea}/text2sql-react-ui:${TAG:-latest}

DBQnA/docker_image_build/build.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
services:
5-
text2sql:
5+
text2query-sql:
66
build:
77
context: GenAIComps
8-
dockerfile: comps/text2sql/src/Dockerfile
8+
dockerfile: comps/text2query/src/Dockerfile
99
args:
1010
IMAGE_REPO: ${REGISTRY:-opea}
1111
BASE_TAG: ${TAG:-latest}
1212
http_proxy: ${http_proxy}
1313
https_proxy: ${https_proxy}
1414
no_proxy: ${no_proxy}
15-
image: ${REGISTRY:-opea}/text2sql:${TAG:-latest}
15+
image: ${REGISTRY:-opea}/text2query-sql:${TAG:-latest}
1616
text2sql-react-ui:
1717
build:
1818
context: ../ui
1919
dockerfile: ./docker/Dockerfile.react
2020
args:
2121
texttosql_url: ${build_texttosql_url}
22-
extends: text2sql
22+
extends: text2query-sql
2323
image: ${REGISTRY:-opea}/text2sql-react-ui:${TAG:-latest}

DBQnA/tests/test_compose_on_rocm.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ function start_services() {
4848
}
4949

5050
function validate_microservice() {
51-
result=$(http_proxy="" curl --connect-timeout 5 --max-time 120000 http://${ip_address}:${DBQNA_TEXT_TO_SQL_PORT}/v1/text2sql \
51+
url="postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${ip_address}:5442/${POSTGRES_DB}"
52+
result=$(http_proxy="" curl --connect-timeout 5 --max-time 120000 http://${ip_address}:$TEXT2SQL_PORT/v1/text2query\
5253
-X POST \
53-
-d '{"input_text": "Find the total number of Albums.","conn_str": {"user": "'${POSTGRES_USER}'","password": "'${POSTGRES_PASSWORD}'","host": "'${ip_address}'", "port": "5442", "database": "'${POSTGRES_DB}'" }}' \
54+
-d '{"query": "Find the total number of Albums.","conn_type": "sql", "conn_url": "'${url}'", "conn_user": "'${POSTGRES_USER}'","conn_password": "'${POSTGRES_PASSWORD}'","conn_dialect": "postgresql" }' \
5455
-H 'Content-Type: application/json')
5556

5657
if echo "$result" | jq -e '.result.output' > /dev/null 2>&1; then

DBQnA/tests/test_compose_on_xeon.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ function start_services() {
4848
}
4949

5050
function validate_microservice() {
51-
result=$(http_proxy="" curl --connect-timeout 5 --max-time 120000 http://${ip_address}:$TEXT2SQL_PORT/v1/text2sql\
51+
url="postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${ip_address}:5442/${POSTGRES_DB}"
52+
result=$(http_proxy="" curl --connect-timeout 5 --max-time 120000 http://${ip_address}:$TEXT2SQL_PORT/v1/text2query\
5253
-X POST \
53-
-d '{"input_text": "Find the total number of Albums.","conn_str": {"user": "'${POSTGRES_USER}'","password": "'${POSTGRES_PASSWORD}'","host": "'${ip_address}'", "port": "5442", "database": "'${POSTGRES_DB}'" }}' \
54+
-d '{"query": "Find the total number of Albums.","conn_type": "sql", "conn_url": "'${url}'", "conn_user": "'${POSTGRES_USER}'","conn_password": "'${POSTGRES_PASSWORD}'","conn_dialect": "postgresql" }' \
5455
-H 'Content-Type: application/json')
5556

5657
if echo "$result" | jq -e '.result.output' > /dev/null 2>&1; then

DBQnA/ui/react/src/App.test.tsx

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,17 @@ const getHostIP = () => {
2121
test('testing api with dynamic host', async () => {
2222
// Get the dynamic host IP
2323
const host = await getHostIP();
24-
const endpointUrl = `http://${host}:9090/v1/text2sql`;
25-
26-
const formData = {
27-
user: 'postgres',
28-
database: 'chinook',
29-
host: host,
30-
password: 'testpwd',
31-
port: '5442',
32-
};
33-
24+
const endpointUrl = `http://${host}:9090/v1/text2query`;
25+
const connUrl = `postgresql://postgres:testpwd@${host}:5442/chinook`;
3426
const question = "Find the total number of invoices.";
3527

3628
const payload = {
37-
input_text: question,
38-
conn_str: formData,
29+
query: question,
30+
conn_type: "sql",
31+
conn_url: connUrl,
32+
conn_user: "postgres",
33+
conn_password: "testpwd",
34+
conn_dialect: "postgresql",
3935
};
4036

4137
const response = await axios.post(endpointUrl, payload);
@@ -47,6 +43,6 @@ test('testing api with dynamic host', async () => {
4743
expect(result.hasOwnProperty('sql')).toBe(true);
4844
expect(result.hasOwnProperty('output')).toBe(true);
4945
expect(result.hasOwnProperty('input')).toBe(true);
50-
expect(result.input.input_text).toBe(question);
46+
expect(result.input.query).toBe(question);
5147

5248
}, apiTimeOutInSeconds * 1000);

DBQnA/ui/react/src/components/DbConnect/DBConnect.tsx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,15 @@ const DBConnect: React.FC = () => {
4242
e.preventDefault();
4343
try {
4444
let api_response: Record<string, any>;
45-
let unifiedConnData = {"conn_str":formData};
46-
api_response = await axios.post(`${TEXT_TO_SQL_URL}/postgres/health`, unifiedConnData);
45+
let connUrl = `postgresql://${formData.user}:${formData.password}@${formData.host}:${formData.port}/${formData.database}`;
46+
let unifiedConnData = {
47+
conn_type: "sql",
48+
conn_url: connUrl,
49+
conn_user: formData.user,
50+
conn_password: formData.password,
51+
conn_dialect: "postgresql",
52+
};
53+
api_response = await axios.post(`${TEXT_TO_SQL_URL}/db/health`, unifiedConnData);
4754

4855
setSqlStatus(null);
4956
setSqlError(null);
@@ -74,13 +81,18 @@ const DBConnect: React.FC = () => {
7481
e.preventDefault();
7582
setIsLoading(true);
7683
try {
84+
const connUrl = `postgresql://${formData.user}:${formData.password}@${formData.host}:${formData.port}/${formData.database}`;
7785
const payload = {
78-
input_text: question,
79-
conn_str: formData,
86+
query: question,
87+
conn_type: "sql",
88+
conn_url: connUrl,
89+
conn_user: formData.user,
90+
conn_password: formData.password,
91+
conn_dialect: "postgresql",
8092
};
8193

8294
let api_response: Record<string, any>;
83-
api_response = await axios.post(`${TEXT_TO_SQL_URL}/text2sql`, payload);
95+
api_response = await axios.post(`${TEXT_TO_SQL_URL}/text2query`, payload);
8496

8597
setSqlQuery(api_response.data.result.sql); // Assuming the API returns an SQL query
8698
setQueryOutput(api_response.data.result.output);

0 commit comments

Comments
 (0)