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
2 changes: 2 additions & 0 deletions apps/api/src/planproof_api/agent/planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from openai import OpenAI

from planproof_api.agent.schemas import ExtractedMetadata, PlanItem
from planproof_api.observability.opik import opik

_SYSTEM_PROMPT = (
"You are a planning assistant. Return ONLY valid JSON with keys: "
Expand All @@ -18,6 +19,7 @@ class PlanGenerationError(RuntimeError):
pass


@opik.track(name="generate_plan")
def generate_plan(
context: str,
metadata: ExtractedMetadata,
Expand Down
14 changes: 14 additions & 0 deletions apps/api/src/planproof_api/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from __future__ import annotations

from pydantic_settings import BaseSettings, SettingsConfigDict


class Settings(BaseSettings):
OPIK_API_KEY: str | None = None
OPIK_PROJECT_NAME: str = "Hackaton"
OPIK_WORKSPACE: str = "silviu-druma"

model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8")


settings = Settings()
15 changes: 15 additions & 0 deletions apps/api/src/planproof_api/main.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
from __future__ import annotations

from pathlib import Path
import sys

from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles

from planproof_api.config import settings
from planproof_api.observability.opik import opik
from planproof_api.routes import router

try:
opik.configure(
api_key=settings.OPIK_API_KEY,
workspace=settings.OPIK_WORKSPACE,
project_name=settings.OPIK_PROJECT_NAME,
)
print(
f"OPIK INITIALIZED: {settings.OPIK_WORKSPACE}/{settings.OPIK_PROJECT_NAME}"
)
except Exception as exc:
print(f"OPIK WARNING: Failed to initialize. ({exc})", file=sys.stderr)

app = FastAPI()

app.include_router(router)
Expand Down
10 changes: 9 additions & 1 deletion apps/api/src/planproof_api/observability/opik.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys

if "OPIK_PROJECT_NAME" not in os.environ:
os.environ["OPIK_PROJECT_NAME"] = "PlanProof"
os.environ["OPIK_PROJECT_NAME"] = "Hackaton"


def _warn(message: str) -> None:
Expand Down Expand Up @@ -35,6 +35,14 @@ def decorator(func):

return decorator

@staticmethod
def configure(*_args, **_kwargs) -> None:
return None

@staticmethod
def get_current_trace_id() -> None:
return None


class _NoOpOpikContext:
@staticmethod
Expand Down
16 changes: 16 additions & 0 deletions apps/api/src/planproof_api/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ def create_plan(request: PlanRequest) -> PlanResponse:
pass

metadata = extract_metadata(request.context)
print(
f"DEBUG: Extractor produced {len(metadata.task_keywords)} keywords"
)
try:
plan, assumptions, questions = _initial_planning_step(request, metadata)
except PlanGenerationError as exc:
Expand Down Expand Up @@ -190,6 +193,12 @@ def create_plan(request: PlanRequest) -> PlanResponse:
)

validation = _validate_plan(plan, metadata, request.current_time)
print(
"DEBUG: Validation - Overlaps: "
f"{validation.metrics.overlap_minutes}, "
"Recall: "
f"{validation.metrics.keyword_recall_score}"
)
repair_attempted = False
repair_success = False

Expand All @@ -201,6 +210,12 @@ def create_plan(request: PlanRequest) -> PlanResponse:
)
validation = _validate_plan(plan, metadata, request.current_time)
repair_success = validation.status == "pass"
print(
"DEBUG: Validation (repair) - Overlaps: "
f"{validation.metrics.overlap_minutes}, "
"Recall: "
f"{validation.metrics.keyword_recall_score}"
)
except PlanGenerationError as exc:
validation = PlanValidation(
status="fail",
Expand All @@ -213,6 +228,7 @@ def create_plan(request: PlanRequest) -> PlanResponse:
),
errors=[str(exc)],
)
print(f"DEBUG: Trace ID: {opik.get_current_trace_id() or 'No Trace'}")

return PlanResponse(
plan=plan,
Expand Down