Skip to content

Commit 8c4a253

Browse files
FAQGen Megaservice (#425)
* Added FAQGEN v1 Signed-off-by: Yogesh Pandey <yogesh.pandey@intel.com> --------- Signed-off-by: Yogesh Pandey <yogesh.pandey@intel.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 21b7d11 commit 8c4a253

96 files changed

Lines changed: 4157 additions & 1 deletion

File tree

Some content is hidden

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

.github/workflows/scripts/build_push.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function docker_build() {
4646
# $1 is like "apple orange pear"
4747
for MEGA_SVC in $1; do
4848
case $MEGA_SVC in
49-
"ChatQnA"|"CodeGen"|"CodeTrans"|"DocSum"|"Translation"|"AudioQnA"|"SearchQnA")
49+
"ChatQnA"|"CodeGen"|"CodeTrans"|"DocSum"|"Translation"|"AudioQnA"|"SearchQnA"|"FaqGen")
5050
cd $MEGA_SVC/docker
5151
IMAGE_NAME="$(getImagenameFromMega $MEGA_SVC)"
5252
docker_build ${IMAGE_NAME}

FaqGen/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# FAQ Generation Application
2+
3+
In today's data-driven world, organizations across various industries face the challenge of managing and understanding vast amounts of information. Legal documents, contracts, regulations, and customer inquiries often contain critical insights buried within dense text. Extracting and presenting these insights in a concise and accessible format is crucial for decision-making, compliance, and customer satisfaction.
4+
5+
Our FAQ Generation Application leverages the power of large language models (LLMs) to revolutionize the way you interact with and comprehend complex textual data. By harnessing cutting-edge natural language processing techniques, our application can automatically generate comprehensive and natural-sounding frequently asked questions (FAQs) from your documents, legal texts, customer queries, and other sources. In this example use case, we utilize LangChain to implement FAQ Generation and facilitate LLM inference using Text Generation Inference on Intel Xeon and Gaudi2 processors.
6+
7+
# Deploy FAQ Generation Service
8+
9+
The FAQ Generation service can be effortlessly deployed on either Intel Gaudi2 or Intel XEON Scalable Processors.
10+
11+
## Deploy FAQ Generation on Gaudi
12+
13+
Refer to the [Gaudi Guide](./docker/gaudi/README.md) for instructions on deploying FAQ Generation on Gaudi.
14+
15+
## Deploy FAQ Generation on Xeon
16+
17+
Refer to the [Xeon Guide](./docker/xeon/README.md) for instructions on deploying FAQ Generation on Xeon.
69.8 KB
Loading
100 KB
Loading
143 KB
Loading

FaqGen/docker/Dockerfile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
3+
# Copyright (C) 2024 Intel Corporation
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
FROM langchain/langchain:latest
7+
8+
9+
RUN apt-get update -y && apt-get install -y --no-install-recommends --fix-missing \
10+
libgl1-mesa-glx \
11+
libjemalloc-dev \
12+
vim
13+
14+
RUN useradd -m -s /bin/bash user && \
15+
mkdir -p /home/user && \
16+
chown -R user /home/user/
17+
18+
RUN cd /home/user/ && \
19+
git clone https://github.com/opea-project/GenAIComps.git
20+
21+
RUN cd /home/user/GenAIComps && pip install --no-cache-dir --upgrade pip && \
22+
pip install -r /home/user/GenAIComps/requirements.txt
23+
24+
COPY ./faqgen.py /home/user/faqgen.py
25+
26+
ENV PYTHONPATH=$PYTHONPATH:/home/user/GenAIComps
27+
28+
USER user
29+
30+
WORKDIR /home/user
31+
32+
ENTRYPOINT ["python", "faqgen.py"]

FaqGen/docker/faqgen.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright (C) 2024 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
import asyncio
5+
import os
6+
7+
from comps import FaqGenGateway, MicroService, ServiceOrchestrator, ServiceType
8+
9+
MEGA_SERVICE_HOST_IP = os.getenv("MEGA_SERVICE_HOST_IP", "0.0.0.0")
10+
MEGA_SERVICE_PORT = int(os.getenv("MEGA_SERVICE_PORT", 8888))
11+
LLM_SERVICE_HOST_IP = os.getenv("LLM_SERVICE_HOST_IP", "0.0.0.0")
12+
LLM_SERVICE_PORT = int(os.getenv("LLM_SERVICE_PORT", 9000))
13+
14+
15+
class FaqGenService:
16+
def __init__(self, host="0.0.0.0", port=8000):
17+
self.host = host
18+
self.port = port
19+
self.megaservice = ServiceOrchestrator()
20+
21+
def add_remote_service(self):
22+
llm = MicroService(
23+
name="llm",
24+
host=LLM_SERVICE_HOST_IP,
25+
port=LLM_SERVICE_PORT,
26+
endpoint="/v1/faqgen",
27+
use_remote_service=True,
28+
service_type=ServiceType.LLM,
29+
)
30+
self.megaservice.add(llm)
31+
self.gateway = FaqGenGateway(megaservice=self.megaservice, host="0.0.0.0", port=self.port)
32+
33+
34+
if __name__ == "__main__":
35+
faqgen = FaqGenService(host=MEGA_SERVICE_HOST_IP, port=MEGA_SERVICE_PORT)
36+
faqgen.add_remote_service()

FaqGen/docker/gaudi/README.md

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
# Build MegaService of FAQ Generation on Gaudi
2+
3+
This document outlines the deployment process for a FAQ Generation application utilizing the [GenAIComps](https://github.com/opea-project/GenAIComps.git) microservice pipeline on Intel Gaudi server. The steps include Docker image creation, container deployment via Docker Compose, and service execution to integrate microservices such as llm. We will publish the Docker images to Docker Hub, which will simplify the deployment process for this service.
4+
5+
## 🚀 Build Docker Images
6+
7+
First of all, you need to build Docker Images locally. This step can be ignored once the Docker images are published to Docker hub.
8+
9+
```bash
10+
git clone https://github.com/opea-project/GenAIComps.git
11+
cd GenAIComps
12+
```
13+
14+
### 1. Pull TGI Gaudi Image
15+
16+
As TGI Gaudi has been officially published as a Docker image, we simply need to pull it:
17+
18+
```bash
19+
docker pull ghcr.io/huggingface/tgi-gaudi:1.2.1
20+
```
21+
22+
### 2. Build LLM Image
23+
24+
```bash
25+
docker build -t opea/llm-faqgen-tgi:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/llms/faq-generation/tgi/Dockerfile .
26+
```
27+
28+
### 3. Build MegaService Docker Image
29+
30+
To construct the Mega Service, we utilize the [GenAIComps](https://github.com/opea-project/GenAIComps.git) microservice pipeline within the `faqgen.py` Python script. Build the MegaService Docker image using the command below:
31+
32+
```bash
33+
git clone https://github.com/opea-project/GenAIExamples
34+
cd GenAIExamples/FaqGen/docker/
35+
docker build --no-cache -t opea/faqgen:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f Dockerfile .
36+
```
37+
38+
### 4. Build UI Docker Image
39+
40+
Construct the frontend Docker image using the command below:
41+
42+
```bash
43+
cd GenAIExamples/FaqGen/docker/ui/
44+
docker build -t opea/faqgen-ui:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f ./docker/Dockerfile .
45+
```
46+
47+
### 5. Build react UI Docker Image (Optional)
48+
49+
Build the frontend Docker image based on react framework via below command:
50+
51+
```bash
52+
cd GenAIExamples/FaqGen/docker/ui
53+
export BACKEND_SERVICE_ENDPOINT="http://${host_ip}:8888/v1/faqgen"
54+
docker build -t opea/faqgen-react-ui:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy --build-arg BACKEND_SERVICE_ENDPOINT=$BACKEND_SERVICE_ENDPOINT -f ./docker/Dockerfile.react .
55+
```
56+
57+
Then run the command `docker images`, you will have the following Docker Images:
58+
59+
1. `ghcr.io/huggingface/tgi-gaudi:1.2.1`
60+
2. `opea/llm-faqgen-tgi:latest`
61+
3. `opea/faqgen:latest`
62+
4. `opea/faqgen-ui:latest`
63+
5. `opea/faqgen-react-ui:latest`
64+
65+
## 🚀 Start Microservices and MegaService
66+
67+
### Setup Environment Variables
68+
69+
Since the `docker_compose.yaml` will consume some environment variables, you need to setup them in advance as below.
70+
71+
```bash
72+
export no_proxy=${your_no_proxy}
73+
export http_proxy=${your_http_proxy}
74+
export https_proxy=${your_http_proxy}
75+
export LLM_MODEL_ID="Intel/neural-chat-7b-v3-3"
76+
export TGI_LLM_ENDPOINT="http://${your_ip}:8008"
77+
export HUGGINGFACEHUB_API_TOKEN=${your_hf_api_token}
78+
export MEGA_SERVICE_HOST_IP=${host_ip}
79+
export LLM_SERVICE_HOST_IP=${host_ip}
80+
export BACKEND_SERVICE_ENDPOINT="http://${host_ip}:8888/v1/faqgen"
81+
```
82+
83+
Note: Please replace with `host_ip` with your external IP address, do not use localhost.
84+
85+
### Start Microservice Docker Containers
86+
87+
```bash
88+
cd GenAIExamples/FaqGen/docker/gaudi
89+
docker compose -f docker_compose.yaml up -d
90+
```
91+
92+
### Validate Microservices
93+
94+
1. TGI Service
95+
96+
```bash
97+
curl http://${your_ip}:8008/generate \
98+
-X POST \
99+
-d '{"inputs":"What is Deep Learning?","parameters":{"max_new_tokens":64, "do_sample": true}}' \
100+
-H 'Content-Type: application/json'
101+
```
102+
103+
2. LLM Microservice
104+
105+
```bash
106+
curl http://${host_ip}:9000/v1/faqgen \
107+
-X POST \
108+
-d '{"query":"Text Embeddings Inference (TEI) is a toolkit for deploying and serving open source text embeddings and sequence classification models. TEI enables high-performance extraction for the most popular models, including FlagEmbedding, Ember, GTE and E5."}' \
109+
-H 'Content-Type: application/json'
110+
```
111+
112+
3. MegaService
113+
114+
```bash
115+
curl http://${host_ip}:8888/v1/faqgen -H "Content-Type: application/json" -d '{
116+
"messages": "Text Embeddings Inference (TEI) is a toolkit for deploying and serving open source text embeddings and sequence classification models. TEI enables high-performance extraction for the most popular models, including FlagEmbedding, Ember, GTE and E5."
117+
}'
118+
```
119+
120+
## Enable LangSmith to Monitor an Application (Optional)
121+
122+
LangSmith offers a suite of tools to debug, evaluate, and monitor language models and intelligent agents. It can be used to assess benchmark data for each microservice. Before launching your services with `docker compose -f docker_compose.yaml up -d`, you need to enable LangSmith tracing by setting the `LANGCHAIN_TRACING_V2` environment variable to true and configuring your LangChain API key.
123+
124+
Here's how you can do it:
125+
126+
1. Install the latest version of LangSmith:
127+
128+
```bash
129+
pip install -U langsmith
130+
```
131+
132+
2. Set the necessary environment variables:
133+
134+
```bash
135+
export LANGCHAIN_TRACING_V2=true
136+
export LANGCHAIN_API_KEY=ls_...
137+
```
138+
139+
## 🚀 Launch the UI
140+
141+
Open this URL `http://{host_ip}:5173` in your browser to access the frontend.
142+
143+
![project-screenshot](../../assets/img/faqgen_ui_text.png)
144+
145+
## 🚀 Launch the React UI (Optional)
146+
147+
To access the FAQGen (react based) frontend, modify the UI service in the `docker_compose.yaml` file. Replace `faqgen-xeon-ui-server` service with the `faqgen-xeon-react-ui-server` service as per the config below:
148+
149+
```bash
150+
faqgen-xeon-react-ui-server:
151+
image: opea/faqgen-react-ui:latest
152+
container_name: faqgen-xeon-react-ui-server
153+
environment:
154+
- no_proxy=${no_proxy}
155+
- https_proxy=${https_proxy}
156+
- http_proxy=${http_proxy}
157+
ports:
158+
- 5174:80
159+
depends_on:
160+
- faqgen-xeon-backend-server
161+
ipc: host
162+
restart: always
163+
```
164+
165+
Open this URL `http://{host_ip}:5174` in your browser to access the react based frontend.
166+
167+
- Create FAQs from Text input
168+
![project-screenshot](../../assets/img/faqgen_react_ui_text.png)
169+
170+
- Create FAQs from Text Files
171+
![project-screenshot](../../assets/img/faqgen_react_ui_text_files.png)
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Copyright (C) 2024 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
version: "3.8"
5+
6+
services:
7+
tgi_service:
8+
image: ghcr.io/huggingface/tgi-gaudi:2.0.1
9+
container_name: tgi-gaudi-server
10+
ports:
11+
- "8008:80"
12+
volumes:
13+
- "./data:/data"
14+
environment:
15+
no_proxy: ${no_proxy}
16+
http_proxy: ${http_proxy}
17+
https_proxy: ${https_proxy}
18+
HABANA_VISIBLE_DEVICES: all
19+
OMPI_MCA_btl_vader_single_copy_mechanism: none
20+
HF_TOKEN: ${HUGGINGFACEHUB_API_TOKEN}
21+
runtime: habana
22+
cap_add:
23+
- SYS_NICE
24+
ipc: host
25+
command: --model-id ${LLM_MODEL_ID} --max-input-length 1024 --max-total-tokens 2048
26+
llm_faqgen:
27+
image: opea/llm-faqgen-tgi:latest
28+
container_name: llm-faqgen-server
29+
depends_on:
30+
- tgi_service
31+
ports:
32+
- "9000:9000"
33+
ipc: host
34+
environment:
35+
no_proxy: ${no_proxy}
36+
http_proxy: ${http_proxy}
37+
https_proxy: ${https_proxy}
38+
TGI_LLM_ENDPOINT: ${TGI_LLM_ENDPOINT}
39+
HUGGINGFACEHUB_API_TOKEN: ${HUGGINGFACEHUB_API_TOKEN}
40+
LANGCHAIN_API_KEY: ${LANGCHAIN_API_KEY}
41+
LANGCHAIN_TRACING_V2: ${LANGCHAIN_TRACING_V2}
42+
LANGCHAIN_PROJECT: "opea-llm-service"
43+
restart: unless-stopped
44+
faqgen-gaudi-backend-server:
45+
image: opea/faqgen:latest
46+
container_name: faqgen-gaudi-backend-server
47+
depends_on:
48+
- tgi_service
49+
- llm_faqgen
50+
ports:
51+
- "8888:8888"
52+
environment:
53+
- no_proxy=${no_proxy}
54+
- https_proxy=${https_proxy}
55+
- http_proxy=${http_proxy}
56+
- MEGA_SERVICE_HOST_IP=${MEGA_SERVICE_HOST_IP}
57+
- LLM_SERVICE_HOST_IP=${LLM_SERVICE_HOST_IP}
58+
ipc: host
59+
restart: always
60+
faqgen-gaudi-ui-server:
61+
image: opea/faqgen-ui:latest
62+
container_name: faqgen-gaudi-ui-server
63+
depends_on:
64+
- faqgen-gaudi-backend-server
65+
ports:
66+
- "5173:5173"
67+
environment:
68+
- no_proxy=${no_proxy}
69+
- https_proxy=${https_proxy}
70+
- http_proxy=${http_proxy}
71+
- DOC_BASE_URL=${BACKEND_SERVICE_ENDPOINT}
72+
ipc: host
73+
restart: always
74+
75+
networks:
76+
default:
77+
driver: bridge

FaqGen/docker/ui/docker/Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright (C) 2024 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# Use node 20.11.1 as the base image
5+
FROM node:20.11.1
6+
7+
# Update package manager and install Git
8+
RUN apt-get update -y && apt-get install -y git
9+
10+
# Copy the front-end code repository
11+
COPY svelte /home/user/svelte
12+
13+
# Set the working directory
14+
WORKDIR /home/user/svelte
15+
16+
# Install front-end dependencies
17+
RUN npm install
18+
19+
# Build the front-end application
20+
RUN npm run build
21+
22+
# Expose the port of the front-end application
23+
EXPOSE 5173
24+
25+
# Run the front-end application in preview mode
26+
CMD ["npm", "run", "preview", "--", "--port", "5173", "--host", "0.0.0.0"]

0 commit comments

Comments
 (0)