Skip to content

Commit

Permalink
helm chart: add nginx to avoid CORS issue (#377)
Browse files Browse the repository at this point in the history
helm chart: add nginx and ui support in chatqna

- Add nginx to avoid CORS issue
- Update readme

Signed-off-by: Ruoyu Ying <[email protected]>
  • Loading branch information
Ruoyu-y authored Sep 9, 2024
1 parent af9e1b6 commit 353f3a5
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 46 deletions.
3 changes: 3 additions & 0 deletions helm-charts/chatqna/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,8 @@ dependencies:
- name: data-prep
version: 1.0.0
repository: "file://../common/data-prep"
- name: chatqna-ui
version: 1.0.0
repository: "file://../common/chatqna-ui"
version: 1.0.0
appVersion: "v1.0"
28 changes: 6 additions & 22 deletions helm-charts/chatqna/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ helm dependency update chatqna
export HFTOKEN="insert-your-huggingface-token-here"
export MODELDIR="/mnt/opea-models"
export MODELNAME="Intel/neural-chat-7b-v3-3"
# If you would like to use the traditional UI, please change the image as well as the containerport within the values
# append these at the end of the command "--set chatqna-ui.image.repository=opea/chatqna-ui,chatqna-ui.image.tag=latest,chatqna-ui.containerPort=5173"
helm install chatqna chatqna --set global.HUGGINGFACEHUB_API_TOKEN=${HFTOKEN} --set global.modelUseHostPath=${MODELDIR} --set tgi.LLM_MODEL_ID=${MODELNAME}
# To use Gaudi device
#helm install chatqna chatqna --set global.HUGGINGFACEHUB_API_TOKEN=${HFTOKEN} --set global.modelUseHostPath=${MODELDIR} --set tgi.LLM_MODEL_ID=${MODELNAME} -f chatqna/gaudi-values.yaml
Expand Down Expand Up @@ -58,32 +60,14 @@ curl http://localhost:8888/v1/chatqna \

### Verify the workload through UI

UI need to get installed before accessing. Follow the steps below to build and install UI:
The UI has already been installed via the Helm chart. To access it, use the external IP of your Kubernetes cluster along with the NGINX port. You can find the NGINX port using the following command:

```bash
# expose endpoint of ChatQnA service and dataprep service
kubectl port-forward svc/chatqna --address 0.0.0.0 8888:8888
kubectl port-forward svc/chatqna-data-prep --address 0.0.0.0 6007:6007

# build and push the UI image if not exist
# skip these steps if the image already exists
git clone https://github.com/opea-project/GenAIExamples.git
cd GenAIExamples/ChatQnA/docker/ui/
docker build --no-cache -t opea/chatqna-conversation-ui:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f ./docker/Dockerfile.react .
# push the image to your cluster, make sure the image exists on each node of your cluster
docker save -o ui.tar opea/chatqna-conversation-ui:latest
sudo ctr -n k8s.io image import ui.tar

# install UI using helm chart. Replace image tag if required
cd
cd GenAIInfra/helm-charts/
helm install ui common/chatqna-ui --set BACKEND_SERVICE_ENDPOINT="http://${host_ip}:8888/v1/chatqna",DATAPREP_SERVICE_ENDPOINT="http://${host_ip}:6007/v1/dataprep",image.tag="latest"

# expose the endpoint of UI for verification
kubectl port-forward svc/ui --address 0.0.0.0 5174:5174
export port=$(kubectl get service chatqna-nginx --output='jsonpath={.spec.ports[0].nodePort}')
echo $port
```

Access `http://localhost:5174` to play with the ChatQnA workload through UI.
Open a browser to access `http://<k8s-cluster-ip-address>:${port}` to play with the ChatQnA workload.

## Values

Expand Down
99 changes: 99 additions & 0 deletions helm-charts/chatqna/templates/nginx-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
apiVersion: v1
data:
default.conf: |+
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
server {
listen 80;
listen [::]:80;
location /home {
alias /usr/share/nginx/html/index.html;
}
location / {
proxy_pass http://{{ include "ui.fullname" (index .Subcharts "chatqna-ui") }}:{{ index .Values "chatqna-ui" "service" "port" }};
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /v1/chatqna {
proxy_pass http://{{ include "chatqna.fullname" . }}:{{ .Values.service.port }};
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /v1/dataprep {
proxy_pass http://{{ include "data-prep.fullname" (index .Subcharts "data-prep") }}:{{ index .Values "data-prep" "service" "port" }};
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /v1/dataprep/get_file {
proxy_pass http://{{ include "data-prep.fullname" (index .Subcharts "data-prep") }}:{{ index .Values "data-prep" "service" "port" }};
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /v1/dataprep/delete_file {
proxy_pass http://{{ include "data-prep.fullname" (index .Subcharts "data-prep") }}:{{ index .Values "data-prep" "service" "port" }};
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
kind: ConfigMap
metadata:
name: nginx-default-config
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "chatqna.fullname" . }}-nginx
spec:
selector:
matchLabels:
app: {{ include "chatqna.fullname" . }}-nginx
template:
metadata:
labels:
app: {{ include "chatqna.fullname" . }}-nginx
spec:
containers:
- image: nginx:1.27.1
imagePullPolicy: IfNotPresent
name: nginx
volumeMounts:
- mountPath: /etc/nginx/conf.d
name: nginx-config-volume
securityContext: {}
volumes:
- configMap:
defaultMode: 420
name: nginx-default-config
name: nginx-config-volume
---
apiVersion: v1
kind: Service
metadata:
name: {{ include "chatqna.fullname" . }}-nginx
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: {{ include "chatqna.fullname" . }}-nginx
type: NodePort
8 changes: 8 additions & 0 deletions helm-charts/chatqna/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ tgi:
guardrails-usvc:
enabled: false

# If you would like to switch to traditional UI image
# Uncomment the following lines
# chatqna-ui:
# image:
# repository: "opea/chatqna-ui"
# tag: "latest"
# containerPort: "5173"

global:
http_proxy: ""
https_proxy: ""
Expand Down
3 changes: 0 additions & 3 deletions helm-charts/common/chatqna-ui/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ metadata:
labels:
{{- include "ui.labels" . | nindent 4 }}
data:
http_proxy: {{ .Values.global.http_proxy | quote }}
https_proxy: {{ .Values.global.https_proxy | quote }}
no_proxy: {{ .Values.global.no_proxy | quote }}
APP_BACKEND_SERVICE_ENDPOINT: {{ .Values.BACKEND_SERVICE_ENDPOINT | quote }}
APP_DATA_PREP_SERVICE_URL: {{ .Values.DATAPREP_SERVICE_ENDPOINT | quote }}
CHAT_BASE_URL: {{ .Values.BACKEND_SERVICE_ENDPOINT | quote }}
Expand Down
21 changes: 9 additions & 12 deletions helm-charts/common/chatqna-ui/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,16 @@ tolerations: []

affinity: {}

# chatQnA Mega service URL, e.g. http://<service-name>:<port>
BACKEND_SERVICE_ENDPOINT: ""
# chatQnA backend service URL, default to Mega backend service
BACKEND_SERVICE_ENDPOINT: "/v1/chatqna"

# data preparation service URL, http://<service-name>:<port>
DATAPREP_SERVICE_ENDPOINT: ""
# data preparation service URL, default to Mega data preparation service
DATAPREP_SERVICE_ENDPOINT: "/v1/dataprep"

# data preparation get file service URL, http://<service-name>:<port>
DATAPREP_GET_FILE_ENDPOINT: ""
# data preparation get file service URL, default to Mega data preparation service
DATAPREP_GET_FILE_ENDPOINT: "/v1/dataprep/get_file"

# data preparation delete file service URL, http://<service-name>:<port>
DATAPREP_DELETE_FILE_ENDPOINT: ""
# data preparation delete file service URL, default to Mega data preparation service
DATAPREP_DELETE_FILE_ENDPOINT: "/v1/dataprep/delete_file"

global:
http_proxy: ""
https_proxy: ""
no_proxy: ""
global: {}
15 changes: 6 additions & 9 deletions microservices-connector/config/manifests/chatqna-ui.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@ metadata:
app.kubernetes.io/version: "v1.0"
app.kubernetes.io/managed-by: Helm
data:
http_proxy: ""
https_proxy: ""
no_proxy: ""
APP_BACKEND_SERVICE_ENDPOINT: ""
APP_DATA_PREP_SERVICE_URL: ""
CHAT_BASE_URL: ""
UPLOAD_FILE_BASE_URL: ""
GET_FILE: ""
DELETE_FILE: ""
APP_BACKEND_SERVICE_ENDPOINT: "/v1/chatqna"
APP_DATA_PREP_SERVICE_URL: "/v1/dataprep"
CHAT_BASE_URL: "/v1/chatqna"
UPLOAD_FILE_BASE_URL: "/v1/dataprep"
GET_FILE: "/v1/dataprep/get_file"
DELETE_FILE: "/v1/dataprep/delete_file"
---
# Source: chatqna-ui/templates/service.yaml
# Copyright (C) 2024 Intel Corporation
Expand Down

0 comments on commit 353f3a5

Please sign in to comment.