-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_simple.py
More file actions
135 lines (118 loc) · 4.39 KB
/
api_simple.py
File metadata and controls
135 lines (118 loc) · 4.39 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/env python3
"""Simplified REST API for ReqDefender"""
from fastapi import FastAPI
from pydantic import BaseModel
import random
from datetime import datetime
app = FastAPI(
title="ReqDefender REST API",
description="AI Agents Debate Your Requirements to Death",
version="1.0.0"
)
class AnalysisRequest(BaseModel):
requirement: str
judge_type: str = "pragmatist"
intensity: str = "standard"
class AnalysisResult(BaseModel):
requirement: str
verdict: str
confidence: float
reasoning: str
alternative: str = None
estimated_savings: float = None
timestamp: datetime
@app.get("/")
async def root():
"""Root endpoint"""
return {
"service": "ReqDefender API",
"version": "1.0.0",
"description": "AI Agents Debate Your Requirements to Death",
"status": "running",
"endpoints": {
"analyze": "/analyze",
"quick": "/quick",
"health": "/health"
}
}
@app.post("/analyze", response_model=AnalysisResult)
async def analyze_requirement(request: AnalysisRequest):
"""Analyze a requirement through simulated agent debate"""
# Simple mock analysis logic
req_lower = request.requirement.lower()
# Heuristic-based analysis for demo
if any(word in req_lower for word in ["blockchain", "crypto", "nft", "web3"]):
verdict = "REJECTED"
confidence = random.uniform(80, 95)
reasoning = "Blockchain adds unnecessary complexity and maintenance burden. Historical data shows poor adoption rates."
alternative = "Use PostgreSQL with audit logs for immutable records"
savings = 2100000.0
elif any(word in req_lower for word in ["search", "filter", "sort", "export"]):
verdict = "APPROVED"
confidence = random.uniform(75, 90)
reasoning = "This is a practical feature with clear user value and straightforward implementation."
alternative = None
savings = None
elif any(word in req_lower for word in ["ai", "machine learning", "artificial intelligence"]):
verdict = "CONDITIONAL"
confidence = random.uniform(60, 75)
reasoning = "AI features can provide value but require careful scoping and user research to avoid over-engineering."
alternative = "Start with rule-based approach, then add ML if data supports it"
savings = None
else:
verdict = random.choice(["APPROVED", "REJECTED", "CONDITIONAL", "NEEDS_RESEARCH"])
confidence = random.uniform(60, 85)
reasoning = "Mixed evidence from agent debate. Some concerns about complexity vs. user value."
alternative = "Consider a simpler MVP approach first"
savings = random.uniform(500000, 2000000) if verdict == "REJECTED" else None
return AnalysisResult(
requirement=request.requirement,
verdict=verdict,
confidence=round(confidence, 1),
reasoning=reasoning,
alternative=alternative,
estimated_savings=savings,
timestamp=datetime.now()
)
@app.post("/quick")
async def quick_analysis(requirement: str):
"""Quick analysis with minimal processing"""
result = await analyze_requirement(AnalysisRequest(
requirement=requirement,
judge_type="pragmatist",
intensity="quick"
))
return {
"requirement": requirement,
"verdict": result.verdict,
"confidence": result.confidence,
"summary": f"{result.verdict} with {result.confidence}% confidence"
}
@app.get("/health")
async def health_check():
"""Health check endpoint"""
return {
"status": "healthy",
"timestamp": datetime.now().isoformat(),
"service": "ReqDefender API"
}
@app.get("/stats")
async def get_stats():
"""Get API statistics"""
return {
"message": "ReqDefender API is running",
"agents": {
"pro_team": ["Product Visionary", "Sales Champion", "UX Designer"],
"con_team": ["Senior Architect", "QA Engineer", "Data Analyst"],
"judges": ["Pragmatist", "Innovator", "User Advocate"]
},
"sample_requirements": [
"Add blockchain to our todo app",
"Implement search functionality",
"Build AI-powered recommendations"
]
}
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8001)
#built with love