Spaces:
Sleeping
Sleeping
| from ninja import Router | |
| from django.http import StreamingHttpResponse | |
| import json | |
| from .council.orchestrator import CouncilOrchestrator | |
| router = Router() | |
| 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') | |