Add Phase 13 internal accounting model
This commit is contained in:
@@ -9,7 +9,7 @@ from app.core.db.common import CommonSessionLocal
|
||||
from app.core.security.csrf import get_or_create_csrf_token, validate_csrf
|
||||
from app.core.templating import templates
|
||||
from app.modules.accounting.bank_service import (
|
||||
ai_assist_transaction, confirm_review, import_completed_job, preflight_choices, queue_post, queue_preflight,
|
||||
ai_assist_transaction, confirm_review, import_completed_job, internal_model_predict_transaction, preflight_choices, queue_post, queue_preflight,
|
||||
queue_rows, sync_posting, visible_workstations,
|
||||
)
|
||||
from app.modules.accounting.ledger_learning_service import active_natures
|
||||
@@ -155,3 +155,37 @@ def ai_assist(
|
||||
return _go(client_id, error=str(exc))
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
@router.post("/{tx_id}/internal-predict")
|
||||
def internal_predict(
|
||||
request: Request,
|
||||
tx_id: int,
|
||||
client_id: int = Form(...),
|
||||
csrf_token: str = Form(...),
|
||||
):
|
||||
validate_csrf(request, csrf_token)
|
||||
db = CommonSessionLocal()
|
||||
try:
|
||||
user, denied = _require_partner(request, db, "accounting.learning.manage")
|
||||
if denied:
|
||||
return denied
|
||||
client, _, scope = _find_visible_client(db, request, user, client_id)
|
||||
if not client:
|
||||
return _go(error="Client is not visible.")
|
||||
prediction = internal_model_predict_transaction(
|
||||
db,
|
||||
tx_id=tx_id,
|
||||
tenant_id=scope.tenant_id,
|
||||
client_id=client.id,
|
||||
force_shadow=True,
|
||||
)
|
||||
return _go(
|
||||
client.id,
|
||||
message=f"Internal model shadow prediction recorded at {prediction.predicted_probability * 100:.1f}%.",
|
||||
)
|
||||
except Exception as exc:
|
||||
db.rollback()
|
||||
return _go(client_id, error=str(exc))
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
Reference in New Issue
Block a user