Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor text2sql. #1304

Merged
merged 16 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/_run-docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ jobs:
SERVING_TOKEN: ${{ secrets.SERVING_TOKEN }}
IMAGE_REPO: ${{ inputs.registry }}
IMAGE_TAG: ${{ inputs.tag }}
opea_branch: "yao531441/text2sql"
example: ${{ inputs.example }}
hardware: ${{ inputs.hardware }}
test_case: ${{ matrix.test_case }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-docker-compose-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
name: E2E test with docker compose

on:
pull_request_target:
pull_request:
branches: ["main", "*rc"]
types: [opened, reopened, ready_for_review, synchronize] # added `ready_for_review` since draft is skipped
paths:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
run: |
cd ..
git clone https://github.com/opea-project/GenAIComps.git
cd GenAIComps && git checkout yao531441/text2sql

- name: Check for Missing Dockerfile Paths in GenAIComps
run: |
Expand Down
16 changes: 8 additions & 8 deletions DBQnA/docker_compose/intel/cpu/xeon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ First of all, you need to build Docker Images locally. This step can be ignored
```bash
git clone https://github.com/opea-project/GenAIComps.git
cd GenAIComps
docker build --no-cache -t opea/texttosql:comps -f comps/texttosql/langchain/Dockerfile .
docker build --no-cache -t opea/text2sql:comps -f comps/text2sql/src/Dockerfile .

```

Expand All @@ -21,13 +21,13 @@ Build the frontend Docker image based on react framework via below command:

```bash
cd GenAIExamples/DBQnA/ui
docker build --no-cache -t opea/texttosql-react-ui:latest -f docker/Dockerfile.react .
docker build --no-cache -t opea/text2sql-react-ui:latest -f docker/Dockerfile.react .

```

Then run the command `docker images`, you will have the following Docker Images:

1. `opea/texttosql:latest`
1. `opea/text2sql:latest`
2. `opea/dbqna-react-ui:latest`

## 🚀 Start Microservices
Expand Down Expand Up @@ -62,7 +62,7 @@ export LLM_MODEL_ID="mistralai/Mistral-7B-Instruct-v0.3"
export POSTGRES_USER=postgres
export POSTGRES_PASSWORD=testpwd
export POSTGRES_DB=chinook
export texttosql_port=9090
export text2sql_port=9090
```

Note: Please replace with `your_ip` with your external IP address, do not use localhost.
Expand Down Expand Up @@ -90,22 +90,22 @@ We will use [Chinook](https://github.com/lerocha/chinook-database) sample databa

```bash

docker run --name test-texttosql-postgres --ipc=host -e POSTGRES_USER=${POSTGRES_USER} -e POSTGRES_HOST_AUTH_METHOD=trust -e POSTGRES_DB=${POSTGRES_DB} -e POSTGRES_PASSWORD=${POSTGRES_PASSWORD} -p 5442:5432 -d -v $WORKPATH/comps/texttosql/langchain/chinook.sql:/docker-entrypoint-initdb.d/chinook.sql postgres:latest
docker run --name test-text2sql-postgres --ipc=host -e POSTGRES_USER=${POSTGRES_USER} -e POSTGRES_HOST_AUTH_METHOD=trust -e POSTGRES_DB=${POSTGRES_DB} -e POSTGRES_PASSWORD=${POSTGRES_PASSWORD} -p 5442:5432 -d -v $WORKPATH/comps/text2sql/langchain/chinook.sql:/docker-entrypoint-initdb.d/chinook.sql postgres:latest
```

- Start TGI Service

```bash

docker run -d --name="test-texttosql-tgi-endpoint" --ipc=host -p $TGI_PORT:80 -v ./data:/data --shm-size 1g -e HUGGINGFACEHUB_API_TOKEN=${HUGGINGFACEHUB_API_TOKEN} -e HF_TOKEN=${HF_TOKEN} -e model=${model} ghcr.io/huggingface/text-generation-inference:2.1.0 --model-id $model
docker run -d --name="test-text2sql-tgi-endpoint" --ipc=host -p $TGI_PORT:80 -v ./data:/data --shm-size 1g -e HUGGINGFACEHUB_API_TOKEN=${HUGGINGFACEHUB_API_TOKEN} -e HF_TOKEN=${HF_TOKEN} -e model=${model} ghcr.io/huggingface/text-generation-inference:2.1.0 --model-id $model
```

- Start Text-to-SQL Service

```bash
unset http_proxy

docker run -d --name="test-texttosql-server" --ipc=host -p ${texttosql_port}:8090 --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e TGI_LLM_ENDPOINT=$TGI_LLM_ENDPOINT opea/texttosql:latest
docker run -d --name="test-text2sql-server" --ipc=host -p ${text2sql_port}:8090 --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e TGI_LLM_ENDPOINT=$TGI_LLM_ENDPOINT opea/text2sql:latest
```

- Start React UI service
Expand Down Expand Up @@ -141,7 +141,7 @@ curl --location http://${your_ip}:9090/v1/postgres/health \
#### 3.2.2 Invoke the microservice.

```bash
curl http://${your_ip}:9090/v1/texttosql\
curl http://${your_ip}:9090/v1/text2sql\
-X POST \
-d '{"input_text": "Find the total number of Albums.","conn_str": {"user": "'${POSTGRES_USER}'","password": "'${POSTGRES_PASSWORD}'","host": "'${your_ip}'", "port": "5442", "database": "'${POSTGRES_DB}'"}}' \
-H 'Content-Type: application/json'
Expand Down
15 changes: 8 additions & 7 deletions DBQnA/docker_compose/intel/cpu/xeon/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ services:
no_proxy: ${no_proxy}
http_proxy: ${http_proxy}
https_proxy: ${https_proxy}
HF_TOKEN: ${HF_TOKEN}
HF_TOKEN: ${HUGGINGFACEHUB_API_TOKEN}
HUGGINGFACEHUB_API_TOKEN: ${HUGGINGFACEHUB_API_TOKEN}
shm_size: 1g
command: --model-id ${LLM_MODEL_ID}

Expand All @@ -32,19 +33,19 @@ services:
volumes:
- ./chinook.sql:/docker-entrypoint-initdb.d/chinook.sql

texttosql-service:
image: opea/texttosql:latest
container_name: texttosql-service
text2sql-service:
image: ${REGISTRY:-opea}/text2sql:${TAG:-latest}
container_name: text2sql-service
ports:
- "9090:8090"
- "9090:8080"
environment:
- TGI_LLM_ENDPOINT=${TGI_LLM_ENDPOINT}

dbqna-xeon-react-ui-server:
image: opea/dbqna-react-ui:latest
image: ${REGISTRY:-opea}/text2sql-react-ui:${TAG:-latest}
container_name: dbqna-xeon-react-ui-server
depends_on:
- texttosql-service
- text2sql-service
ports:
- "5174:80"
environment:
Expand Down
10 changes: 5 additions & 5 deletions DBQnA/docker_image_build/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
# SPDX-License-Identifier: Apache-2.0

services:
texttosql:
text2sql:
build:
context: GenAIComps
dockerfile: comps/texttosql/langchain/Dockerfile
dockerfile: comps/text2sql/src/Dockerfile
args:
http_proxy: ${http_proxy}
https_proxy: ${https_proxy}
no_proxy: ${no_proxy}
image: ${REGISTRY:-opea}/texttosql:${TAG:-latest}
texttosql-react-ui:
image: ${REGISTRY:-opea}/text2sql:${TAG:-latest}
text2sql-react-ui:
build:
context: ../ui
dockerfile: ./docker/Dockerfile.react
args:
http_proxy: ${http_proxy}
https_proxy: ${https_proxy}
no_proxy: ${no_proxy}
image: ${REGISTRY:-opea}/texttosql-react-ui:${TAG:-latest}
image: ${REGISTRY:-opea}/text2sql-react-ui:${TAG:-latest}
70 changes: 29 additions & 41 deletions DBQnA/tests/test_compose_on_xeon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,66 +4,54 @@

set -xe

IMAGE_REPO=${IMAGE_REPO:-"opea"}
IMAGE_TAG=${IMAGE_TAG:-"latest"}
echo "REGISTRY=IMAGE_REPO=${IMAGE_REPO}"
echo "TAG=IMAGE_TAG=${IMAGE_TAG}"
export REGISTRY=${IMAGE_REPO}
export TAG=${IMAGE_TAG}

WORKPATH=$(dirname "$PWD")
LOG_PATH="$WORKPATH/tests"
ip_address=$(hostname -I | awk '{print $1}')
tgi_port=8008
tgi_volume=$WORKPATH/data

export model="meta-llama/Meta-Llama-3-8B-Instruct"
export HUGGINGFACEHUB_API_TOKEN=${HUGGINGFACEHUB_API_TOKEN}
export POSTGRES_USER=postgres
export POSTGRES_PASSWORD=testpwd
export POSTGRES_DB=chinook
export TEXTTOSQL_PORT=9090
export TGI_LLM_ENDPOINT="http://${ip_address}:${tgi_port}"


function build_docker_images() {
echo $WORKPATH
OPEAPATH=$(realpath "$WORKPATH/../..")

echo "Building Text to Sql service..."
cd $OPEAPATH
rm -rf GenAIComps/
git clone https://github.com/opea-project/GenAIComps.git
cd $OPEAPATH/GenAIComps
docker build --no-cache -t opea/texttosql:latest -f comps/texttosql/langchain/Dockerfile .

echo "Building React UI service..."
cd $OPEAPATH/GenAIExamples/DBQnA/ui
docker build --no-cache -t opea/dbqna-react-ui:latest -f docker/Dockerfile.react .
cd $WORKPATH/docker_image_build
git clone https://github.com/opea-project/GenAIComps.git && cd GenAIComps && git checkout "${opea_branch:-"main"}" && cd ../

echo "Build all the images with --no-cache, check docker_image_build.log for details..."
docker compose -f build.yaml build --no-cache > ${LOG_PATH}/docker_image_build.log
}

function start_service() {

docker run --name test-texttosql-postgres --ipc=host -e POSTGRES_USER=${POSTGRES_USER} -e POSTGRES_HOST_AUTH_METHOD=trust -e POSTGRES_DB=${POSTGRES_DB} -e POSTGRES_PASSWORD=${POSTGRES_PASSWORD} -p 5442:5432 -d -v $WORKPATH/docker_compose/intel/cpu/xeon/chinook.sql:/docker-entrypoint-initdb.d/chinook.sql postgres:latest

docker run -d --name="test-texttosql-tgi-endpoint" --ipc=host -p $tgi_port:80 -v ./data:/data --shm-size 1g -e HUGGINGFACEHUB_API_TOKEN=${HUGGINGFACEHUB_API_TOKEN} -e HF_TOKEN=${HUGGINGFACEHUB_API_TOKEN} -e model=${model} ghcr.io/huggingface/text-generation-inference:2.1.0 --model-id $model


docker run -d --name="test-texttosql-server" --ipc=host -p $TEXTTOSQL_PORT:8090 --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e TGI_LLM_ENDPOINT=$TGI_LLM_ENDPOINT opea/texttosql:latest
cd $WORKPATH/docker_compose/intel/cpu/xeon
export model="mistralai/Mistral-7B-Instruct-v0.3"
export LLM_MODEL_ID=${model}
export HUGGINGFACEHUB_API_TOKEN=${HUGGINGFACEHUB_API_TOKEN}
export POSTGRES_USER=postgres
export POSTGRES_PASSWORD=testpwd
export POSTGRES_DB=chinook
export TEXT2SQL_PORT=9090
export TGI_LLM_ENDPOINT="http://${ip_address}:${tgi_port}"

# Start Docker Containers
docker compose -f compose.yaml up -d > ${LOG_PATH}/start_services_with_compose.log

# check whether tgi is fully ready.
n=0
until [[ "$n" -ge 100 ]] || [[ $ready == true ]]; do
docker logs test-texttosql-tgi-endpoint > ${LOG_PATH}/tgi.log
docker logs tgi-service > ${LOG_PATH}/tgi.log
n=$((n+1))
if grep -q Connected ${LOG_PATH}/tgi.log; then
break
fi
sleep 5s
done
sleep 5s

# Run the UI container
docker run -d --name="test-dbqna-react-ui-server" --ipc=host -p 5174:80 -e no_proxy=$no_proxy -e https_proxy=$https_proxy -e http_proxy=$http_proxy opea/dbqna-react-ui:latest

}

function validate_microservice() {
result=$(http_proxy="" curl --connect-timeout 5 --max-time 120000 http://${ip_address}:$TEXTTOSQL_PORT/v1/texttosql\
result=$(http_proxy="" curl --connect-timeout 5 --max-time 120000 http://${ip_address}:$TEXT2SQL_PORT/v1/text2sql\
-X POST \
-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}'" }}' \
-H 'Content-Type: application/json')
Expand All @@ -73,8 +61,8 @@ function validate_microservice() {
echo "Result correct."
else
echo "Result wrong. Received was $result"
docker logs test-texttosql-server > ${LOG_PATH}/texttosql.log
docker logs test-texttosql-tgi-endpoint > ${LOG_PATH}/tgi.log
docker logs text2sql-service > ${LOG_PATH}/text2sql.log
docker logs tgi-service > ${LOG_PATH}/tgi.log
exit 1
fi

Expand Down Expand Up @@ -110,8 +98,8 @@ function validate_frontend() {
}

function stop_docker() {
cid=$(docker ps -aq --filter "name=test-*")
if [[ ! -z "$cid" ]]; then docker stop $cid && docker rm $cid && sleep 1s; fi
cd $WORKPATH/docker_compose/intel/cpu/xeon
docker compose stop && docker compose rm -f
}

function main() {
Expand Down
5 changes: 3 additions & 2 deletions DBQnA/ui/react/src/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const getHostIP = () => {
test('testing api with dynamic host', async () => {
// Get the dynamic host IP
const host = await getHostIP();
const endpointUrl = `http://${host}:9090/v1/texttosql`;
const endpointUrl = `http://${host}:9090/v1/text2sql`;

const formData = {
user: 'postgres',
Expand All @@ -43,9 +43,10 @@ test('testing api with dynamic host', async () => {
expect(response.status).toBe(200);

const result = response.data.result;
console.log(result);
expect(result.hasOwnProperty('sql')).toBe(true);
expect(result.hasOwnProperty('output')).toBe(true);
expect(result.hasOwnProperty('input')).toBe(true);
expect(result.input).toBe(question);
expect(result.input.input_text).toBe(question);

}, apiTimeOutInSeconds * 1000);
4 changes: 2 additions & 2 deletions DBQnA/ui/react/src/components/DbConnect/DBConnect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const DBConnect: React.FC = () => {
};

let api_response: Record<string, any>;
api_response = await axios.post(`${TEXT_TO_SQL_URL}/texttosql`, payload);
api_response = await axios.post(`${TEXT_TO_SQL_URL}/text2sql`, payload);

setSqlQuery(api_response.data.result.sql); // Assuming the API returns an SQL query
setQueryOutput(api_response.data.result.output);
Expand Down Expand Up @@ -163,7 +163,7 @@ const DBConnect: React.FC = () => {
</div>

{/* DBQnA Section */}
<div className={styleClasses.textToSQLSection}>
<div className={styleClasses.text2SQLSection}>
<Title order={1}>DBQnA</Title>
{isConnected && (
<form className={styleClasses.form} onSubmit={handleGenerateSQL}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
}

.dbConnectSection,
.textToSQLSection {
.text2SQLSection {
flex: 1; /* Allow each section to take up equal space */
padding: 20px;
background-color: white;
Expand Down
Loading