Skip to content

Commit

Permalink
feat: upgrade langflow version and add 'endpoint' to downloaded flows (
Browse files Browse the repository at this point in the history
…#11)

* feat: upgrade langflow version and add 'endpoint' to downloaded flows

* feat: upgrade langflow version and add 'endpoint' to downloaded flows

* feat: upgrade langflow version and add 'endpoint' to downloaded flows

* skip yaml

* skip yaml

* skip yaml

* add maintainers

* add maintainers

* add maintainers
  • Loading branch information
nicoloboschi authored Jul 23, 2024
1 parent fa01b52 commit 44fdb23
Show file tree
Hide file tree
Showing 11 changed files with 1,061 additions and 419 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ on:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
lint-test:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -40,15 +44,15 @@ jobs:
- name: Run chart-testing (lint)
if: steps.list-changed.outputs.changed == 'true'
run: ct lint --debug --target-branch main
run: ct lint --debug --target-branch main --validate-yaml false

- name: Create kind cluster
if: steps.list-changed.outputs.changed == 'true'
uses: helm/[email protected]

- name: Run chart-testing (install)
if: steps.list-changed.outputs.changed == 'true'
run: ct install --debug --target-branch main
run: ct install --debug --target-branch main --chart-repos bitnami=https://charts.bitnami.com/bitnami

release:
needs: lint-test
Expand Down
8 changes: 5 additions & 3 deletions charts/langflow-ide/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ apiVersion: v2
name: langflow-ide
description: Helm chart for Langflow IDE
type: application
version: 0.0.1
appVersion: 1.0-alpha

version: 0.1.0
appVersion: latest
maintainers:
- name: Langflow
email: [email protected]
dependencies:
- name: postgresql
version: 15.x
Expand Down
8 changes: 3 additions & 5 deletions charts/langflow-ide/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ ingress:
# hosts:
# - chart-example.local

langflow:
global:
langflow:
global:
image:
pullPolicy: IfNotPresent
tag: ""
Expand Down Expand Up @@ -127,8 +127,6 @@ langflow:
# kind: Managed
# cachingmode: ReadOnly
storageClass: {}



frontend:
enabled: true
Expand Down Expand Up @@ -171,4 +169,4 @@ secretProvider:
enabled: false

postgresql:
enabled: false
enabled: false
7 changes: 5 additions & 2 deletions charts/langflow-runtime/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ apiVersion: v2
name: langflow-runtime
description: A helm chart for running LangFlow flows as a service
type: application
version: 0.0.1
appVersion: "1.0-alpha"
version: 0.1.0
appVersion: latest
maintainers:
- name: Langflow
email: [email protected]
124 changes: 90 additions & 34 deletions charts/langflow-runtime/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# LangFlow runtime chart
# Langflow runtime chart

Deploy LangFlow flows to Kubernetes with this Helm chart.
Deploy Langflow flows to Kubernetes with this Helm chart.
Using a dedicated deployment for a set of flows is fundamental in production environments in order to have a granular resource control.


Expand All @@ -13,26 +13,49 @@ There are two ways to import a flow:
```yaml
downloadFlows:
flows:
- url: https://raw.githubusercontent.com/langflow-ai/langflow/dev/tests/data/BasicChatwithPromptandHistory.json
# basicAuth: "myuser:mypassword"
# headers:
# Authorization: "Bearer my-key"
- url: https://raw.githubusercontent.com/datastax/langflow-charts/main/examples/flows/basic-prompting-hello-world.json
endpoint: hello-world
```
2. **Packaging the flow as docker image**: You can add a flow from to a docker image based on Langflow runtime and refer to it in the chart.
See an example in the `apps` directory.

## Deploy the flow

Install the chart (using option 1):
Since the basic prompting needs an OpenAI Key, we need to create a secret with the key:
```
kubectl create secret generic langflow-secrets --from-literal=openai-key=sk-xxxx
```
This command will create a secret named `langflow-secrets` with the key `openai-key` containing your secret value.

We need to create a custom `values.yaml` file to:
1. Refer to the flow we want to deploy
2. Plug the secret we created to the Langflow deployment

(custom-values.yaml)
```yaml
downloadFlows:
flows:
- url: https://raw.githubusercontent.com/datastax/langflow-charts/main/examples/flows/basic-prompting-hello-world.json
endpoint: hello-world
env:
- name: LANGFLOW_LOG_LEVEL
value: "INFO"
- name: OPENAI_API_KEY
valueFrom:
secretKeyRef:
name: langflow-secrets
key: openai-key
```
See the full file at [basic-prompting-hello-world.yaml](https://raw.githubusercontent.com/datastax/langflow-charts/main/examples/flows/langflow-runtime/basic-prompting-hello-world.yaml)

Now we can deploy the chart (using option 1):

```bash
helm repo add langflow https://langflow-ai.github.io/langflow-helm-charts
helm repo update
helm install langflow-runtime langflow/langflow-runtime \
--set "downloadFlows.flows[0].uuid=4ca07770-c0e4-487c-ad42-77c6039ce02e" \
--set "downloadFlows.flows[0].url=https://raw.githubusercontent.com/datastax/langflow-charts/main/examples/langflow-runtime/just-chat/justchat.json" \
--set replicaCount=1
helm install langflow-runtime langflow/langflow-runtime --values custom-values.yaml
```

Tunnel the service to localhost:
Expand All @@ -41,22 +64,66 @@ Tunnel the service to localhost:
kubectl port-forward svc/langflow-langflow-runtime 7860:7860
```

Call the flow API endpoint:
Call the flow API endpoint using `hello-world` as flow name:
```bash
curl -X POST \
"http://localhost:7860/api/v1/run/4ca07770-c0e4-487c-ad42-77c6039ce02e?stream=false" \
"http://localhost:7860/api/v1/run/hello-world?stream=false" \
-H 'Content-Type: application/json'\
-d '{
"input_value": "message",
"input_value": "Hello there!",
"output_type": "chat",
"input_type": "chat",
"tweaks": {
"ChatInput-1BPcY": {},
"ChatOutput-J1bsS": {}
}
"input_type": "chat"
}'
```


## Upgrade Langflow version
To change the Langflow version or use a custom docker image, you can modify the `image` parameter in the chart.

```yaml
image:
repository: "langflowai/langflow-backend"
tag: 1.x.y
```

## Download flows options
The `downloadFlows` section in the `values.yaml` file allows you to download flows from remote locations.
You can specify the following options:
* `url`: The URL of the flow. Must point to a JSON file.
* `endpoint`: Override the endpoint of the flow. By default, the endpoint is the UUID of the flow or anything you set in the flow (`endpoint_name` key).
* `uuid`: Override the UUID of the flow. If not specified, the UUID will be extracted from the flow file.
* `basicAuth`: Basic authentication credentials in the form `username:password`.
* `headers`: Custom headers to add to the request. For example, to add Authorization header for downloading from private repositories.

## Langflow secrets
The `env` section in the `values.yaml` file allows you to set environment variables for the Langflow deployment.
The recommended way to set sensitive information is to use Kubernetes secrets.
You can reference a secret in the `values.yaml` file by using the `valueFrom` key.

```yaml
env:
- name: OPENAI_API_KEY
valueFrom:
secretKeyRef:
name: langflow-secrets
key: openai-key
- name: ASTRA_DB_APPLICATION_TOKEN
valueFrom:
secretKeyRef:
name: langflow-secrets
key: astra-token
```
where:
* `name`: refer to the environment variable name used by your flow.
* `valueFrom.secretKeyRef.name`: refers to the kubernetes secret name.
* `valueFrom.secretKeyRef.key`: refers to the key in the secret.
For example, to create a matching secret with the above example you can use the following command:

```
kubectl create secret generic langflow-secrets --from-literal=openai-key=sk-xxxx --from-literal=astra-token=AstraCS:xxx
```


## Scale the flows

In order to add more resources to the flows container, you could decide to scale:
Expand All @@ -68,12 +135,11 @@ In order to add more resources to the flows container, you could decide to scale

To scale horizontally you only need to modify the `replicaCount` parameter in the chart.

```yaml
helm install langflow-runtime langflow/langflow-runtime \
--set "downloadFlows.flows[0].uuid=4ca07770-c0e4-487c-ad42-77c6039ce02e" \
--set "downloadFlows.flows[0].url=https://raw.githubusercontent.com/datastax/langflow-charts/main/examples/langflow-runtime/just-chat/justchat.json" \
--set replicaCount=5
```
replicaCount: 5
```
Please note that if your flow relies on shared state (e.g. builtin chat memory), you will need to setup a shared database.
### Scale vertically
Expand All @@ -89,13 +155,3 @@ resources:
cpu: 100m
memory: 128Mi
```
To scale vertically you only need modify the `resources`

```
helm install langflow-runtime langflow/langflow-runtime \
--set "downloadFlows.flows[0].uuid=4ca07770-c0e4-487c-ad42-77c6039ce02e" \
--set "downloadFlows.flows[0].url=https://raw.githubusercontent.com/datastax/langflow-charts/main/examples/langflow-runtime/just-chat/justchat.json" \
--set replicaCount=5
```
10 changes: 7 additions & 3 deletions charts/langflow-runtime/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ spec:
set -e &&
mkdir -p {{ .Values.downloadFlows.path }} &&
{{- range .Values.downloadFlows.flows }}
echo "Downloading flows from {{ .url }}" &&
curl --fail -o {{ $.Values.downloadFlows.path }}/{{ .uuid | default (.url | sha256sum | trunc 8) }}.json \
{{- $targetFile := printf "%s/%s.json" $.Values.downloadFlows.path (.uuid | default (.url | sha256sum | trunc 8)) -}}
echo "Downloading flows from {{ .url }} to {{ $targetFile }}" &&
curl --fail -o '{{ $targetFile }}' \
{{- if .basicAuth }}
-u "{{ .basicAuth }}" \
{{- end }}
Expand All @@ -64,7 +65,10 @@ spec:
-H "{{ $key }}: {{ $value }}" \
{{- end }}
{{- end }}
{{ .url }} &&
'{{ .url }}' &&
{{- if .endpoint }}
python -c 'import json, sys;f = sys.argv[1]; data = json.load(open(f));data["endpoint_name"]="{{ .endpoint }}";json.dump(data, open(f, "w"))' '{{ $targetFile }}' &&
{{- end }}
{{- end }}
echo 'Flows downloaded' &&
langflow run --backend-only --host 0.0.0.0 --port {{ .Values.service.port }}
Expand Down
6 changes: 3 additions & 3 deletions charts/langflow-runtime/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ securityContext: {}
env:
- name: LANGFLOW_LOG_LEVEL
value: "INFO"
# - name: openai_key_var
# - name: OPENAI_API_KEY
# valueFrom:
# secretKeyRef:
# name: openai-key
# name: langflow-secrets
# key: openai-key


Expand Down Expand Up @@ -108,4 +108,4 @@ nodeSelector: {}

tolerations: []

affinity: {}
affinity: {}
Loading

0 comments on commit 44fdb23

Please sign in to comment.