Skip to content

Commit bcb85ef

Browse files
author
Arena AI Agent
committed
feat(api): 🔌 build Enterprise-Ready RESTful FastAPI backend to allow external integration of the Epistemic Engine
1 parent 02930f3 commit bcb85ef

3 files changed

Lines changed: 85 additions & 1 deletion

File tree

‎Makefile‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ help:
1010
@echo " make lint - Run Ruff to check code formatting and errors"
1111
@echo " make clean - Remove __pycache__, .pytest_cache, and build files"
1212
@echo " make cli - Test the CLI interface directly"
13+
@echo " make serve - Launch the RESTful FastAPI backend server"
1314

1415
install:
1516
@echo "Installing Epistemic Forge..."
@@ -32,3 +33,7 @@ clean:
3233
cli:
3334
@echo "Running CLI test query..."
3435
epistemic-forge --query "Is RAG strictly better than Long-Context LLMs?"
36+
37+
serve:
38+
@echo "Booting Enterprise API Server..."
39+
uvicorn epistemic_forge.ui.api:app --host 0.0.0.0 --port 8000 --reload

‎epistemic_forge/ui/api.py‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
"""FastAPI Backend for Epistemic Forge.
2+
3+
Provides a RESTful Enterprise-Ready API to integrate the Neuro-Symbolic
4+
engine into any larger MLOps or business workflow.
5+
"""
6+
from fastapi import FastAPI, HTTPException, BackgroundTasks
7+
from pydantic import BaseModel
8+
from typing import List, Optional, Dict, Any
9+
from epistemic_forge.models import ProjectSpec
10+
from epistemic_forge.pipeline.arsenal_run import run_pipeline
11+
12+
app = FastAPI(
13+
title="Epistemic Forge API",
14+
description="Neuro-Symbolic State Machine API for Deterministic Reasoning.",
15+
version="1.0.0-rc1"
16+
)
17+
18+
class ForgeRequest(BaseModel):
19+
title: str
20+
question: str
21+
domain: str = "hybrid"
22+
target_model: str = "openai/gpt-4o-mini"
23+
keywords: List[str] = []
24+
api_key: Optional[str] = None
25+
api_base: Optional[str] = None
26+
budget_tokens: int = 15000
27+
28+
class ForgeResponse(BaseModel):
29+
status: str
30+
score: float
31+
claims: List[Dict[str, Any]]
32+
final_memo: str
33+
peer_review: Dict[str, Any]
34+
35+
@app.post("/api/v1/forge", response_model=ForgeResponse)
36+
async def generate_claim_lattice(req: ForgeRequest):
37+
"""Executes the full L0-L6 pipeline and returns a structured lattice and synthesis."""
38+
try:
39+
spec = ProjectSpec(
40+
title=req.title,
41+
question=req.question,
42+
domain=req.domain,
43+
target_model=req.target_model,
44+
keywords=req.keywords,
45+
api_key=req.api_key,
46+
api_base=req.api_base,
47+
budget_tokens=req.budget_tokens
48+
)
49+
50+
result = run_pipeline(
51+
title=spec.title,
52+
question=spec.question,
53+
domain=spec.domain.value
54+
)
55+
56+
final_memo = ""
57+
for art in getattr(result, "artifacts", []):
58+
if art.name == "Final Synthesis Memo":
59+
final_memo = art.content
60+
break
61+
62+
# Handle claims safely
63+
raw_claims = getattr(result, "claims", [])
64+
claims_list = [c.model_dump() if hasattr(c, "model_dump") else c for c in raw_claims]
65+
66+
return ForgeResponse(
67+
status="success",
68+
score=getattr(result, "final_score", 0.0),
69+
claims=claims_list,
70+
final_memo=final_memo,
71+
peer_review=getattr(result, "peer_review", {})
72+
)
73+
74+
except Exception as e:
75+
raise HTTPException(status_code=500, detail=str(e))
76+
77+
@app.get("/health")
78+
async def health_check():
79+
return {"status": "operational", "engine": "neuro-symbolic-v1"}

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ classifiers = [
3131
"Topic :: Scientific/Engineering :: Artificial Intelligence",
3232
"Topic :: Text Processing :: Linguistic",
3333
]
34-
dependencies = ["litellm>=1.40.0", "duckduckgo-search>=5.0.0", "chromadb>=0.4.0", "nbformat>=5.0.0", "pydantic>=2.0.0", "loguru>=0.7.0", "tenacity>=8.0.0", "instructor>=1.3.0", "rich>=13.0.0", "streamlit>=1.35.0"]
34+
dependencies = ["litellm>=1.40.0", "duckduckgo-search>=5.0.0", "chromadb>=0.4.0", "nbformat>=5.0.0", "fastapi>=0.100.0", "uvicorn>=0.20.0", "pydantic>=2.0.0", "loguru>=0.7.0", "tenacity>=8.0.0", "instructor>=1.3.0", "rich>=13.0.0", "streamlit>=1.35.0"]
3535

3636
[project.optional-dependencies]
3737
dev = ["pytest>=7.0", "pytest-mock"]

0 commit comments

Comments
 (0)