refactor: improve wiki page writer prompts

Apply llm-findings.md recommendations:

Conflict detection (temp 0.0):
- Add explicit analysis steps (CoT)
- Strict rules: only flag direct contradictions
- Negative constraints for false positives

Page creation (temp 0.3):
- Add CRITICAL CONSTRAINTS section
- "Do NOT invent facts not in source"
- "Do NOT fill sections with placeholders"
- Omit sections if information unavailable

Page reconstruction (temp 0.2):
- Add preservation constraints
- "Do NOT rephrase facts changing meaning"
- "Preserve exact quotes, dates, numbers verbatim"

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-23 17:21:58 +01:00
co-authored by Claude Opus 4.5
parent 8e003bb9e8
commit edfe11f0fb
+44 -20
View File
@@ -131,8 +131,8 @@ class WikiPageWriter:
conflicts=conflicts conflicts=conflicts
) )
# Reconstruct with LLM # Reconstruct with LLM (lower temperature for precise merging)
reconstructed = await self._call_llm(prompt) reconstructed = await self._call_llm(prompt, temperature=0.2)
# Ensure standard sections are present # Ensure standard sections are present
reconstructed = self._ensure_standard_sections( reconstructed = self._ensure_standard_sections(
@@ -155,7 +155,7 @@ class WikiPageWriter:
Returns: Returns:
List of conflicts with: {fact_a, fact_b, confidence, context} List of conflicts with: {fact_a, fact_b, confidence, context}
""" """
prompt = f"""Analyze these two pieces of content for factual conflicts. prompt = f"""Analyze these contents for direct factual conflicts.
EXISTING CONTENT: EXISTING CONTENT:
{existing_content[:2000]} {existing_content[:2000]}
@@ -163,25 +163,26 @@ EXISTING CONTENT:
NEW INFORMATION: NEW INFORMATION:
{new_information[:2000]} {new_information[:2000]}
Identify any facts that contradict each other. For each conflict, provide: ANALYSIS STEPS:
1. The fact from existing content 1. Identify specific factual claims in existing content (dates, numbers, names, states)
2. The contradicting fact from new information 2. Identify specific factual claims in new content
3. Confidence level (low/medium/high) 3. Compare ONLY for direct contradictions (X says A, Y says not-A)
4. Context/explanation
Return ONLY valid JSON: RULES:
- Do NOT flag differences in wording or phrasing as conflicts
- Do NOT flag new/additional information as conflicts
- Do NOT flag opinion differences as conflicts
- ONLY flag direct factual contradictions
- Return valid JSON only, no commentary
Return format:
{{ {{
"conflicts": [ "conflicts": [
{{ {{"existing_fact": "...", "new_fact": "...", "confidence": "low/medium/high", "context": "..."}}
"existing_fact": "fact from old content",
"new_fact": "contradicting fact",
"confidence": "medium",
"context": "explanation of why these conflict"
}}
] ]
}} }}
If no conflicts, return: {{"conflicts": []}} If no conflicts: {{"conflicts": []}}
JSON:""" JSON:"""
@@ -189,7 +190,8 @@ JSON:"""
response = await self.ollama.generate_text( response = await self.ollama.generate_text(
prompt=prompt, prompt=prompt,
model=self.model, model=self.model,
stream=False stream=False,
temperature=0.0 # Deterministic for consistent conflict detection
) )
# Extract JSON # Extract JSON
@@ -348,6 +350,13 @@ FORMATTING RULES:
- Keep sections focused and scannable - Keep sections focused and scannable
- Adapt structure to content - not all sections apply to all topics - Adapt structure to content - not all sections apply to all topics
CRITICAL CONSTRAINTS:
- Do NOT invent facts not present in the source information above
- Do NOT add speculative information or assumptions
- Do NOT fill sections with placeholder text or generic statements
- If information for a section is not available, OMIT the section entirely
- Base ALL content strictly on provided source information
Generate ONLY the markdown content (do not include Sources, Knowledge Graph, or Mind Map sections - those are added automatically). Generate ONLY the markdown content (do not include Sources, Knowledge Graph, or Mind Map sections - those are added automatically).
MARKDOWN:""" MARKDOWN:"""
@@ -403,6 +412,13 @@ FORMATTING RULES:
- Bold important terms - Bold important terms
- Add subsections (###) where it improves clarity - Add subsections (###) where it improves clarity
CRITICAL CONSTRAINTS:
- Do NOT rephrase facts in ways that change their meaning
- Do NOT remove ANY information unless explicitly superseded by newer facts
- Do NOT add information not present in existing content or new information
- Preserve exact quotes, dates, numbers, and names verbatim
- Do NOT fill gaps with assumptions or general knowledge
OUTPUT INSTRUCTIONS: OUTPUT INSTRUCTIONS:
- Return complete page content (do not include Sources, Knowledge Graph, Mind Map - those are added automatically) - Return complete page content (do not include Sources, Knowledge Graph, Mind Map - those are added automatically)
- Include updated "Changes & Updates" section noting what was changed today - Include updated "Changes & Updates" section noting what was changed today
@@ -410,13 +426,21 @@ OUTPUT INSTRUCTIONS:
RECONSTRUCTED MARKDOWN:""" RECONSTRUCTED MARKDOWN:"""
async def _call_llm(self, prompt: str) -> str: async def _call_llm(self, prompt: str, temperature: float = 0.3) -> str:
"""Call LLM with prompt and return response.""" """
Call LLM with prompt and return response.
Args:
prompt: The prompt text
temperature: Sampling temperature (0.0=deterministic, higher=creative)
Default 0.3 for controlled but natural content generation
"""
try: try:
response = await self.ollama.generate_text( response = await self.ollama.generate_text(
prompt=prompt, prompt=prompt,
model=self.model, model=self.model,
stream=False stream=False,
temperature=temperature
) )
if not response: if not response: