Skip to content

Commit

Permalink
Merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
BeatrixCohere committed Jun 27, 2024
2 parents 5d89d4f + 51795fe commit a8aded7
Show file tree
Hide file tree
Showing 25 changed files with 3,275 additions and 6,164 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ COPY src/interfaces/coral_web/.env.development .
COPY src/interfaces/coral_web/.env.production .

ENV NEXT_PUBLIC_API_HOSTNAME='/api'
RUN pnpm install \
&& pnpm next:build
RUN npm install \
&& npm run next:build

# Terrarium
WORKDIR /usr/src/app
Expand Down
3 changes: 3 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
},
"COHERE_API_KEY": {
"description": "Your Cohere API key"
},
"INSTALL_COMMUNITY_DEPS": {
"description": "Whether to enable community features true/false"
}
},
"hooks": {
Expand Down
7 changes: 6 additions & 1 deletion charts/cohere-toolkit/templates/backend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,13 @@ metadata:
app.kubernetes.io/name: toolkit-backend
{{- include "cohere-toolkit.labels" . | nindent 4 }}
stringData:
COHERE_API_KEY: "{{ .Values.global.cohere.api_key }}"
DATABASE_URL: "{{ template "cohere-toolkit.database-url" $ }}"
{{- if .Values.global.cohere.api_key }}
COHERE_API_KEY: "{{ .Values.global.cohere.api_key }}"
{{- end }}
{{- if .Values.terrarium.enabled }}
PYTHON_INTERPRETER_URL: "http://terrarium"
{{- end }}
{{- with $values.config }}
{{- toYaml . | nindent 2 }}
{{- end }}
141 changes: 141 additions & 0 deletions charts/cohere-toolkit/templates/terrarium.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
{{- $values := .Values.terrarium}}
{{- if $values.enabled }}
apiVersion: v1
kind: ServiceAccount
metadata:
name: terrarium
namespace: {{ .Release.Namespace }}
labels:
{{- include "cohere-toolkit.labels" . | nindent 4 }}
{{- with $values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with $values.serviceAccount.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 2 }}
{{- end }}

---

apiVersion: apps/v1
kind: Deployment
metadata:
name: terrarium
namespace: {{ .Release.Namespace }}
labels:
app.kubernetes.io/name: terrarium
{{- include "cohere-toolkit.labels" . | nindent 4 }}
spec:
replicas: {{ $values.replicaCounts }}
selector:
matchLabels:
app.kubernetes.io/name: terrarium
template:
metadata:
name: terrarium
labels:
app.kubernetes.io/name: terrarium
{{- include "cohere-toolkit.labels" . | nindent 8 }}
{{- with $values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
serviceAccountName: terrarium
{{- with $values.podSecurityContext }}
securityContext:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with $values.initContainers }}
initContainers:
{{- toYaml . | nindent 8 }}
{{- end }}
containers:
- name: terrarium
image: {{ $values.image.repository }}:{{ $values.image.tag | default .Chart.AppVersion }}
imagePullPolicy: {{ $values.image.pullPolicy }}
{{- with $values.securityContext }}
securityContext:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with $values.resources }}
resources:
{{- toYaml . | nindent 12 }}
{{- end }}
ports:
- containerPort: 8080
protocol: TCP
name: http
{{- /* TODO: Add livenessProbe and readinessProbe */}}
{{- with $values.sidecars }}
{{- toYaml . | nindent 12 }}
{{- end }}
restartPolicy: Always
{{- with $values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with $values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with $values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}

---

apiVersion: v1
kind: Service
metadata:
name: terrarium
namespace: {{ .Release.Namespace }}
labels:
app.kubernetes.io/name: terrarium
{{- include "cohere-toolkit.labels" . | nindent 4 }}
spec:
selector:
app.kubernetes.io/name: terrarium
ports:
- protocol: TCP
port: {{ $values.service.port }}
targetPort: http
type: {{ $values.service.type }}

---

{{- if $values.autoscaling.enabled }}
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: terrarium
namespace: {{ .Release.Namespace }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: terrarium
minReplicas: {{ $values.autoscaling.minReplicas }}
maxReplicas: {{ $values.autoscaling.maxReplicas }}
metrics:
{{- if $values.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ $values.autoscaling.targetCPUUtilizationPercentage }}
{{- end}}
{{- if $values.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: {{ $values.autoscaling.targetMemoryUtilizationPercentage }}
{{- end}}
{{- end}}

{{- end }}
63 changes: 63 additions & 0 deletions charts/cohere-toolkit/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,66 @@ frontend:
sidecars: [ ]

config: {}

terrarium:
enabled: true

replicaCounts: 1

image:
repository: ghcr.io/cohere-ai/terrarium
pullPolicy: Always
# Overrides the image tag whose default is the chart appVersion.
tag: ""

serviceAccount:
# Specifies whether a service account should be created
# Annotations to add to the service account
annotations: { }
imagePullSecrets: [ ]

podAnnotations: { }

podSecurityContext: { }
# fsGroup: 2000

securityContext: { }
# capabilities:
# drop:
# - ALL
# readOnlyRootFilesystem: true
# runAsNonRoot: true
# runAsUser: 1000

service:
type: ClusterIP
port: 80

resources: { }
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
# limits:
# cpu: 100m
# memory: 128Mi
# requests:
# cpu: 100m
# memory: 128Mi

autoscaling:
enabled: false
minReplicas: 1
maxReplicas: 100
targetCPUUtilizationPercentage: 80
targetMemoryUtilizationPercentage: 80

nodeSelector: { }

tolerations: [ ]

affinity: { }

initContainers: [ ]

sidecars: [ ]
2 changes: 1 addition & 1 deletion docker_scripts/cloudrun-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ source "${APP_HOME}/functions"
if [[ -z ${1} ]]; then
run_frontend
run_terrarium
run_backend
run_backend_poetry

else
exec "$@"
Expand Down
2 changes: 1 addition & 1 deletion docker_scripts/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ if [[ -z ${1} ]]; then
run_postgre
run_frontend
run_terrarium
run_backend
run_backend_poetry

else
exec "$@"
Expand Down
3 changes: 2 additions & 1 deletion docker_scripts/env-defaults
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ export NEXT_PUBLIC_API_HOSTNAME=${NEXT_PUBLIC_API_HOSTNAME:-http://localhost:800
export FRONTEND_HOSTNAME=${FRONTEND_HOSTNAME:-http://localhost:4000}
export NEXT_PUBLIC_FRONTEND_HOSTNAME=${FRONTEND_HOSTNAME:-http://localhost:4000}
export PYTHON_INTERPRETER_URL=${PYTHON_INTERPRETER_URL:-http://localhost:8080}
export DATABASE_URL=${DATABASE_URL:-postgresql+psycopg2://postgre:postgre@localhost:5432/toolkit}
export DATABASE_URL=${DATABASE_URL:-postgresql+psycopg2://postgre:postgre@localhost:5432/toolkit}
export INSTALL_COMMUNITY_DEPS=${INSTALL_COMMUNITY_DEPS:false}
13 changes: 8 additions & 5 deletions docker_scripts/functions
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,10 @@ run_backend() {

run_backend_poetry() {
cd /workspace
poetry install --without setup
if [ "${INSTALL_COMMUNITY_DEPS,,}" == "true" ]; then
echo "Install with community deps..."
poetry install --with community
fi
source .venv/bin/activate
echo "Migration started..."
alembic -c src/backend/alembic.ini upgrade head
Expand All @@ -269,16 +272,16 @@ run_backend_poetry() {
run_frontend_proxy() {
cd /workspace/src/interfaces/coral_web
echo "Starting Frontend..."
pm2 start pnpm -- start:single-docker-proxy
pm2 start npm -- run -- start:single-docker-proxy
echo "Frontend started..."
}

run_frontend() {
cd /workspace/src/interfaces/coral_web
echo "Building Frontend when we are not in a localhost environment"
pnpm next:build
echo "Building Frontend"
npm run next:build
echo "Starting Frontend..."
pm2 start pnpm -- start:single-docker
pm2 start npm -- run -- start:single-docker
echo "Frontend started..."
}

Expand Down
2 changes: 1 addition & 1 deletion docker_scripts/gcp-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if [[ -z ${1} ]]; then
run_nginx
run_frontend_proxy
run_terrarium
run_backend
run_backend_poetry
else
exec "$@"
fi
8 changes: 7 additions & 1 deletion docs/deployment_guides/single_container.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ You can then run the container with the following command:
```bash
docker run --name=cohere-toolkit -itd -e COHERE_API_KEY='Your Cohere API key here' -p 8000:8000 -p 4000:4000 cohere-ai/cohere-toolkit
```
If you would like to use .env file to pass the parameters, you can mount it to the container using:
If you need to use community features, you can run the container with the following command:
```bash
docker run --name=cohere-toolkit -itd -e INSTALL_COMMUNITY_DEPS='true' -e COHERE_API_KEY='Your Cohere API key here' -p 8000:8000 -p 4000:4000 cohere-ai/cohere-toolkit
```

If you would like to use .env file to pass the parameters, you can mount it to the container using the following command.
If you need to use community features, please set `INSTALL_COMMUNITY_DEPS=true` in your .env file.
```bash
docker run --name=cohere-toolkit -itd --env-file .env -p 8000:8000 -p 4000:4000 cohere-ai/cohere-toolkit
```
Expand Down
11 changes: 10 additions & 1 deletion docs/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
Try the default Toolkit application yourself by deploying it in a container locally. You will need to have [Docker](https://www.docker.com/products/docker-desktop/) and [Docker-compose >= 2.22](https://docs.docker.com/compose/install/) installed.

```bash

docker run -e COHERE_API_KEY='>>YOUR_API_KEY<<' -p 8000:8000 -p 4000:4000 ghcr.io/cohere-ai/cohere-toolkit:latest
```

If you need to use community features, you can run the container with the following command:

```bash
docker run -e INSTALL_COMMUNITY_DEPS='true' -e COHERE_API='>>YOUR_API_KEY<<' -p 8000:8000 -p 4000:4000 ghcr.io/cohere-ai/cohere-toolkit:latest
```

Go to localhost:4000 in your browser and start chatting with the model. This will use the model hosted on Cohere's platform. If you want to add your own tools or use another model, follow the instructions below to fork the repository.
Expand Down Expand Up @@ -217,6 +221,11 @@ Install your dependencies:
poetry install
```

if you need to install the community features, run:
```bash
poetry install --with community
```

Run linters:

```bash
Expand Down
15 changes: 12 additions & 3 deletions gcp.backend.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ ENV PATH="$VIRTUAL_ENV/bin:$PATH"
ARG DATABASE_URL
ENV DATABASE_URL=${DATABASE_URL}

# set USE_COMMUNITY_FEATURES from arguments
ARG INSTALL_COMMUNITY_DEPS
ENV INSTALL_COMMUNITY_DEPS=${INSTALL_COMMUNITY_DEPS}

WORKDIR /workspace

ARG port=8000
Expand All @@ -27,11 +31,16 @@ ARG port=8000
ENV PORT=${port}

# Copy dependency files to avoid cache invalidations
COPY pyproject.toml poetry.lock ./
COPY pyproject.toml poetry.lock README.md ./

# Install poetry and run poetry install
RUN pip install --no-cache-dir poetry==1.6.1 && \
poetry install
RUN pip install --no-cache-dir poetry==1.6.1 \
RUN if [ "${INSTALL_COMMUNITY_DEPS,,}" == "true" ]; then \
poetry install --with community \
else \
poetry install; \
fi


COPY src/backend/ src/backend/

Expand Down
Loading

0 comments on commit a8aded7

Please sign in to comment.