From 325311fcc4d9116f44a140635d10afd773dd1667 Mon Sep 17 00:00:00 2001 From: Ruoyu Ying Date: Tue, 3 Sep 2024 09:46:30 +0800 Subject: [PATCH 1/2] helm chart: add nginx to avoid CORS issue Signed-off-by: Ruoyu Ying --- helm-charts/chatqna/Chart.yaml | 3 + helm-charts/chatqna/README.md | 29 ++---- .../chatqna/templates/nginx-deployment.yaml | 99 +++++++++++++++++++ helm-charts/chatqna/values.yaml | 8 ++ .../chatqna-ui/templates/configmap.yaml | 3 - helm-charts/common/chatqna-ui/values.yaml | 21 ++-- .../config/manifests/chatqna-ui.yaml | 15 ++- 7 files changed, 131 insertions(+), 47 deletions(-) create mode 100644 helm-charts/chatqna/templates/nginx-deployment.yaml diff --git a/helm-charts/chatqna/Chart.yaml b/helm-charts/chatqna/Chart.yaml index 5860d61a..f99dd7f0 100644 --- a/helm-charts/chatqna/Chart.yaml +++ b/helm-charts/chatqna/Chart.yaml @@ -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" diff --git a/helm-charts/chatqna/README.md b/helm-charts/chatqna/README.md index c33e2f50..bb144cc3 100644 --- a/helm-charts/chatqna/README.md +++ b/helm-charts/chatqna/README.md @@ -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 @@ -58,32 +60,13 @@ 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://:${port}` to play with the ChatQnA workload. ## Values diff --git a/helm-charts/chatqna/templates/nginx-deployment.yaml b/helm-charts/chatqna/templates/nginx-deployment.yaml new file mode 100644 index 00000000..9e9d6502 --- /dev/null +++ b/helm-charts/chatqna/templates/nginx-deployment.yaml @@ -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 diff --git a/helm-charts/chatqna/values.yaml b/helm-charts/chatqna/values.yaml index 6aa7275f..bfacc09a 100644 --- a/helm-charts/chatqna/values.yaml +++ b/helm-charts/chatqna/values.yaml @@ -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: "" diff --git a/helm-charts/common/chatqna-ui/templates/configmap.yaml b/helm-charts/common/chatqna-ui/templates/configmap.yaml index 301f149f..bd868131 100644 --- a/helm-charts/common/chatqna-ui/templates/configmap.yaml +++ b/helm-charts/common/chatqna-ui/templates/configmap.yaml @@ -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 }} diff --git a/helm-charts/common/chatqna-ui/values.yaml b/helm-charts/common/chatqna-ui/values.yaml index d62fddec..29c8d84f 100644 --- a/helm-charts/common/chatqna-ui/values.yaml +++ b/helm-charts/common/chatqna-ui/values.yaml @@ -62,19 +62,16 @@ tolerations: [] affinity: {} -# chatQnA Mega service URL, e.g. http://: -BACKEND_SERVICE_ENDPOINT: "" +# chatQnA backend service URL, default to Mega backend service +BACKEND_SERVICE_ENDPOINT: "/v1/chatqna" -# data preparation service URL, http://: -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://: -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://: -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: {} \ No newline at end of file diff --git a/microservices-connector/config/manifests/chatqna-ui.yaml b/microservices-connector/config/manifests/chatqna-ui.yaml index aff07171..89fa5e07 100644 --- a/microservices-connector/config/manifests/chatqna-ui.yaml +++ b/microservices-connector/config/manifests/chatqna-ui.yaml @@ -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 From 77c91e43981e07ee56d490b62700ecbc772f26a4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 9 Sep 2024 01:01:00 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- helm-charts/chatqna/README.md | 1 + helm-charts/common/chatqna-ui/values.yaml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/helm-charts/chatqna/README.md b/helm-charts/chatqna/README.md index bb144cc3..558a2362 100644 --- a/helm-charts/chatqna/README.md +++ b/helm-charts/chatqna/README.md @@ -61,6 +61,7 @@ curl http://localhost:8888/v1/chatqna \ ### Verify the workload through 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 export port=$(kubectl get service chatqna-nginx --output='jsonpath={.spec.ports[0].nodePort}') echo $port diff --git a/helm-charts/common/chatqna-ui/values.yaml b/helm-charts/common/chatqna-ui/values.yaml index 29c8d84f..a349adcf 100644 --- a/helm-charts/common/chatqna-ui/values.yaml +++ b/helm-charts/common/chatqna-ui/values.yaml @@ -74,4 +74,4 @@ DATAPREP_GET_FILE_ENDPOINT: "/v1/dataprep/get_file" # data preparation delete file service URL, default to Mega data preparation service DATAPREP_DELETE_FILE_ENDPOINT: "/v1/dataprep/delete_file" -global: {} \ No newline at end of file +global: {}