|
|
|
|
|
|
|
|
from dataclasses import dataclass, field |
|
|
from typing import List, Optional |
|
|
from enum import Enum |
|
|
|
|
|
|
|
|
class PromptType(Enum): |
|
|
SYSTEM = "SYSTEM" |
|
|
USER = "USER" |
|
|
ASSISTANT = "ASSISTANT" |
|
|
|
|
|
|
|
|
@dataclass(frozen=True) |
|
|
class ContextualPrompt: |
|
|
"""Immutable prompt template with contextual awareness.""" |
|
|
role: str |
|
|
region: Optional[str] = None |
|
|
context_items: List[str] = field(default_factory=list) |
|
|
constraints: List[str] = field(default_factory=list) |
|
|
prompt_type: PromptType = PromptType.SYSTEM |
|
|
|
|
|
def build(self) -> str: |
|
|
"""Build the complete prompt string.""" |
|
|
parts = [f"You are a {self.role}"] |
|
|
|
|
|
if self.region: |
|
|
parts[0] += f" operating in {self.region}." |
|
|
else: |
|
|
parts[0] += "." |
|
|
|
|
|
if self.context_items: |
|
|
parts.append("\nCONTEXT:") |
|
|
for item in self.context_items: |
|
|
parts.append(f"- {item}") |
|
|
|
|
|
if self.constraints: |
|
|
parts.append("\nCONSTRAINTS:") |
|
|
for constraint in self.constraints: |
|
|
parts.append(f"- {constraint}") |
|
|
|
|
|
return "\n".join(parts) |
|
|
|
|
|
|
|
|
|
|
|
BAD_PROMPT = "You are a financial advisor. Give strict, rational advice." |
|
|
|
|
|
|
|
|
LAGOS_FINANCIAL_ADVISOR = ContextualPrompt( |
|
|
role="financial advisor", |
|
|
region="Lagos, Nigeria", |
|
|
context_items=[ |
|
|
"You understand the concept of 'Black Tax' and extended family support.", |
|
|
"You prioritize community reputation over ruthless individual efficiency.", |
|
|
"You speak in a respectful, empathetic tone." |
|
|
], |
|
|
constraints=[ |
|
|
"Do NOT suggest cutting off family members.", |
|
|
"DO suggest budgeting for family support as a fixed expense line item." |
|
|
] |
|
|
) |
|
|
|
|
|
|
|
|
CONTEXTUAL_PROMPT = LAGOS_FINANCIAL_ADVISOR.build() |
|
|
|