Skip to content

Commit

Permalink
chat
Browse files Browse the repository at this point in the history
  • Loading branch information
arti-shalb committed Nov 22, 2023
1 parent bec8694 commit 2311b5d
Show file tree
Hide file tree
Showing 10 changed files with 288 additions and 40 deletions.
1 change: 1 addition & 0 deletions huggingface-model/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
charts
6 changes: 6 additions & 0 deletions huggingface-model/Chart.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dependencies:
- name: mongodb
repository: oci://registry-1.docker.io/bitnamicharts
version: 14.3.0
digest: sha256:1536cff09b6be684c82ea0780c96f266c549494dfacec84371054fa30e6c5cfa
generated: "2023-11-21T15:00:46.692964492+02:00"
9 changes: 7 additions & 2 deletions huggingface-model/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
apiVersion: v2
name: huggingface-model
description: Helm chart for deploy Hugging Face models and chat-ui to Kubernetes cluster. See [Hugging Face models](https://huggingface.co/models)
description: Helm chart for deploy Hugging Face models to Kubernetes cluster. See [Hugging Face models](https://huggingface.co/models)

type: application

version: 0.0.23
version: 0.1.0

dependencies:
- condition: mongodb.enabled
name: mongodb
repository: oci://registry-1.docker.io/bitnamicharts
version: 14.x.x
13 changes: 12 additions & 1 deletion huggingface-model/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{{/*
Generate internal container port.
*/}}
{{- define "huggingface-model.chat.base-config" -}}
- name: {{ .Values.model.organization }}/{{ .Values.model.name }}
endpoints:
- url: http://{{ include "huggingface-model.fullname" . }}:{{ .Values.service.port | default 8080 }}
type: "tgi"
{{- if .Values.chat.modelConfig }}{{- .Values.chat.modelConfig | toYaml | nindent 2 }}{{ end }}
{{- if .Values.chat.additionalModels }}{{ .Values.chat.additionalModels | toYaml | nindent 0 }}{{ end }}
{{- end}}
{{- define "huggingface-model.containerPort" -}}
{{- if .Values.huggingface }}
{{- default 8080 .Values.huggingface.containerPort }}
Expand Down Expand Up @@ -70,7 +78,10 @@ Selector labels
app.kubernetes.io/name: {{ include "huggingface-model.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{- define "huggingface-chat.selectorLabels" -}}
app.kubernetes.io/name: {{ include "huggingface-model.name" . }}-chat-ui
app.kubernetes.io/instance: {{ .Release.Name }}-chat
{{- end }}
{{/*
Create the name of the service account to use
*/}}
Expand Down
4 changes: 1 addition & 3 deletions huggingface-model/templates/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
apiVersion: apps/v1
kind: {{ $kind }}
metadata:
annotations:
reloader.stakater.com/auto: "true"
name: {{ include "huggingface-model.fullname" . }}
labels:
{{- include "huggingface-model.labels" . | nindent 4 }}
Expand Down Expand Up @@ -59,7 +57,7 @@ spec:
args:
- |
set -x
if [ -f "/usr/src/{{ .Values.model.name }}/config.json" ]; then echo "Model {{ .Values.model.organization }} is already downloaded. Skipping init..."; exit 0; fi
if [ -f "/usr/src/{{ .Values.model.name }}/config.json" ]; then echo "Model {{ .Values.model.name }} is already downloaded. Skipping init..."; exit 0; fi
rm -rf /usr/src/{{ .Values.model.name }}/*
{{- if and .Values.init.s3.enabled }}
apk add --update aws-cli
Expand Down
73 changes: 73 additions & 0 deletions huggingface-model/templates/chat/application.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{{- if .Values.chat.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "huggingface-model.fullname" . }}-chat
labels:
{{- include "huggingface-model.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.chat.replicaCount }}
selector:
matchLabels:
{{- include "huggingface-chat.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.chat.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "huggingface-chat.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.chat.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
containers:
- name: model
image: {{ .Values.chat.image.repo }}:{{ .Values.chat.image.tag }}
imagePullPolicy: {{ .Values.chat.image.pullPolicy }}
ports:
- containerPort: 3000
env:
- name: MODELS
value: '{{ toRawJson (fromYamlArray (include "huggingface-model.chat.base-config" .)) }}'
- name: MONGODB_HOST
value: {{ if .Values.mongodb.install }}{{ include "mongodb.service.nameOverride" .Subcharts.mongodb }}{{ else }}{{ .Values.chat.mongodb.host }}{{ end }}
{{- if .Values.mongodb.port }}
- name: MONGODB_PORT
value: {{ .Values.chat.mongodb.port | quote }}
{{- end }}
- name: MONGODB_USER
value: {{ .Values.chat.mongodb.user | default "root" }}
{{- if .Values.mongodb.install }}
- name: MONGODB_URL_PARAMS
value: "admin?directConnection=true&authSource=admin"
- name: MONGODB_PASSWORD
valueFrom:
secretKeyRef:
name: {{ include "mongodb.service.nameOverride" .Subcharts.mongodb }}
key: mongodb-root-password
{{- else }}
{{- if .Values.mongodb.password }}
- name: MONGODB_PASSWORD
value: {{ .Values.chat.mongodb.password | quote }}
- name: MONGODB_URL_PARAMS
value: {{ .Values.chat.mongodb.urlParams }}
{{- end }}
{{- end }}
resources:
{{- toYaml .Values.chat.resources | nindent 12 }}
{{- with .Values.chat.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.chat.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.chat.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
53 changes: 53 additions & 0 deletions huggingface-model/templates/chat/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{{- if and .Values.chat.enabled .Values.chat.ingress.enabled }}
{{- $fullName := printf "%s-chat" (include "huggingface-model.fullname" .) -}}
{{- $serviceName := printf "%s-chat" (include "huggingface-model.fullname" .) -}}
{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1
{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1beta1
{{- else -}}
apiVersion: extensions/v1beta1
{{- end }}
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
{{- include "huggingface-model.labels" . | nindent 4 }}
{{- with .Values.chat.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if .Values.chat.ingress.tls }}
tls:
{{- range .Values.chat.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.chat.ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
{{- range .paths }}
- path: {{ .path }}
pathType: {{ .pathType }}
backend:
service:
name: {{ $serviceName }}
port:
{{- if .servicePort }}
{{- .servicePort | toYaml | nindent 18 }}
{{- else }}
number: 8080
{{- end }}
{{- if .extendedOptions }}
{{- .extendedOptions | toYaml | nindent 14 }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
14 changes: 14 additions & 0 deletions huggingface-model/templates/chat/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "huggingface-model.fullname" . }}-chat
labels:
{{- include "huggingface-model.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type | default "ClusterIP" }}
ports:
- name: http
port: {{ .Values.service.port | default 8080 }}
targetPort: 3000
selector:
{{- include "huggingface-chat.selectorLabels" . | nindent 4 }}
27 changes: 11 additions & 16 deletions huggingface-model/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
{{- if .Values.ingresses.enabled -}}
{{- $gitVersion := .Capabilities.KubeVersion.GitVersion }}
{{- $labels := include "huggingface-model.labels" . -}}
{{- $fullName := include "huggingface-model.fullname" . -}}
{{- range $index, $_ := .Values.ingresses.configs }}
---
{{- if semverCompare ">=1.19-0" $gitVersion -}}
{{- if .Values.ingress.enabled -}}
{{- $fullName := (include "huggingface-model.fullname" .) -}}
{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1
{{- else if semverCompare ">=1.14-0" $gitVersion -}}
{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1beta1
{{- else -}}
apiVersion: extensions/v1beta1
{{- end }}
kind: Ingress
metadata:
name: {{ $fullName }}-{{ $index }}
name: {{ $fullName }}
labels:
{{- $labels | nindent 4 }}
{{- with .annotations }}
{{- include "huggingface-model.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if .tls }}
{{- if .Values.ingress.tls }}
tls:
{{- range .tls }}
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
Expand All @@ -32,7 +28,7 @@ spec:
{{- end }}
{{- end }}
rules:
{{- range .hosts }}
{{- range .Values.ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
Expand All @@ -50,12 +46,11 @@ spec:
{{- if .servicePort }}
{{- .servicePort | toYaml | nindent 18 }}
{{- else }}
number: 80
number: 8080
{{- end }}
{{- if .extendedOptions }}
{{- .extendedOptions | toYaml | nindent 14 }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
Loading

0 comments on commit 2311b5d

Please sign in to comment.