Spaces:
Sleeping
Sleeping
File size: 1,250 Bytes
41f0f2e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | from ninja import Router
from django.http import StreamingHttpResponse
import json
from .council.orchestrator import CouncilOrchestrator
router = Router()
@router.get("/council/stream")
def council_stream(request, query: str, api_key: str = None):
def event_stream():
council = CouncilOrchestrator(api_key=api_key)
# Stage 1
yield f"data: {json.dumps({'type': 'status', 'message': 'Stage 1: Gathering First Opinions...'})}\n\n"
opinions = council.stage_1_opinions(query)
yield f"data: {json.dumps({'type': 'stage1', 'data': opinions})}\n\n"
# Stage 2
yield f"data: {json.dumps({'type': 'status', 'message': 'Stage 2: Peer Review (Anonymized)...'})}\n\n"
reviews = council.stage_2_reviews(query, opinions)
yield f"data: {json.dumps({'type': 'stage2', 'data': reviews})}\n\n"
# Stage 3
yield f"data: {json.dumps({'type': 'status', 'message': 'Stage 3: Chairman Synthesis...'})}\n\n"
final_answer = council.stage_3_synthesis(query, opinions, reviews)
yield f"data: {json.dumps({'type': 'final', 'data': final_answer})}\n\n"
return StreamingHttpResponse(event_stream(), content_type='text/event-stream')
|