-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
181 lines (145 loc) · 4.85 KB
/
Copy pathmain.py
File metadata and controls
181 lines (145 loc) · 4.85 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
"""
0xLaVaN x402 API - Monetized Agent Services
Revenue while sleeping. Code as leverage.
"""
import os
from dotenv import load_dotenv
from fastapi import FastAPI, HTTPException
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
from x402.http import FacilitatorConfig, HTTPFacilitatorClient, PaymentOption
from x402.http.middleware.fastapi import PaymentMiddlewareASGI
from x402.http.types import RouteConfig
from x402.mechanisms.evm.exact import ExactEvmServerScheme
from x402.schemas import Network
from x402.server import x402ResourceServer
load_dotenv()
# Config
WALLET_ADDRESS = os.getenv("WALLET_ADDRESS", "0x11F5397F191144894cD907A181ED61A7bf5634dE")
NETWORK: Network = "eip155:8453" # Base Mainnet
FACILITATOR_URL = os.getenv("FACILITATOR_URL", "https://x402.org/facilitator")
if not WALLET_ADDRESS:
raise ValueError("WALLET_ADDRESS required")
# Response schemas
class ThesisRequest(BaseModel):
thesis: str
class RoastResponse(BaseModel):
roast: str
weaknesses: list[str]
counter_thesis: str
confidence_adjustment: str
class GameTheoryRequest(BaseModel):
situation: str
players: list[str]
class GameTheoryResponse(BaseModel):
game_type: str
players_analysis: dict
nash_equilibria: list[str]
dominant_strategies: dict
recommendation: str
class HealthResponse(BaseModel):
agent: str
philosophy: str
services: dict
# App
app = FastAPI(
title="0xLaVaN API",
description="Permissionless agent services. Pay per request.",
version="0.1.0"
)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_methods=["*"],
allow_headers=["*"],
)
# x402 Middleware
facilitator = HTTPFacilitatorClient(FacilitatorConfig(url=FACILITATOR_URL))
server = x402ResourceServer(facilitator)
server.register(NETWORK, ExactEvmServerScheme())
routes = {
"POST /roast": RouteConfig(
accepts=[
PaymentOption(
scheme="exact",
pay_to=WALLET_ADDRESS,
price="$0.02",
network=NETWORK,
),
],
mime_type="application/json",
description="Roast your trade thesis - contrarian analysis with weaknesses exposed",
),
"POST /game-theory": RouteConfig(
accepts=[
PaymentOption(
scheme="exact",
pay_to=WALLET_ADDRESS,
price="$0.05",
network=NETWORK,
),
],
mime_type="application/json",
description="Game theory analysis - Nash equilibria, dominant strategies, recommendations",
),
}
app.add_middleware(PaymentMiddlewareASGI, routes=routes, server=server)
# Routes
@app.get("/", response_model=HealthResponse)
async def root():
"""Health check - free"""
return HealthResponse(
agent="0xLaVaN",
philosophy="Wealth through leverage. Happiness through subtraction.",
services={
"POST /roast": "$0.02 - Contrarian analysis of your trade thesis",
"POST /game-theory": "$0.05 - Nash equilibrium analysis of any situation",
}
)
@app.post("/roast", response_model=RoastResponse)
async def roast_thesis(request: ThesisRequest):
"""
Roast My Thesis - $0.02 USDC
Submit your trade thesis. Get back:
- Brutal contrarian take
- List of weaknesses
- Counter-thesis
- Confidence adjustment recommendation
"""
thesis = request.thesis
if len(thesis) < 20:
raise HTTPException(400, "Thesis too short. Give me something to work with.")
if len(thesis) > 2000:
raise HTTPException(400, "Thesis too long. Brevity is the soul of wit.")
# TODO: Integrate actual LLM analysis
# For now, return structured placeholder
return RoastResponse(
roast="[LLM analysis pending integration]",
weaknesses=["Placeholder - real analysis coming"],
counter_thesis="[Counter-thesis generation pending]",
confidence_adjustment="Wait for full integration"
)
@app.post("/game-theory", response_model=GameTheoryResponse)
async def analyze_game_theory(request: GameTheoryRequest):
"""
Game Theory Analysis - $0.05 USDC
Describe a situation and players. Get back:
- Game classification
- Player incentive analysis
- Nash equilibria
- Dominant strategies
- Strategic recommendation
"""
if len(request.players) < 2:
raise HTTPException(400, "Need at least 2 players for game theory.")
# TODO: Integrate game theory skill
return GameTheoryResponse(
game_type="[Classification pending]",
players_analysis={},
nash_equilibria=["[Analysis pending integration]"],
dominant_strategies={},
recommendation="[Strategic recommendation pending]"
)
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8402)