Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions samples/crew-django-advanced/.devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM mcr.microsoft.com/devcontainers/python:3.12-bookworm
11 changes: 11 additions & 0 deletions samples/crew-django-advanced/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"build": {
"dockerfile": "Dockerfile",
"context": ".."
},
"features": {
"ghcr.io/defanglabs/devcontainer-feature/defang-cli:1.0.4": {},
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/devcontainers/features/aws-cli:1": {}
}
}
27 changes: 27 additions & 0 deletions samples/crew-django-advanced/.github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Deploy

on:
push:
branches:
- main

jobs:
deploy:
environment: playground
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write

steps:
- name: Checkout Repo
uses: actions/checkout@v4

- name: Deploy
uses: DefangLabs/[email protected]
with:
config-env-vars: DJANGO_SECRET_KEY POSTGRES_PASSWORD SSL_MODE
env:
DJANGO_SECRET_KEY: ${{ secrets.DJANGO_SECRET_KEY }}
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
SSL_MODE: ${{ secrets.SSL_MODE }}
37 changes: 37 additions & 0 deletions samples/crew-django-advanced/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Python
__pycache__/
*.pyc
*.pyo
*.pyd
.Python
env/
venv/
ENV/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# Django
*.log
staticfiles/
media/
db.sqlite3

# Node
node_modules/
.next/
.env

# Docker
pgdata/
90 changes: 90 additions & 0 deletions samples/crew-django-advanced/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Crew.ai Advanced Django Sample

[![1-click-deploy](https://raw.githubusercontent.com/DefangLabs/defang-assets/main/Logos/Buttons/SVG/deploy-with-defang.svg)](https://portal.defang.dev/redirect?url=https%3A%2F%2Fgithub.com%2Fnew%3Ftemplate_name%3Dsample-crew-django-redis-postgres-template%26template_owner%3DDefangSamples)

This sample builds upon the basic CrewAI example and demonstrates a
multi-agent workflow. A lightweight classifier determines whether the user is
requesting a summary, a deeper research answer or a translation. Depending on
the decision different agents – powered by multiple LLM sizes – are executed
and the progress is streamed back to the browser using Django Channels.

## Prerequisites

1. Download [Defang CLI](https://github.com/DefangLabs/defang)
2. (Optional) If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc) authenticate with your cloud provider account
3. (Optional for local development) [Docker CLI](https://docs.docker.com/engine/install/)

## Development

To run the application locally, you can use the following command:

```bash
docker compose -f ./compose.local.yaml up --build
```

## Configuration

For this sample, you will need to provide the following [configuration](https://docs.defang.io/docs/concepts/configuration):

> Note that if you are using the 1-click deploy option, you can set these values as secrets in your GitHub repository and the action will automatically deploy them for you.

### `POSTGRES_PASSWORD`
The password for the Postgres database.
```bash
defang config set POSTGRES_PASSWORD
```

### `SSL_MODE`

The SSL mode for the Postgres database.
```bash
defang config set SSL_MODE
```

### `DJANGO_SECRET_KEY`

The secret key for the Django application.
```bash
defang config set DJANGO_SECRET_KEY
```

### LLM configuration

Three different LLM endpoints are used to demonstrate branching. Configure them via:

```bash
defang config set SMALL_LLM_URL
defang config set SMALL_LLM_MODEL
defang config set MEDIUM_LLM_URL
defang config set MEDIUM_LLM_MODEL
defang config set LARGE_LLM_URL
defang config set LARGE_LLM_MODEL
```

In addition the embedding model is configured with `EMBEDDING_URL` and `EMBEDDING_MODEL`.

## Deployment

> [!NOTE]
> Download [Defang CLI](https://github.com/DefangLabs/defang)

### Defang Playground

Deploy your application to the Defang Playground by opening up your terminal and typing:
```bash
defang compose up
```

### BYOC

If you want to deploy to your own cloud account, you can [use Defang BYOC](https://docs.defang.io/docs/tutorials/deploy-to-your-cloud).

---

Title: Crew.ai Advanced Django Sample

Short Description: Demonstrates branching CrewAI workflows with multiple LLM sizes to handle summarisation, research and translation requests.

Tags: Django, Celery, Redis, Postgres, AI, ML, CrewAI

Languages: Python
27 changes: 27 additions & 0 deletions samples/crew-django-advanced/app/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Default .dockerignore file for Defang
**/__pycache__
**/.direnv
**/.DS_Store
**/.envrc
**/.git
**/.github
**/.idea
**/.next
**/.vscode
**/compose.*.yaml
**/compose.*.yml
**/compose.yaml
**/compose.yml
**/docker-compose.*.yaml
**/docker-compose.*.yml
**/docker-compose.yaml
**/docker-compose.yml
**/node_modules
**/Thumbs.db
Dockerfile
*.Dockerfile
# Ignore our own binary, but only in the root to avoid ignoring subfolders
defang
defang.exe
# Ignore our project-level state
.defang
21 changes: 21 additions & 0 deletions samples/crew-django-advanced/app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Dockerfile for Django API/Worker
FROM python:3.11-slim

# install curl
RUN apt-get update && apt-get install -y curl \
&& rm -rf /var/lib/apt/lists/*

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
WORKDIR /app

COPY requirements.txt ./
RUN pip install --upgrade pip && pip install -r requirements.txt

COPY . .

RUN python manage.py collectstatic --noinput

RUN chmod +x run.sh

CMD ["./run.sh"]
3 changes: 3 additions & 0 deletions samples/crew-django-advanced/app/config/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .celery import app as celery_app

__all__ = ("celery_app",)
28 changes: 28 additions & 0 deletions samples/crew-django-advanced/app/config/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""
ASGI config for config project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.1/howto/deployment/asgi/
"""

import os

from channels.routing import ProtocolTypeRouter, URLRouter
from django.core.asgi import get_asgi_application
from channels.auth import AuthMiddlewareStack
import os

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')

import core.routing

application = ProtocolTypeRouter({
"http": get_asgi_application(),
"websocket": AuthMiddlewareStack(
URLRouter(
core.routing.websocket_urlpatterns
)
),
})
8 changes: 8 additions & 0 deletions samples/crew-django-advanced/app/config/celery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import os
from celery import Celery

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")

app = Celery("config")
app.config_from_object("django.conf:settings", namespace="CELERY")
app.autodiscover_tasks()
Loading
Loading