40 lines
1.5 KiB
Python
40 lines
1.5 KiB
Python
"""독서토론 발언에서 주장을 추출한다."""
|
|
|
|
from models.context import AnalysisInput, DiscussionContext
|
|
from settings import settings
|
|
from utils.common_llm import StructuredLLM
|
|
|
|
SYSTEM_PROMPT = """너는 독서토론 기록에서 참여자의 주장을 추출한다.
|
|
|
|
- 화자가 실제로 내세운 주장만 뽑는다. 없는 주장을 추측해서 만들지 않는다.
|
|
- statement: 주장을 한 문장으로 정리한다.
|
|
- evidence: 화자가 그 주장을 뒷받침하려고 든 근거를 옮긴다. 근거를 대지 않았으면 빈 목록으로 둔다.
|
|
- speaker: 발언자 이름을 그대로 쓴다."""
|
|
|
|
claim_llm = StructuredLLM(settings.llm_model, settings.chatgpt_api_key)
|
|
|
|
|
|
def _render_input(analysis_input: AnalysisInput) -> str:
|
|
lines = [f"책: {analysis_input.book.title} ({analysis_input.book.author})"]
|
|
|
|
if analysis_input.excerpts:
|
|
lines.append("\n[원문 발췌]")
|
|
for excerpt in analysis_input.excerpts:
|
|
locator = f"({excerpt.locator}) " if excerpt.locator else ""
|
|
lines.append(f"{locator}{excerpt.text}")
|
|
|
|
if analysis_input.turns:
|
|
lines.append("\n[토론 발언]")
|
|
for turn in analysis_input.turns:
|
|
lines.append(f"{turn.speaker}: {turn.text}")
|
|
|
|
return "\n".join(lines)
|
|
|
|
|
|
async def extract_claims(analysis_input: AnalysisInput) -> DiscussionContext:
|
|
return await claim_llm.ask(
|
|
DiscussionContext,
|
|
_render_input(analysis_input),
|
|
system=SYSTEM_PROMPT,
|
|
)
|