vasiuuu/DGX_AI
0
1from __future__ import annotations2 3from typing import TYPE_CHECKING4 5from codeforge.interrogator.models import InterrogationResult6 7if TYPE_CHECKING:8 from codeforge.kb.indexer import SkillsIndex9 10_TEMPLATES = (11 "What is the exact success criterion for '{brief_head}'?",12 "Have you considered the guidance from {skill_name}: '{section_title}'?",13 "Which of these assumptions is most load-bearing: success metric, inputs, failure modes?",14 "What is the single hardest edge case for '{brief_head}'?",15 "Have you consulted {skill_name2} for the patterns it recommends?",16)17 18 19class Interrogator:20 """Generates Socratic questions that cite real skill corpus nodes."""21 22 def __init__(self, index: SkillsIndex | None) -> None:23 self._index = index24 25 def generate(self, brief: str, *, top_k: int = 5) -> InterrogationResult:26 brief_head = brief.strip()[:80] or "the task"27 results = (28 self._index.search(brief, top_k=top_k)29 if self._index is not None30 else []31 )32 cited_ids = tuple(r.node_id for r in results[:2])33 first = results[0] if results else None34 second = results[1] if len(results) > 1 else first35 36 skill_name = first.skill_name if first else "the skill library"37 section_title = (38 "/".join(first.section_path) if first else "the relevant section"39 )40 skill_name2 = second.skill_name if second else skill_name41 42 questions = tuple(43 t.format(44 brief_head=brief_head,45 skill_name=skill_name,46 section_title=section_title,47 skill_name2=skill_name2,48 )49 for t in _TEMPLATES50 )51 return InterrogationResult(questions=questions, cited_node_ids=cited_ids)52 