Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions backend/api/assembly_plans.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from backend.services.assembly_plan_build_service import AssemblyPlanBuildService
from backend.services.circuit_graph import build_circuit_graph
from backend.services.circuit_graph_ai import CircuitGraphAiEnrichmentService
from backend.services.conversation_bench_plan_service import ConversationBenchPlanService
from backend.services.ingestion_ai_review_service import estimate_local_tokens
from backend.services.openai_assist_utils import parse_json_object

Expand All @@ -29,6 +30,11 @@ class AssemblyBuildRequest(BaseModel):
strategy: str = "Vector + CrossEncoder"


class ConversationBenchPlanRequest(BaseModel):
conversationId: str = ""
objective: str = ""


class StepUpdateRequest(BaseModel):
completed: bool = False

Expand All @@ -47,6 +53,7 @@ def create_router(
deps: ApiDependencies,
*,
assembly_plan_store: Any,
conversation_store: Any,
bench_tools: Any,
openai_assist_service: Any | None,
get_rag_response: Callable[..., Any],
Expand All @@ -57,6 +64,7 @@ def create_router(
recovery_system_prompt: str,
default_model: str,
username_for_user: Callable[[Any], str | None],
trace_logger: Any = None,
) -> APIRouter:
router = APIRouter()
build_service = AssemblyPlanBuildService(
Expand All @@ -73,6 +81,16 @@ def create_router(
openai_assist_service=openai_assist_service,
query_local_llm=query_ollama_chat_with_retry,
local_model_name=default_model,
trace_logger=trace_logger,
)
conversation_bench_service = ConversationBenchPlanService(
conversation_store=conversation_store,
assembly_plan_store=assembly_plan_store,
ai_provider_store=deps.ai_provider_store,
openai_assist_service=openai_assist_service,
query_local_llm=query_ollama_chat_with_retry,
local_model_name=default_model,
trace_logger=trace_logger,
)

@router.get("/api/assembly-plans")
Expand Down Expand Up @@ -148,6 +166,39 @@ async def assembly_plan_build(req: Request, payload: AssemblyBuildRequest):
"validation": result.get("validation"),
}

@router.post("/api/assembly-plans/from-conversation")
async def assembly_plan_from_conversation(req: Request, payload: ConversationBenchPlanRequest):
user, entity, error = deps.require_entity_member(req)
if error:
return error
conversation_id = payload.conversationId.strip()
if not conversation_id:
return JSONResponse({"error": "Conversation id is required."}, status_code=400)
user_id = deps.user_id_for_user(user)
result = await run_in_threadpool(
conversation_bench_service.create_plan,
conversation_id=conversation_id,
user_id=user_id,
username=username_for_user(user),
entity_id=entity.entity_id,
objective_override=payload.objective,
)
if not result.get("ok"):
return JSONResponse(
{
"error": result.get("error") or "Conversation could not be converted into a Bench plan.",
"aiReview": result.get("aiReview"),
"validation": result.get("validation"),
},
status_code=int(result.get("status") or 422),
)
return {
"plan": result.get("plan"),
"source": result.get("source"),
"aiReview": result.get("aiReview"),
"validation": result.get("validation"),
}

@router.patch("/api/assembly-plans/{plan_id}/steps/{step_id}")
async def assembly_step_update(plan_id: str, step_id: str, req: Request, payload: StepUpdateRequest):
user, error = deps.require_authenticated_user(req)
Expand Down
2 changes: 2 additions & 0 deletions backend/app_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ def register_api_routes(
app.include_router(assembly_plans_api.create_router(
api_dependencies,
assembly_plan_store=assembly_plan_store,
conversation_store=conversation_store,
bench_tools=bench_tools,
openai_assist_service=openai_assist_service,
get_rag_response=get_rag_response,
Expand All @@ -135,6 +136,7 @@ def register_api_routes(
recovery_system_prompt=recovery_system_prompt,
default_model=default_model,
username_for_user=username_for_user,
trace_logger=trace_logger,
))
app.include_router(documents_api.create_router(
api_dependencies,
Expand Down
Loading