This project demonstrates Server-Sent Events (SSE) in Django using CrewAI and Daphne as the ASGI server. The system simulates an AI-powered HR assistant that communicates with candidates through streamed responses.
python-dotenv
git clone https://github.com/zas03ia/SSE_CrewAI.git cd django-sse-crewai
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate pip install -r requirements.txt
.env
File & Add API KeyCreate a .env
file in the root directory:
GEMINI_API_KEY=your-google-gemini-api-key
šØ Don't commit .env
to Git. Add it to .gitignore
.
python manage.py migrate
python manage.py runserver
Daphne is used because it supports ASGI (for SSE).
settings.py
Ensure ASGI is properly configured:
ASGI_APPLICATION = "sse_demo.asgi.application"
views.py
)# Implementation Example from django.http import StreamingHttpResponse from django.shortcuts import render import asyncio async def sse_stream(request): # ..... more code here asyncio.create_task(async_crew_execution()) async def event_stream(): while process['crew_executes']: yield f"data: {process['event']}\n\n" await asyncio.sleep(0.2) return StreamingHttpResponse(event_stream(), content_type="text/event-stream")
urls.py
)from django.urls import path from .views import sse_stream urlpatterns = [ path("sse/", sse_stream, name="sse_stream"), ]
This project showcases how to integrate CrewAI with Django and SSE streaming using an ASGI-compatible setup with Daphne. š
Feel free to contribute and improve the project! š
Project link: https://github.com/zas03ia/SSE_CrewAI
There are no models linked
There are no datasets linked
There are no models linked
There are no datasets linked