MuhammadSaad16's picture
Upload 111 files
807b59f verified

Implementation Tasks: Content Personalization API

Feature Branch: 005-content-personalize Generated: 2025-12-14 Status: βœ… Implementation Complete

Task Summary

Phase Description Task Count
Phase 1 Setup 0 (no setup needed)
Phase 2 Foundational 3
Phase 3 US1 - Beginner Personalization 2
Phase 4 US2 - Advanced Personalization 1
Phase 5 US3 - Intermediate/Hardware 1
Phase 6 Polish & Integration 2
Total 9

Phase 2: Foundational (Blocking Prerequisites)

These tasks must complete before any user story implementation.

  • T001 [P] Create PersonalizeRequest and PersonalizeResponse Pydantic schemas in app/schemas/personalize.py
  • T002 [P] Add personalize_content method to OpenAIService in app/services/openai_service.py
  • T003 Create personalization route with user lookup and OpenAI integration in app/routes/personalize.py

Parallel Execution: T001 and T002 can run in parallel (different files, no dependencies)

Phase 2 Completion Criteria:

  • Schemas validate content (non-empty, ≀50K chars) and user_id (positive integer)
  • OpenAI service method accepts user profile and returns JSON with personalized_content and adjustments_made
  • Route fetches user from database, calls OpenAI, returns PersonalizeResponse

Phase 3: User Story 1 - Beginner Personalization (P1)

Story Goal: A user with beginner software experience submits content and receives personalized content with added explanations and simpler terminology.

Independent Test: Create user with software_level="beginner", submit technical content, verify response includes explanations and simplified language.

Tasks

  • T004 [US1] Verify beginner personalization logic in system prompt includes PL-001 rules (detailed explanations, simpler terminology, examples) in app/services/openai_service.py
  • T005 [US1] Register personalize router in FastAPI application in app/main.py

Phase 3 Completion Criteria:

  • POST /api/personalize returns 200 with personalized_content for beginner user
  • Content includes added explanations and simpler terminology
  • adjustments_made describes the beginner-focused changes

Manual Test (from quickstart.md):

curl -X POST http://localhost:8000/api/personalize \
  -H "Content-Type: application/json" \
  -d '{"content": "A recursive function calls itself to solve smaller instances of the same problem.", "user_id": 1}'

Phase 4: User Story 2 - Advanced Personalization (P1)

Story Goal: A user with advanced software experience submits content and receives personalized content with technical depth, without basic explanations.

Independent Test: Create user with software_level="advanced", submit basic content, verify response has technical depth without redundant basics.

Tasks

  • T006 [US2] Verify advanced personalization logic in system prompt includes PL-003 rules (technical depth, skip basics, precise terminology) in app/services/openai_service.py

Phase 4 Completion Criteria:

  • POST /api/personalize returns content with technical depth for advanced user
  • Basic explanations are omitted
  • adjustments_made describes the advanced-focused changes

Manual Test:

curl -X POST http://localhost:8000/api/personalize \
  -H "Content-Type: application/json" \
  -d '{"content": "Variables store data. Use = to assign values.", "user_id": 2}'

Phase 5: User Story 3 - Intermediate/Hardware Focus (P2)

Story Goal: A user with intermediate software skills but basic hardware knowledge gets appropriately balanced content - moderate software complexity while explaining hardware concepts.

Independent Test: Create user with software_level="intermediate" and hardware_level="basic", submit mixed content, verify appropriate adaptation for each domain.

Tasks

  • T007 [US3] Verify hardware personalization logic in system prompt includes PL-004/PL-005/PL-006 rules for hardware levels in app/services/openai_service.py

Phase 5 Completion Criteria:

  • POST /api/personalize handles mixed software/hardware content
  • Software concepts presented at intermediate level
  • Hardware concepts receive additional explanation for hardware_level="basic"
  • learning_goals influence content emphasis per PL-007

Manual Test:

curl -X POST http://localhost:8000/api/personalize \
  -H "Content-Type: application/json" \
  -d '{"content": "GPIO pins allow the microcontroller to interface with external circuits.", "user_id": 3}'

Phase 6: Polish & Cross-Cutting Concerns

  • T008 Add error handling for JSON parse errors from OpenAI response in app/routes/personalize.py
  • T009 Verify all error responses match OpenAPI contract (400, 404, 503) in app/routes/personalize.py

Phase 6 Completion Criteria:

  • Invalid JSON from OpenAI returns appropriate error
  • User not found returns 404
  • OpenAI failure returns 503
  • Empty content returns 400
  • Content > 50K chars returns 400

Dependencies

Phase 2 (Foundational)
    β”‚
    β”œβ”€β”€ T001 (schemas) ──────────┐
    β”‚                            β”‚
    β”œβ”€β”€ T002 (openai service) ───┼──► T003 (route) ──► T005 (register router)
    β”‚                            β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                        β”‚
                                        β–Ό
                              Phase 3, 4, 5 (User Stories)
                              (can be verified independently)
                                        β”‚
                                        β–Ό
                              Phase 6 (Polish)

Story Dependencies:

  • US1, US2, US3 are all independent once Phase 2 completes
  • All stories use the same endpoint with different user profiles
  • No story blocks another

Parallel Execution Opportunities

Within Phase 2

T001 (schemas)        ─┐
                       β”œβ”€β”€β–Ί T003 (route) ──► T005 (main.py)
T002 (openai service) β”€β”˜

Across User Stories

Once T005 completes, all user stories can be verified in parallel:

  • US1: Test with beginner user
  • US2: Test with advanced user
  • US3: Test with intermediate user + hardware focus

Implementation Strategy

MVP Scope (Recommended First Pass)

Complete Phase 2 + Phase 3 (US1) only:

  • T001, T002, T003, T004, T005
  • 5 tasks for minimal working feature
  • Verifiable with single beginner user test

Full Implementation

All 9 tasks across all phases


Task Details

T001: Create Pydantic Schemas

File: app/schemas/personalize.py Requirements:

  • PersonalizeRequest with content (str, non-empty, ≀50K) and user_id (int, positive)
  • PersonalizeResponse with personalized_content (str) and adjustments_made (str)
  • Use field_validator for validation Reference: plan.md Section 1, data-model.md Schema Implementation

T002: Add OpenAI Personalization Method

File: app/services/openai_service.py Requirements:

  • Method: personalize_content(content, software_level, hardware_level, learning_goals) -> dict
  • System prompt with all PL-001 through PL-007 rules
  • Use GPT-4 with JSON response format
  • Return dict with personalized_content and adjustments_made Reference: plan.md Section 2

T003: Create Personalization Route

File: app/routes/personalize.py Requirements:

  • POST /api/personalize endpoint
  • Fetch user by user_id, return 404 if not found
  • Call OpenAIService.personalize_content with user profile
  • Return PersonalizeResponse
  • Handle OpenAI errors with 503 response Reference: plan.md Section 3

T004: Verify Beginner Logic

File: app/services/openai_service.py Requirements:

  • Confirm system prompt includes PL-001: "Add detailed explanations, use simpler terminology, break down complex concepts, provide examples"
  • Verify beginner-level content adaptation works correctly

T005: Register Router

File: app/main.py Requirements:

  • Import personalize router
  • Add app.include_router(personalize.router) Reference: plan.md Section 4

T006: Verify Advanced Logic

File: app/services/openai_service.py Requirements:

  • Confirm system prompt includes PL-003: "Add technical depth, skip basic explanations, use precise technical terminology"

T007: Verify Hardware Logic

File: app/services/openai_service.py Requirements:

  • Confirm system prompt includes PL-004/PL-005/PL-006 for hardware levels
  • Confirm PL-007 for learning_goals emphasis

T008: JSON Error Handling

File: app/routes/personalize.py Requirements:

  • Wrap JSON parsing in try/except
  • Return 500 error if OpenAI returns invalid JSON

T009: Verify Error Responses

File: app/routes/personalize.py Requirements:

  • Test empty content β†’ 400
  • Test content > 50K β†’ 400
  • Test invalid user_id β†’ 400
  • Test user not found β†’ 404
  • Test OpenAI failure β†’ 503

Files Modified

File Tasks Type
app/schemas/personalize.py T001 New
app/services/openai_service.py T002, T004, T006, T007 Modify
app/routes/personalize.py T003, T008, T009 New
app/main.py T005 Modify

Acceptance Checklist

  • POST /api/personalize returns 200 with valid response for beginner user
  • POST /api/personalize returns 200 with valid response for advanced user
  • POST /api/personalize returns 200 with valid response for intermediate user
  • Hardware content adapted based on hardware_level
  • learning_goals influence content emphasis
  • Empty content returns 400
  • Content > 50K returns 400
  • Invalid user_id returns 400
  • Non-existent user returns 404
  • OpenAI failure returns 503