feat: chatbot
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
"""
|
||||
Free-form, read-only chat with GPT-4o about the current cockpit state.
|
||||
No function-calling — this endpoint can never trigger an action.
|
||||
Free-form chat with GPT-4o about the current cockpit state.
|
||||
The only tool the model can call (propose_trade) just writes a pending row to
|
||||
ai_trade_proposals — it never touches the real portfolio. Confirm/reject below
|
||||
are the only way a proposal turns into (or is discarded from) a real position.
|
||||
"""
|
||||
from typing import List, Optional
|
||||
|
||||
@@ -58,3 +60,50 @@ def clear_session(body: ClearBody):
|
||||
clear_chat_session(body.session_id)
|
||||
clear_context_cache(body.session_id)
|
||||
return {"cleared": body.session_id}
|
||||
|
||||
|
||||
@router.get("/trade-proposals")
|
||||
def list_trade_proposals(status: str = "pending"):
|
||||
from services.database import get_ai_trade_proposals
|
||||
return {"proposals": get_ai_trade_proposals(status=status)}
|
||||
|
||||
|
||||
@router.post("/trade-proposals/{proposal_id}/confirm")
|
||||
def confirm_trade_proposal(proposal_id: str):
|
||||
"""Promotes a pending AI proposal into a real open position, reusing the
|
||||
same enrichment (live price, Black-Scholes leg pricing) as a manual add."""
|
||||
from services.database import get_ai_trade_proposal, resolve_ai_trade_proposal
|
||||
from routers.portfolio import add_pos, AddPositionRequest
|
||||
|
||||
proposal = get_ai_trade_proposal(proposal_id)
|
||||
if not proposal:
|
||||
raise HTTPException(404, "Proposition introuvable.")
|
||||
if proposal["status"] != "pending":
|
||||
raise HTTPException(400, f"Proposition deja {proposal['status']}.")
|
||||
|
||||
req = AddPositionRequest(
|
||||
title=proposal["title"],
|
||||
underlying=proposal["underlying"],
|
||||
strategy=proposal["strategy"],
|
||||
asset_class=proposal.get("asset_class") or "indices",
|
||||
expiry_days=proposal.get("expiry_days") or 90,
|
||||
legs=proposal.get("legs") or [],
|
||||
capital_invested=proposal["capital_invested"],
|
||||
geo_trigger=proposal.get("geo_trigger") or "",
|
||||
rationale=proposal.get("rationale") or "",
|
||||
)
|
||||
result = add_pos(req)
|
||||
resolve_ai_trade_proposal(proposal_id, "confirmed", portfolio_id=result["id"])
|
||||
return {"status": "confirmed", "portfolio_id": result["id"]}
|
||||
|
||||
|
||||
@router.post("/trade-proposals/{proposal_id}/reject")
|
||||
def reject_trade_proposal(proposal_id: str):
|
||||
from services.database import get_ai_trade_proposal, resolve_ai_trade_proposal
|
||||
proposal = get_ai_trade_proposal(proposal_id)
|
||||
if not proposal:
|
||||
raise HTTPException(404, "Proposition introuvable.")
|
||||
if proposal["status"] != "pending":
|
||||
raise HTTPException(400, f"Proposition deja {proposal['status']}.")
|
||||
resolve_ai_trade_proposal(proposal_id, "rejected")
|
||||
return {"status": "rejected"}
|
||||
|
||||
Reference in New Issue
Block a user