AI Configuration
YapHub's AI behaviour is driven by a focused, hardcoded prompt optimised for generating concise Dutch-language summaries. Unlike the original plan for a full prompt template management system, the MVP uses a single proven prompt constant.
Current Implementation
The AI prompt is defined as a PHP constant in DigestConstants::HIGHLIGHT_SUMMARY_PROMPT:
Summarize the following content in 2-3 sentences (in Dutch).
If it's a link or short title, infer its context from the extracted text:
Title/Input: %s
URL: %s
Content:
%sThree variables are injected via sprintf:
| Position | Variable | Source |
|---|---|---|
%s (1) | Title | Knowledge.title |
%s (2) | URL | Knowledge.url |
%s (3) | Content | Knowledge.content (user text + extracted URL content) |
Generation Parameters
| Parameter | Value | Purpose |
|---|---|---|
| Temperature | 0.3 | Factual, consistent output |
| Max Tokens | 150 | Keeps summaries to 2-3 sentences |
| Language | Dutch | Implicit in the prompt instruction |
| Fallback | Truncate to 200 chars | Graceful degradation on AI failure |
Why a Hardcoded Prompt
During development, the prompt was iterated on until it produced reliable Dutch summaries. Since the system only generates one type of summary (a concise highlight), a single well-tuned prompt is simpler and more maintainable than a database-backed template system.
Benefits of this approach:
- Zero configuration — no admin UI needed, works out of the box
- Deterministic — same input always produces the same prompt
- Easy to test — mock mode returns predictable results
- No database dependency — the prompt doesn't require additional tables
Future Enhancements
The following improvements could be made post-MVP:
- Configurable prompts — Move the prompt to a config file or environment variable for easy tweaking without code changes
- Per-category prompts — Different categories could have specialised prompts (e.g., more technical for "DevOps" categories)
- A/B testing — Compare prompt variations to optimise summary quality
- Prompt template entity — Database-backed templates with versioning if the system needs to support multiple prompt types
The AiProviderInterface abstraction is already in place, so adding these features would require minimal architectural changes.
Generation flow
- During digest creation,
KnowledgeHighlightGenerator::generateHighlight()checks if a knowledge item already has ahighlightfield (lazy — skip if present) - If not, builds the prompt using
sprintf(HIGHLIGHT_SUMMARY_PROMPT, title, url, content) - Calls
AiProviderInterface::generateCompletion(prompt, options) - Stores the result in
Knowledge.highlight(TEXT field) - On failure, falls back to truncating the content to 200 characters
Storage
AI summaries are stored in two locations:
Knowledge.highlight— Primary TEXT field on the knowledge entityDigest.knowledgeHighlights— JSON snapshot at digest generation time (immutable digest record)