Files
personal-ai-assistant/backend/app/services/context_service.py
dolgolyov.alexei b0790d719c Generalize from health-specific to universal personal assistant
The app manages multiple life areas (health, finance, personal, work),
not just health. Updated all health-specific language throughout:

Backend:
- Default system prompt: general personal assistant (not health-only)
- AI tool descriptions: generic (not health records/medications)
- Memory categories: health, finance, personal, work, document_summary, other
  (replaces condition, medication, allergy, vital)
- PDF template: "Prepared for" (not "Patient"), "Key Information" (not "Health Profile")
- Renamed generate_health_pdf -> generate_pdf_report, health_report.html -> report.html
- Renamed run_daily_health_review -> run_daily_review
- Context assembly: "User Profile" (not "Health Profile")
- OpenAPI: generic descriptions

Frontend:
- Dashboard subtitle: "Your personal AI assistant"
- Memory categories: Health, Finance, Personal, Work
- Document types: Report, Contract, Receipt, Certificate (not lab_result, etc.)
- Updated en + ru translations throughout

Documentation:
- README: general personal assistant description
- Removed health-only feature descriptions

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-19 15:15:39 +03:00

73 lines
2.3 KiB
Python

import uuid
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from app.models.context_file import ContextFile
DEFAULT_SYSTEM_PROMPT = """You are a personal AI assistant helping users manage different areas of their life. Your role is to:
- Help users organize and understand their uploaded documents and data
- Provide recommendations and insights based on stored information
- Schedule reminders for important events, deadlines, and recurring activities
- Compile summaries and reports when requested
- Answer questions clearly and helpfully
Always be empathetic, accurate, and clear. When uncertain about specialized topics, recommend consulting a relevant professional.
You can communicate in English and Russian based on the user's preference."""
async def get_primary_context(db: AsyncSession) -> ContextFile | None:
result = await db.execute(
select(ContextFile).where(ContextFile.type == "primary", ContextFile.user_id.is_(None))
)
return result.scalar_one_or_none()
async def get_personal_context(db: AsyncSession, user_id: uuid.UUID) -> ContextFile | None:
result = await db.execute(
select(ContextFile).where(ContextFile.type == "personal", ContextFile.user_id == user_id)
)
return result.scalar_one_or_none()
async def upsert_personal_context(
db: AsyncSession, user_id: uuid.UUID, content: str
) -> ContextFile:
ctx = await get_personal_context(db, user_id)
if ctx:
ctx.content = content
ctx.version = ctx.version + 1
ctx.updated_by = user_id
else:
ctx = ContextFile(
type="personal",
user_id=user_id,
content=content,
version=1,
updated_by=user_id,
)
db.add(ctx)
await db.flush()
return ctx
async def upsert_primary_context(
db: AsyncSession, content: str, admin_user_id: uuid.UUID
) -> ContextFile:
ctx = await get_primary_context(db)
if ctx:
ctx.content = content
ctx.version = ctx.version + 1
ctx.updated_by = admin_user_id
else:
ctx = ContextFile(
type="primary",
user_id=None,
content=content,
version=1,
updated_by=admin_user_id,
)
db.add(ctx)
await db.flush()
return ctx