"""토론에서 나온 주장과 페르소나로 다음 발화의 가이드를 만든다.""" from models.context import AnalysisInput from models.utterance_guide import UtteranceGuide, UtteranceGuideInput from services.claim_extraction import extract_claims from settings import settings from utils.common_llm import StructuredLLM SYSTEM_PROMPT = """너는 독서토론에 참여하는 AI의 다음 발화를 설계한다. 주어진 페르소나로 토론에 참여한다고 보고, 발화문은 쓰지 말고 어떻게 발화할지만 정한다. - target_claim: 반응할 주장 하나를 고르고 한 문장으로 옮긴다. - intent: 그 주장에 대해 무엇을 할지 쓴다. 동의, 반박, 질문, 확장 등. - key_message: 핵심으로 전할 내용을 한 문장으로 쓴다. - tone: 페르소나의 성격과 말투에 맞는 태도를 쓴다.""" guide_llm = StructuredLLM(settings.llm_model, settings.chatgpt_api_key) def _render_input(guide_input: UtteranceGuideInput) -> str: persona = guide_input.persona lines = [ f"책: {guide_input.book.title} ({guide_input.book.author})", "\n[페르소나]", f"이름: {persona.name}", f"성격: {persona.personality}", f"말투: {persona.speaking_style}", f"관점: {persona.perspective}", ] if guide_input.claims: lines.append("\n[토론에서 나온 주장]") for claim in guide_input.claims: lines.append(f"{claim.speaker}: {claim.statement}") for evidence in claim.evidence: lines.append(f" 근거: {evidence}") return "\n".join(lines) async def build_utterance_guide(guide_input: UtteranceGuideInput) -> UtteranceGuide: return await guide_llm.ask( UtteranceGuide, _render_input(guide_input), system=SYSTEM_PROMPT, ) async def generate_style_guide(analysis_input: AnalysisInput) -> UtteranceGuide: """지식 기반 스타일 가이드를 생성한다.""" discussion = await extract_claims(analysis_input) return await build_utterance_guide( UtteranceGuideInput( book=analysis_input.book, persona=analysis_input.persona, claims=discussion.claims, ) )