Ver3.0 ๐ Claude๋ก ๊ณ์ฝ์ ์ฃผ์ ์กฐํญ ์๋์ถ์ถ ๋ด ๊ตฌ์ถํ๊ธฐ

๐ Claude๋ก ๊ณ์ฝ์ ์ฃผ์ ์กฐํญ ์๋์ถ์ถ ๋ด ๊ตฌ์ถํ๊ธฐ
AI๊ฐ ๊ณ์ฝ์๋ฅผ ์ฝ๊ณ ํต์ฌ๋ง ์์ ๋ฝ์๋ด๋ ๋ง๋ฒ ๊ฐ์ ์๋ํ ์์คํ ๋ง๋ค๊ธฐ ๐คโจ
๐ฏ ์ ๊ณ์ฝ์ ์๋์ถ์ถ ๋ด์ด ํ์ํ ๊น?
๋งค์ผ ์์ญ, ์๋ฐฑ ์ฅ์ ๊ณ์ฝ์๋ฅผ ๊ฒํ ํด์ผ ํ๋ ๋ฒ๋ฌดํ, ๊ตฌ๋งคํ, ์์
ํ์ ๊ณ ์ถฉ์ ์๊ฐํด๋ด. ๐
๊ฐ ๊ณ์ฝ์๋ง๋ค ์ค์ํ ์กฐํญ๋ค์ด ์ด๋์ ์จ์ด์๋์ง ์ฐพ์๋ด๋ ค๋ฉด ํ ์ฅ๋น ์ต์ 30๋ถ์์ 1์๊ฐ์ ์กฑํ ๊ฑธ๋ ค.
๊ฒ๋ค๊ฐ ์ฌ๋์ด ํ๋ค ๋ณด๋ฉด ์ค์๋ ์๊ธฐ๊ณ , ์ค์ํ ์กฐํญ์ ๋์น๋ ๊ฒฝ์ฐ๋ ์์ง.
์ด๋ฐ ๋ฐ๋ณต์ ์ด๊ณ ์ง๋ฃจํ ์์
์ AI์๊ฒ ๋งก๊ธฐ๋ฉด ์ด๋จ๊น? ๐ค
๋ฐ๋ก ์ฌ๊ธฐ์ Claude ๊ฐ์ ๋ํ ์ธ์ด๋ชจ๋ธ(LLM)์ด ๋น์ ๋ฐํ๋ ๊ฑฐ์ผ.
Claude๋ ๊ธด ๋ฌธ์๋ฅผ ์ดํดํ๊ณ , ๋งฅ๋ฝ์ ํ์
ํ๊ณ , ํต์ฌ ์ ๋ณด๋ฅผ ์ถ์ถํ๋ ๋ฐ ์ ๋ง ํ์ํ ๋ฅ๋ ฅ์ ๊ฐ์ง๊ณ ์๊ฑฐ๋ .
โข ์คํํธ์ : ํฌ์ ๊ณ์ฝ์ ๋ฆฌ๋ทฐ ํ๋ก์ธ์ค๋ฅผ 3์ผ์์ 4์๊ฐ์ผ๋ก ์์ถ
โข ๊ตฌ๋งค๋ถ์: ๊ณต๊ธ์ ์ฒด ๊ณ์ฝ ์กฐ๊ฑด ๋น๊ต ๋ถ์ ์๋ํ๋ก ํ์๋ ฅ 30% ํฅ์
โข ๋ถ๋์ฐ ์ค๊ฐ: ์๋์ฐจ ๊ณ์ฝ์ ํต์ฌ ์กฐํญ ์ฆ์ ์ถ์ถ๋ก ๊ณ ๊ฐ ๋ง์กฑ๋ ์์น
๐ง Claude๊ฐ ๊ณ์ฝ์ ๋ถ์์ ์ต์ ์ธ ์ด์
์ฌ๋ฌ AI ๋ชจ๋ธ ์ค์์๋ Claude๋ฅผ ์ ํํ๋ ๋ฐ๋ ๋ช
ํํ ์ด์ ๊ฐ ์์ด.
ํนํ Anthropic์ Claude 3 ์๋ฆฌ์ฆ(Haiku, Sonnet, Opus)๋ ๊ณ์ฝ์ ๊ฐ์ ๋ฒ๋ฅ ๋ฌธ์ ์ฒ๋ฆฌ์ ๊ฐ์ ์ ๋ณด์ฌ์ฃผ๊ฑฐ๋ . ๐ช
1๏ธโฃ ๊ธด ์ปจํ ์คํธ ์๋์ฐ (์ต๋ 200K ํ ํฐ)
์ผ๋ฐ์ ์ธ ๊ณ์ฝ์๋ ๋ณดํต 10~50ํ์ด์ง ์ ๋์ธ๋ฐ, Claude๋ ํ ๋ฒ์ ์๋ฐฑ ํ์ด์ง๋ฅผ ์ฒ๋ฆฌํ ์ ์์ด.
์ด๊ฒ ์ผ๋ง๋ ์ค์ํ์ง ์์? ๋ฌธ์๋ฅผ ์ชผ๊ฐ์ง ์๊ณ ์ ์ฒด ๋งฅ๋ฝ์ ์ ์งํ๋ฉด์ ๋ถ์ํ ์ ์๋ค๋ ๊ฑฐ์ผ. ๐
2๏ธโฃ ๋ฐ์ด๋ ์ง์์ฌํญ ์ค์ ๋ฅ๋ ฅ
"์ด ๊ณ์ฝ์์์ ๊ธ์ก, ๊ธฐ๊ฐ, ์์ฝ ์กฐ๊ฑด๋ง ์ถ์ถํด์ค"๋ผ๊ณ ํ๋ฉด ์ ๋ง ๊ทธ๊ฒ๋ง ๊น๋ํ๊ฒ ๋ฝ์๋ด.
๋ค๋ฅธ ๋ชจ๋ธ๋ค์ ๊ฐ๋ ์๋ฑํ ์ ๋ณด๊น์ง ์์ด์ ์ฃผ๋ ๊ฒฝ์ฐ๊ฐ ์๋๋ฐ, Claude๋ ์ง์๋ฅผ ์ ํํ ๋ฐ๋ผ. ๐ฏ
3๏ธโฃ ๊ตฌ์กฐํ๋ ์ถ๋ ฅ ์์ฑ
JSON, XML, ํ ํ์ ๋ฑ ์ํ๋ ํฌ๋งท์ผ๋ก ๊ฒฐ๊ณผ๋ฅผ ๋ฐ์ ์ ์์ด.
์ด๊ฑด ๋์ค์ ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ์ ์ฅํ๊ฑฐ๋ ๋ค๋ฅธ ์์คํ ๊ณผ ์ฐ๋ํ ๋ ์์ฒญ ํธํด. ๐ง
4๏ธโฃ ๋ฒ๋ฅ ์ฉ์ด ์ดํด๋
"์ ์ดํ์๋ฌด", "์ํด๋ฐฐ์์์ ์ก", "๋ถ๊ฐํญ๋ ฅ ์กฐํญ" ๊ฐ์ ์ ๋ฌธ ์ฉ์ด๋ค์ ์ ํํ ์ดํดํ๊ณ ์ฒ๋ฆฌํด.
์ผ๋ฐ AI๋ ์ด๋ฐ ์ฉ์ด๋ฅผ ๊ทธ๋ฅ ๋จ์ด๋ก๋ง ์ธ์ํ์ง๋ง, Claude๋ ๋ฒ์ ์๋ฏธ๊น์ง ํ์ ํ๊ฑฐ๋ . โ๏ธ
ํนํ ํ๋กฌํํธ ์์ง๋์ด๋ง์ด๋ API ์ฐ๋ ๋ถ๋ถ์์ ์ ๋ฌธ๊ฐ์ ์กฐ์ธ์ด ํฐ ๋์์ด ๋ ์ ์์ด! ๐
๐๏ธ ์์คํ ์ํคํ ์ฒ ์ค๊ณํ๊ธฐ
๋ณธ๊ฒฉ์ ์ผ๋ก ๋ด์ ๋ง๋ค๊ธฐ ์ ์, ์ ์ฒด ์์คํ
์ด ์ด๋ป๊ฒ ๋์ํ ์ง ์ค๊ณ๋ถํฐ ํด์ผ ํด.
๊ฑด๋ฌผ์ ์ง์ ๋ ์ค๊ณ๋๊ฐ ํ์ํ๋ฏ์ด, ์ํํธ์จ์ด๋ ๋ง์ฐฌ๊ฐ์ง์ผ. ๐๏ธ
Step 1: ๋ฌธ์ ์ ๋ ฅ ๐ฅ
์ฌ์ฉ์๊ฐ ๊ณ์ฝ์ ํ์ผ์ ์ ๋ก๋ํ๋ ๋จ๊ณ์ผ. PDF, DOCX, ์ด๋ฏธ์ง ํ์ผ ๋ฑ ๋ค์ํ ํ์์ ์ง์ํด์ผ ํด.
ํ์ผ ํฌ๊ธฐ ์ ํ(๋ณดํต 10MB ์ดํ)๊ณผ ๋ณด์ ๊ฒ์ฆ๋ ์ด ๋จ๊ณ์์ ์ฒ๋ฆฌํ์ง.
Step 2: ํ ์คํธ ์ถ์ถ ๐
PDF์์ ํ ์คํธ๋ฅผ ๋ฝ์๋ด๋ ์์ ์ด์ผ. ์ค์บ๋ ๋ฌธ์๋ผ๋ฉด OCR(๊ดํ ๋ฌธ์ ์ธ์)์ด ํ์ํด.
PyPDF2๋ ๋์งํธ PDF์ฉ, Tesseract๋ ์ด๋ฏธ์ง/์ค์บ ๋ฌธ์์ฉ์ผ๋ก ์ฌ์ฉํด.
Step 3: ์ ์ฒ๋ฆฌ ๐งน
์ถ์ถ๋ ํ ์คํธ๋ฅผ ์ ์ ํ๋ ๋จ๊ณ์ผ. ๋ถํ์ํ ๊ณต๋ฐฑ ์ ๊ฑฐ, ํน์๋ฌธ์ ์ฒ๋ฆฌ, ํ์ด์ง ๋ฒํธ ์ ๊ฑฐ ๋ฑ์ ํด.
๋ฌธ์๊ฐ ๋๋ฌด ๊ธธ๋ฉด Claude์ ํ ํฐ ์ ํ์ ๊ณ ๋ คํด์ ์ ์ ํ ๋ถํ ํ๊ธฐ๋ ํด.
Step 4: Claude API ํธ์ถ ๐ค
์ ์ฒ๋ฆฌ๋ ํ ์คํธ์ ํจ๊ป ํ๋กฌํํธ๋ฅผ Claude์๊ฒ ๋ณด๋ด๋ ๋จ๊ณ์ผ.
์ฌ๊ธฐ์ ํ๋กฌํํธ ์ค๊ณ๊ฐ ์ ๋ง ์ค์ํ๋ฐ, ์ด๊ฑด ๋ค์์ ์์ธํ ๋ค๋ฃฐ๊ฒ!
Step 5: ์กฐํญ ์ถ์ถ ๋ฐ ๊ตฌ์กฐํ ๐
Claude๊ฐ ๋ฐํํ ๊ฒฐ๊ณผ๋ฅผ ํ์ฑํด์ ๊ตฌ์กฐํ๋ ๋ฐ์ดํฐ๋ก ๋ง๋ค์ด.
JSON ํ์์ผ๋ก ๋ฐ์ผ๋ฉด ํ์ด์ฌ ๋์ ๋๋ฆฌ๋ก ์ฝ๊ฒ ๋ณํํ ์ ์์ง.
Step 6: ํ์ฒ๋ฆฌ ๋ฐ ๊ฒ์ฆ โ
์ถ์ถ๋ ๋ฐ์ดํฐ์ ์ ํจ์ฑ์ ๊ฒ์ฆํด. ๋ ์ง ํ์์ด ๋ง๋์ง, ๊ธ์ก์ ์ด์ํ ๊ฐ์ ์๋์ง ์ฒดํฌํ๋ ๊ฑฐ์ผ.
ํ์ํ๋ฉด ์ถ๊ฐ ํฌ๋งทํ ๋ ํ๊ณ .
Step 7: ๊ฒฐ๊ณผ ์ ์ฅ ๐พ
์ฒ๋ฆฌ๋ ๋ฐ์ดํฐ๋ฅผ ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ์ ์ฅํ๊ฑฐ๋ ํ์ผ๋ก ๋ด๋ณด๋ด.
๋์ค์ ๊ฒ์ํ๊ฑฐ๋ ๋ถ์ํ ์ ์๋๋ก ์ธ๋ฑ์ฑ๋ ํด์ฃผ๋ฉด ์ข์.
Step 8: ์ฌ์ฉ์์๊ฒ ์ถ๋ ฅ ๐ฑ
์น ๋์๋ณด๋๋ ์ด๋ฉ์ผ, ์ฌ๋ ๋ฉ์์ง ๋ฑ์ผ๋ก ๊ฒฐ๊ณผ๋ฅผ ์ ๋ฌํด.
์๊ฐํ๋ ํํ๋ก ๋ณด์ฌ์ฃผ๋ฉด ์ฌ์ฉ์ ๊ฒฝํ์ด ํจ์ฌ ์ข์์ ธ.
๐ป ๊ฐ๋ฐ ํ๊ฒฝ ์ธํ ํ๊ธฐ
์ด์ ์ค์ ๋ก ์ฝ๋๋ฅผ ์์ฑํ ์ค๋น๋ฅผ ํด๋ณด์! ๐ ๏ธ
ํ์ํ ๋๊ตฌ๋ค์ ์ค์นํ๊ณ ๊ฐ๋ฐ ํ๊ฒฝ์ ๊ตฌ์ถํ๋ ๊ณผ์ ์ด์ผ.
1. Python 3.8 ์ด์
์ต์ ๋ฒ์ ์ ํ์ด์ฌ์ ์ฌ์ฉํ๋ ๊ฒ ์ข์. 3.10์ด๋ 3.11์ ์ถ์ฒํด.
2. Anthropic Python SDK
Claude API๋ฅผ ์ฝ๊ฒ ์ฌ์ฉํ ์ ์๊ฒ ํด์ฃผ๋ ๊ณต์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ผ.
3. ๋ฌธ์ ์ฒ๋ฆฌ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
โข PyPDF2 ๋๋ pdfplumber: PDF ํ ์คํธ ์ถ์ถ
โข python-docx: Word ๋ฌธ์ ์ฒ๋ฆฌ
โข pytesseract: OCR ๊ธฐ๋ฅ (์ด๋ฏธ์ง์์ ํ ์คํธ ์ถ์ถ)
โข Pillow: ์ด๋ฏธ์ง ์ฒ๋ฆฌ
4. ์น ํ๋ ์์ํฌ (์ ํ)
โข FastAPI: ๋น ๋ฅด๊ณ ํ๋์ ์ธ API ์๋ฒ
โข Flask: ๊ฐ๋ณ๊ณ ๊ฐ๋จํ ์น ํ๋ ์์ํฌ
5. ๋ฐ์ดํฐ๋ฒ ์ด์ค (์ ํ)
โข PostgreSQL + psycopg2: ๊ด๊ณํ DB
โข MongoDB + pymongo: NoSQL DB
โข SQLite: ๊ฐ๋จํ ํ๋กํ ํ์ ์ฉ
# ๊ฐ์ํ๊ฒฝ ์์ฑ ๋ฐ ํ์ฑํ
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
# ํ์ ํจํค์ง ์ค์น
pip install anthropic
pip install PyPDF2 pdfplumber
pip install python-docx
pip install pytesseract pillow
pip install fastapi uvicorn
pip install python-multipart # ํ์ผ ์
๋ก๋์ฉ
pip install pydantic # ๋ฐ์ดํฐ ๊ฒ์ฆ์ฉ
# ์ ํ์ ํจํค์ง
pip install sqlalchemy psycopg2-binary
pip install python-dotenv # ํ๊ฒฝ๋ณ์ ๊ด๋ฆฌ
pytesseract๋ ํ์ด์ฌ ๋ํผ์ผ ๋ฟ์ด๊ณ , ์ค์ Tesseract ์์ง์ ๋ณ๋๋ก ์ค์นํด์ผ ํด.
โข Windows: https://github.com/UB-Mannheim/tesseract/wiki ์์ ์ค์น ํ์ผ ๋ค์ด๋ก๋
โข Mac: brew install tesseract
โข Linux: sudo apt-get install tesseract-ocr
API ํค ๊ด๋ฆฌ:
Claude API ํค๋ ์ ๋ ์ฝ๋์ ์ง์ ๋ฃ์ง ๋ง๊ณ , ํ๊ฒฝ๋ณ์๋ .env ํ์ผ๋ก ๊ด๋ฆฌํด์ผ ํด!
๊นํ๋ธ์ ์ฌ๋ฆด ๋ ์ค์๋ก ํค๊ฐ ๋ ธ์ถ๋๋ฉด ํฐ์ผ๋๊ฑฐ๋ . ๐
# .env ํ์ผ ์์ฑ
ANTHROPIC_API_KEY=your_api_key_here
MAX_FILE_SIZE=10485760 # 10MB
ALLOWED_EXTENSIONS=pdf,docx,doc
DATABASE_URL=postgresql://user:password@localhost/contracts
๐ ํต์ฌ ์ฝ๋ ๊ตฌํํ๊ธฐ
๋๋์ด ๋ณธ๊ฒฉ์ ์ธ ์ฝ๋ฉ ์๊ฐ์ด์ผ! ๐
๊ฐ ๊ธฐ๋ฅ๋ณ๋ก ๋ชจ๋ํํด์ ๊ตฌํํ๋ฉด ๋์ค์ ์ ์ง๋ณด์ํ๊ธฐ๋ ํธํ๊ณ , ์ฌ์ฌ์ฉ์ฑ๋ ๋์์ ธ.
import PyPDF2
import docx
from PIL import Image
import pytesseract
from typing import Optional
import logging
logger = logging.getLogger(__name__)
class DocumentParser:
"""๋ค์ํ ํ์์ ๋ฌธ์์์ ํ
์คํธ๋ฅผ ์ถ์ถํ๋ ํด๋์ค"""
def __init__(self):
self.supported_formats = ['pdf', 'docx', 'doc', 'png', 'jpg', 'jpeg']
def extract_text(self, file_path: str) -> Optional[str]:
"""
ํ์ผ ๊ฒฝ๋ก๋ฅผ ๋ฐ์์ ํ
์คํธ๋ฅผ ์ถ์ถ
Args:
file_path: ๋ฌธ์ ํ์ผ ๊ฒฝ๋ก
Returns:
์ถ์ถ๋ ํ
์คํธ ๋๋ None
"""
file_extension = file_path.split('.')[-1].lower()
try:
if file_extension == 'pdf':
return self._extract_from_pdf(file_path)
elif file_extension in ['docx', 'doc']:
return self._extract_from_docx(file_path)
elif file_extension in ['png', 'jpg', 'jpeg']:
return self._extract_from_image(file_path)
else:
logger.error(f"์ง์ํ์ง ์๋ ํ์ผ ํ์: {file_extension}")
return None
except Exception as e:
logger.error(f"ํ
์คํธ ์ถ์ถ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}")
return None
def _extract_from_pdf(self, file_path: str) -> str:
"""PDF ํ์ผ์์ ํ
์คํธ ์ถ์ถ"""
text = ""
with open(file_path, 'rb') as file:
pdf_reader = PyPDF2.PdfReader(file)
for page_num in range(len(pdf_reader.pages)):
page = pdf_reader.pages[page_num]
text += page.extract_text()
# ํ
์คํธ๊ฐ ๊ฑฐ์ ์์ผ๋ฉด ์ค์บ๋ PDF์ผ ๊ฐ๋ฅ์ฑ
if len(text.strip()) < 100:
logger.warning("PDF์์ ํ
์คํธ๊ฐ ๊ฑฐ์ ์ถ์ถ๋์ง ์์. OCR ์๋...")
return self._ocr_pdf(file_path)
return text
def _extract_from_docx(self, file_path: str) -> str:
"""DOCX ํ์ผ์์ ํ
์คํธ ์ถ์ถ"""
doc = docx.Document(file_path)
text = ""
for paragraph in doc.paragraphs:
text += paragraph.text + "\n"
# ํ ๋ด์ฉ๋ ์ถ์ถ
for table in doc.tables:
for row in table.rows:
for cell in row.cells:
text += cell.text + "\t"
text += "\n"
return text
def _extract_from_image(self, file_path: str) -> str:
"""์ด๋ฏธ์ง ํ์ผ์์ OCR๋ก ํ
์คํธ ์ถ์ถ"""
image = Image.open(file_path)
text = pytesseract.image_to_string(image, lang='kor+eng')
return text
def _ocr_pdf(self, file_path: str) -> str:
"""์ค์บ๋ PDF๋ฅผ ์ด๋ฏธ์ง๋ก ๋ณํ ํ OCR"""
# pdf2image ๋ผ์ด๋ธ๋ฌ๋ฆฌ ํ์
from pdf2image import convert_from_path
images = convert_from_path(file_path)
text = ""
for image in images:
text += pytesseract.image_to_string(image, lang='kor+eng')
return text
def preprocess_text(self, text: str) -> str:
"""์ถ์ถ๋ ํ
์คํธ ์ ์ฒ๋ฆฌ"""
# ์ฐ์๋ ๊ณต๋ฐฑ ์ ๊ฑฐ
text = ' '.join(text.split())
# ํ์ด์ง ๋ฒํธ ํจํด ์ ๊ฑฐ (์: "- 1 -", "Page 1")
import re
text = re.sub(r'-\s*\d+\s*-', '', text)
text = re.sub(r'Page\s+\d+', '', text, flags=re.IGNORECASE)
# ํน์๋ฌธ์ ์ ๋ฆฌ (ํ์ํ ๊ฒฝ์ฐ)
# text = re.sub(r'[^\w\s๊ฐ-ํฃ.,;:()\[\]{}]', '', text)
return text.strip()
import anthropic
import json
from typing import Dict, List, Optional
import os
from dotenv import load_dotenv
load_dotenv()
class ClaudeContractAnalyzer:
"""Claude API๋ฅผ ์ฌ์ฉํ ๊ณ์ฝ์ ๋ถ์ ํด๋์ค"""
def __init__(self, api_key: Optional[str] = None):
self.api_key = api_key or os.getenv('ANTHROPIC_API_KEY')
self.client = anthropic.Anthropic(api_key=self.api_key)
self.model = "claude-3-sonnet-20240229" # ๋๋ claude-3-opus
def extract_contract_clauses(self, contract_text: str) -> Dict:
"""
๊ณ์ฝ์ ํ
์คํธ์์ ์ฃผ์ ์กฐํญ ์ถ์ถ
Args:
contract_text: ๊ณ์ฝ์ ์ ๋ฌธ
Returns:
์ถ์ถ๋ ์กฐํญ๋ค์ ๋ด์ ๋์
๋๋ฆฌ
"""
prompt = self._build_extraction_prompt(contract_text)
try:
message = self.client.messages.create(
model=self.model,
max_tokens=4096,
temperature=0, # ์ผ๊ด์ฑ์ ์ํด 0์ผ๋ก ์ค์
messages=[
{"role": "user", "content": prompt}
]
)
# ์๋ต์์ ํ
์คํธ ์ถ์ถ
response_text = message.content[0].text
# JSON ํ์ฑ
result = self._parse_response(response_text)
return result
except Exception as e:
print(f"Claude API ํธ์ถ ์ค ์ค๋ฅ: {str(e)}")
return {}
def _build_extraction_prompt(self, contract_text: str) -> str:
"""๊ณ์ฝ์ ๋ถ์์ ์ํ ํ๋กฌํํธ ์์ฑ"""
prompt = f"""๋น์ ์ ๋ฒ๋ฅ ๋ฌธ์ ๋ถ์ ์ ๋ฌธ๊ฐ์
๋๋ค.
๋ค์ ๊ณ์ฝ์์์ ์ฃผ์ ์กฐํญ๋ค์ ์ถ์ถํ์ฌ ๊ตฌ์กฐํ๋ JSON ํ์์ผ๋ก ๋ฐํํด์ฃผ์ธ์.
์ถ์ถํด์ผ ํ ํญ๋ชฉ:
1. ๊ณ์ฝ ๋น์ฌ์ (parties): ๊ฐ, ์ ๋ฑ์ ๋น์ฌ์ ์ ๋ณด
2. ๊ณ์ฝ ๋ชฉ์ (purpose): ๊ณ์ฝ์ ์ฃผ์ ๋ชฉ์
3. ๊ณ์ฝ ๊ธฐ๊ฐ (duration): ์์์ผ, ์ข
๋ฃ์ผ, ๊ธฐ๊ฐ
4. ๊ณ์ฝ ๊ธ์ก (amount): ๊ณ์ฝ๊ธ, ์ค๋๊ธ, ์๊ธ ๋ฑ
5. ์ง๊ธ ์กฐ๊ฑด (payment_terms): ์ง๊ธ ๋ฐฉ๋ฒ, ์๊ธฐ
6. ์๋ฌด์ฌํญ (obligations): ๊ฐ ๋น์ฌ์์ ์ฃผ์ ์๋ฌด
7. ์์ฝ ์กฐ๊ฑด (penalty_clauses): ์์ฝ๊ธ, ์ํด๋ฐฐ์ ์กฐ๊ฑด
8. ํด์ง ์กฐ๊ฑด (termination_clauses): ๊ณ์ฝ ํด์ง ์ฌ์ ๋ฐ ์ ์ฐจ
9. ๋ถ์ ํด๊ฒฐ (dispute_resolution): ๊ดํ ๋ฒ์, ์ค์ฌ ์กฐํญ
10. ํน์ฝ ์ฌํญ (special_provisions): ๊ธฐํ ํน๋ณํ ์ฝ์
๊ณ์ฝ์ ๋ด์ฉ:
{contract_text}
์๋ต ํ์ (๋ฐ๋์ ์ ํจํ JSON์ผ๋ก ๋ฐํ):
{{
"parties": {{
"party_a": "๊ฐ ๋น์ฌ์ ์ ๋ณด",
"party_b": "์ ๋น์ฌ์ ์ ๋ณด"
}},
"purpose": "๊ณ์ฝ ๋ชฉ์ ",
"duration": {{
"start_date": "YYYY-MM-DD",
"end_date": "YYYY-MM-DD",
"period": "๊ธฐ๊ฐ ์ค๋ช
"
}},
"amount": {{
"total": "์ด ๊ธ์ก",
"breakdown": ["๊ณ์ฝ๊ธ", "์ค๋๊ธ", "์๊ธ"]
}},
"payment_terms": "์ง๊ธ ์กฐ๊ฑด ์ค๋ช
",
"obligations": {{
"party_a": ["์๋ฌด1", "์๋ฌด2"],
"party_b": ["์๋ฌด1", "์๋ฌด2"]
}},
"penalty_clauses": "์์ฝ ์กฐ๊ฑด ์ค๋ช
",
"termination_clauses": "ํด์ง ์กฐ๊ฑด ์ค๋ช
",
"dispute_resolution": "๋ถ์ ํด๊ฒฐ ๋ฐฉ๋ฒ",
"special_provisions": ["ํน์ฝ1", "ํน์ฝ2"]
}}
์ฃผ์์ฌํญ:
- ๊ณ์ฝ์์ ๋ช
์๋์ง ์์ ๋ด์ฉ์ "๋ช
์๋์ง ์์"์ผ๋ก ํ์
- ๋ ์ง๋ YYYY-MM-DD ํ์์ผ๋ก ํต์ผ
- ๊ธ์ก์ ์ซ์์ ๋จ์๋ฅผ ๋ช
ํํ ํ์
- ๋ชจํธํ ํํ์ ์๋ฌธ ๊ทธ๋๋ก ์ธ์ฉ"""
return prompt
def _parse_response(self, response_text: str) -> Dict:
"""Claude ์๋ต์ ํ์ฑํ์ฌ ๋์
๋๋ฆฌ๋ก ๋ณํ"""
try:
# JSON ๋ถ๋ถ๋ง ์ถ์ถ (๋งํฌ๋ค์ด ์ฝ๋ ๋ธ๋ก ์ ๊ฑฐ)
if "```json" in response_text:
json_start = response_text.find("```json") + 7
json_end = response_text.find("```", json_start)
json_text = response_text[json_start:json_end].strip()
elif "```" in response_text:
json_start = response_text.find("```") + 3
json_end = response_text.find("```", json_start)
json_text = response_text[json_start:json_end].strip()
else:
json_text = response_text.strip()
# JSON ํ์ฑ
result = json.loads(json_text)
return result
except json.JSONDecodeError as e:
print(f"JSON ํ์ฑ ์ค๋ฅ: {str(e)}")
print(f"์๋ต ํ
์คํธ: {response_text[:500]}...")
return {"error": "JSON ํ์ฑ ์คํจ", "raw_response": response_text}
def validate_extraction(self, extracted_data: Dict) -> Dict:
"""์ถ์ถ๋ ๋ฐ์ดํฐ์ ์ ํจ์ฑ ๊ฒ์ฆ"""
validation_result = {
"is_valid": True,
"warnings": [],
"errors": []
}
# ํ์ ํ๋ ์ฒดํฌ
required_fields = ["parties", "purpose", "duration"]
for field in required_fields:
if field not in extracted_data or not extracted_data[field]:
validation_result["errors"].append(f"ํ์ ํ๋ ๋๋ฝ: {field}")
validation_result["is_valid"] = False
# ๋ ์ง ํ์ ๊ฒ์ฆ
if "duration" in extracted_data:
duration = extracted_data["duration"]
if isinstance(duration, dict):
for date_field in ["start_date", "end_date"]:
if date_field in duration:
date_value = duration[date_field]
if date_value != "๋ช
์๋์ง ์์":
import re
if not re.match(r'\d{4}-\d{2}-\d{2}', date_value):
validation_result["warnings"].append(
f"๋ ์ง ํ์ ๋ถ์ผ์น: {date_field}"
)
# ๊ธ์ก ์ ๋ณด ๊ฒ์ฆ
if "amount" in extracted_data:
amount = extracted_data["amount"]
if isinstance(amount, dict) and "total" in amount:
if amount["total"] == "๋ช
์๋์ง ์์":
validation_result["warnings"].append("๊ณ์ฝ ๊ธ์ก์ด ๋ช
์๋์ง ์์")
return validation_result
โข ๋ช ํํ ์ญํ ๋ถ์ฌ: "๋น์ ์ ๋ฒ๋ฅ ๋ฌธ์ ๋ถ์ ์ ๋ฌธ๊ฐ์ ๋๋ค"
โข ๊ตฌ์ฒด์ ์ธ ์ง์์ฌํญ: ์ถ์ถํ ํญ๋ชฉ์ ๋ช ํํ ๋์ด
โข ์ถ๋ ฅ ํ์ ์ง์ : JSON ์คํค๋ง๋ฅผ ์์๋ก ์ ๊ณต
โข ์์ธ ์ฒ๋ฆฌ ๊ท์น: ์ ๋ณด๊ฐ ์์ ๋ ์ด๋ป๊ฒ ํ์ํ ์ง ๋ช ์
โข Temperature 0: ์ผ๊ด์ฑ ์๋ ๊ฒฐ๊ณผ๋ฅผ ์ํด ์ฐฝ์์ฑ ์ต์ํ
๐ FastAPI๋ก ์น ์๋น์ค ๋ง๋ค๊ธฐ
์ด์ ๋ง๋ ๊ธฐ๋ฅ๋ค์ ์น API๋ก ์ ๊ณตํด๋ณด์! ๐
FastAPI๋ฅผ ์ฌ์ฉํ๋ฉด ๋น ๋ฅด๊ณ ์ฝ๊ฒ RESTful API๋ฅผ ๊ตฌ์ถํ ์ ์์ด.
from fastapi import FastAPI, File, UploadFile, HTTPException
from fastapi.responses import JSONResponse
from fastapi.middleware.cors import CORSMiddleware
import shutil
import os
from pathlib import Path
from typing import Optional
import logging
from document_parser import DocumentParser
from claude_client import ClaudeContractAnalyzer
# ๋ก๊น
์ค์
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
# FastAPI ์ฑ ์์ฑ
app = FastAPI(
title="๊ณ์ฝ์ ์๋ ๋ถ์ API",
description="Claude AI๋ฅผ ํ์ฉํ ๊ณ์ฝ์ ์ฃผ์ ์กฐํญ ์๋ ์ถ์ถ ์์คํ
",
version="1.0.0"
)
# CORS ์ค์ (ํ๋ก ํธ์๋์์ ์ ๊ทผ ๊ฐ๋ฅํ๋๋ก)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # ํ๋ก๋์
์์๋ ํน์ ๋๋ฉ์ธ๋ง ํ์ฉ
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# ์
๋ก๋ ๋๋ ํ ๋ฆฌ ์ค์
UPLOAD_DIR = Path("uploads")
UPLOAD_DIR.mkdir(exist_ok=True)
# ํด๋์ค ์ธ์คํด์ค ์์ฑ
parser = DocumentParser()
analyzer = ClaudeContractAnalyzer()
@app.get("/")
async def root():
"""API ๋ฃจํธ ์๋ํฌ์ธํธ"""
return {
"message": "๊ณ์ฝ์ ์๋ ๋ถ์ API์ ์ค์ ๊ฒ์ ํ์ํฉ๋๋ค!",
"endpoints": {
"upload": "/api/analyze",
"health": "/health"
}
}
@app.get("/health")
async def health_check():
"""์๋ฒ ์ํ ํ์ธ"""
return {"status": "healthy", "service": "contract-analyzer"}
@app.post("/api/analyze")
async def analyze_contract(
file: UploadFile = File(...),
extract_tables: Optional[bool] = False
):
"""
๊ณ์ฝ์ ํ์ผ์ ์
๋ก๋ํ๊ณ ์ฃผ์ ์กฐํญ์ ์ถ์ถ
Args:
file: ์
๋ก๋ํ ๊ณ์ฝ์ ํ์ผ (PDF, DOCX, ์ด๋ฏธ์ง)
extract_tables: ํ ๋ฐ์ดํฐ ์ถ์ถ ์ฌ๋ถ
Returns:
์ถ์ถ๋ ๊ณ์ฝ์ ์กฐํญ ์ ๋ณด
"""
# ํ์ผ ํ์ฅ์ ๊ฒ์ฆ
file_extension = file.filename.split('.')[-1].lower()
if file_extension not in parser.supported_formats:
raise HTTPException(
status_code=400,
detail=f"์ง์ํ์ง ์๋ ํ์ผ ํ์์
๋๋ค. ์ง์ ํ์: {', '.join(parser.supported_formats)}"
)
# ํ์ผ ํฌ๊ธฐ ๊ฒ์ฆ (10MB ์ ํ)
file.file.seek(0, 2) # ํ์ผ ๋์ผ๋ก ์ด๋
file_size = file.file.tell() # ํ์ฌ ์์น = ํ์ผ ํฌ๊ธฐ
file.file.seek(0) # ๋ค์ ์ฒ์์ผ๋ก
if file_size > 10 * 1024 * 1024: # 10MB
raise HTTPException(
status_code=400,
detail="ํ์ผ ํฌ๊ธฐ๋ 10MB๋ฅผ ์ด๊ณผํ ์ ์์ต๋๋ค."
)
# ํ์ผ ์ ์ฅ
file_path = UPLOAD_DIR / file.filename
try:
with open(file_path, "wb") as buffer:
shutil.copyfileobj(file.file, buffer)
logger.info(f"ํ์ผ ์
๋ก๋ ์๋ฃ: {file.filename}")
# 1๋จ๊ณ: ํ
์คํธ ์ถ์ถ
logger.info("ํ
์คํธ ์ถ์ถ ์์...")
raw_text = parser.extract_text(str(file_path))
if not raw_text:
raise HTTPException(
status_code=500,
detail="ํ์ผ์์ ํ
์คํธ๋ฅผ ์ถ์ถํ ์ ์์ต๋๋ค."
)
# 2๋จ๊ณ: ํ
์คํธ ์ ์ฒ๋ฆฌ
logger.info("ํ
์คํธ ์ ์ฒ๋ฆฌ ์ค...")
processed_text = parser.preprocess_text(raw_text)
# 3๋จ๊ณ: Claude๋ก ์กฐํญ ์ถ์ถ
logger.info("AI ๋ถ์ ์์...")
extracted_data = analyzer.extract_contract_clauses(processed_text)
# 4๋จ๊ณ: ๊ฒฐ๊ณผ ๊ฒ์ฆ
logger.info("๊ฒฐ๊ณผ ๊ฒ์ฆ ์ค...")
validation = analyzer.validate_extraction(extracted_data)
# ์๋ต ๊ตฌ์ฑ
response = {
"success": True,
"filename": file.filename,
"file_size": file_size,
"extracted_data": extracted_data,
"validation": validation,
"metadata": {
"text_length": len(processed_text),
"model_used": analyzer.model
}
}
logger.info("๋ถ์ ์๋ฃ!")
return JSONResponse(content=response)
except Exception as e:
logger.error(f"๋ถ์ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}")
raise HTTPException(
status_code=500,
detail=f"๋ถ์ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}"
)
finally:
# ์์ ํ์ผ ์ญ์ (์ ํ์ฌํญ)
if file_path.exists():
# file_path.unlink() # ํ์ผ ๋ณด๊ดํ๋ ค๋ฉด ์ฃผ์ ์ฒ๋ฆฌ
pass
@app.post("/api/batch-analyze")
async def batch_analyze_contracts(files: list[UploadFile] = File(...)):
"""
์ฌ๋ฌ ๊ณ์ฝ์๋ฅผ ํ ๋ฒ์ ๋ถ์
Args:
files: ์
๋ก๋ํ ๊ณ์ฝ์ ํ์ผ ๋ฆฌ์คํธ
Returns:
๊ฐ ํ์ผ๋ณ ๋ถ์ ๊ฒฐ๊ณผ
"""
results = []
for file in files:
try:
# ๊ฐ ํ์ผ์ ๋ํด analyze_contract ๋ก์ง ์คํ
result = await analyze_contract(file)
results.append({
"filename": file.filename,
"status": "success",
"data": result
})
except Exception as e:
results.append({
"filename": file.filename,
"status": "error",
"error": str(e)
})
return JSONResponse(content={
"total_files": len(files),
"results": results
})
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)
# ๊ฐ๋ฐ ๋ชจ๋๋ก ์คํ (์๋ ๋ฆฌ๋ก๋)
uvicorn main:app --reload --host 0.0.0.0 --port 8000
# ํ๋ก๋์
๋ชจ๋๋ก ์คํ
uvicorn main:app --host 0.0.0.0 --port 8000 --workers 4
# ์๋ฒ ์คํ ํ ์ ์
# API ๋ฌธ์: http://localhost:8000/docs
# ๋์ฒด ๋ฌธ์: http://localhost:8000/redoc
โข ํ์ ํํ : Python์ ํ์ ํํธ๋ฅผ ํ์ฉํด์ ์๋ ๊ฒ์ฆ
โข ๋น๋๊ธฐ ์ง์: async/await๋ก ๋์ ์ฑ๋ฅ ๊ตฌํ
โข ์์กด์ฑ ์ฃผ์ : ์ฝ๋ ์ฌ์ฌ์ฉ์ฑ๊ณผ ํ ์คํธ ์ฉ์ด์ฑ ํฅ์
โข ๋น ๋ฅธ ๊ฐ๋ฐ: ๋ณด์ผ๋ฌํ๋ ์ดํธ ์ฝ๋ ์ต์ํ
๐จ ํ๋ก ํธ์๋ ์ธํฐํ์ด์ค ๊ตฌ์ถ
๋ฐฑ์๋ API๊ฐ ์ค๋น๋์ผ๋, ์ด์ ์ฌ์ฉ์๊ฐ ์ฝ๊ฒ ์ฌ์ฉํ ์ ์๋ ์น ์ธํฐํ์ด์ค๋ฅผ ๋ง๋ค์ด๋ณด์! ๐ฅ๏ธ
๊ฐ๋จํ HTML + JavaScript๋ก๋ ์ถฉ๋ถํ ๋ฉ์ง UI๋ฅผ ๋ง๋ค ์ ์์ด.
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>๊ณ์ฝ์ ์๋ ๋ถ์ ์์คํ
</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); min-height: 100vh; padding: 20px; }
.container { max-width: 900px; margin: 0 auto; background: white; border-radius: 20px; padding: 40px; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
h1 { color: #667eea; text-align: center; margin-bottom: 30px; font-size: 2.5em; }
.upload-area { border: 3px dashed #667eea; border-radius: 15px; padding: 60px 20px; text-align: center; cursor: pointer; transition: all 0.3s; margin-bottom: 30px; }
.upload-area:hover { background: #f0f4ff; border-color: #764ba2; }
.upload-area.dragover { background: #e0e7ff; border-color: #4c51bf; }
.file-input { display: none; }
.upload-icon { font-size: 4em; margin-bottom: 20px; }
.upload-text { font-size: 1.2em; color: #666; }
.file-info { background: #f0f4ff; padding: 15px; border-radius: 10px; margin-bottom: 20px; display: none; }
.analyze-btn { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; border: none; padding: 15px 40px; font-size: 1.1em; border-radius: 10px; cursor: pointer; width: 100%; transition: transform 0.2s; }
.analyze-btn:hover { transform: translateY(-2px); box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4); }
.analyze-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.loading { display: none; text-align: center; margin: 20px 0; }
.spinner { border: 4px solid #f3f3f3; border-top: 4px solid #667eea; border-radius: 50%; width: 50px; height: 50px; animation: spin 1s linear infinite; margin: 0 auto; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
.results { display: none; margin-top: 30px; }
.result-section { background: #f9fafb; padding: 20px; border-radius: 10px; margin-bottom: 15px; border-left: 4px solid #667eea; }
.result-title { font-size: 1.2em; font-weight: bold; color: #667eea; margin-bottom: 10px; }
.result-content { color: #333; line-height: 1.6; }
.error { background: #fee; border-left-color: #e53e3e; }
.error .result-title { color: #e53e3e; }
</style>
</head>
<body>
<div class="container">
<h1>๐ ๊ณ์ฝ์ ์๋ ๋ถ์ ์์คํ
</h1>
<div class="upload-area" id="uploadArea">
<div class="upload-icon">๐</div>
<div class="upload-text">
ํด๋ฆญํ๊ฑฐ๋ ํ์ผ์ ๋๋๊ทธํ์ฌ ์
๋ก๋ํ์ธ์<br>
<small>(PDF, DOCX, ์ด๋ฏธ์ง ํ์ผ ์ง์)</small>
</div>
<input type="file" id="fileInput" class="file-input" accept=".pdf,.docx,.doc,.png,.jpg,.jpeg">
</div>
<div class="file-info" id="fileInfo"></div>
<button class="analyze-btn" id="analyzeBtn" disabled>๋ถ์ ์์ ๐</button>
<div class="loading" id="loading">
<div class="spinner"></div>
<p>AI๊ฐ ๊ณ์ฝ์๋ฅผ ๋ถ์ํ๊ณ ์์ต๋๋ค...</p>
</div>
<div class="results" id="results"></div>
</div>
<script>
const uploadArea = document.getElementById('uploadArea');
const fileInput = document.getElementById('fileInput');
const fileInfo = document.getElementById('fileInfo');
const analyzeBtn = document.getElementById('analyzeBtn');
const loading = document.getElementById('loading');
const results = document.getElementById('results');
let selectedFile = null;
// ํด๋ฆญ์ผ๋ก ํ์ผ ์ ํ
uploadArea.addEventListener('click', () => fileInput.click());
// ํ์ผ ์ ํ ์ด๋ฒคํธ
fileInput.addEventListener('change', (e) => {
handleFile(e.target.files[0]);
});
// ๋๋๊ทธ ์ค ๋๋กญ
uploadArea.addEventListener('dragover', (e) => {
e.preventDefault();
uploadArea.classList.add('dragover');
});
uploadArea.addEventListener('dragleave', () => {
uploadArea.classList.remove('dragover');
});
uploadArea.addEventListener('drop', (e) => {
e.preventDefault();
uploadArea.classList.remove('dragover');
handleFile(e.dataTransfer.files[0]);
});
function handleFile(file) {
if (!file) return;
selectedFile = file;
const fileSize = (file.size / 1024 / 1024).toFixed(2);
fileInfo.innerHTML = `
<strong>์ ํ๋ ํ์ผ:</strong> ${file.name}<br>
<strong>ํฌ๊ธฐ:</strong> ${fileSize} MB<br>
<strong>ํ์:</strong> ${file.type || '์ ์ ์์'}
`;
fileInfo.style.display = 'block';
analyzeBtn.disabled = false;
}
// ๋ถ์ ๋ฒํผ ํด๋ฆญ
analyzeBtn.addEventListener('click', async () => {
if (!selectedFile) return;
analyzeBtn.disabled = true;
loading.style.display = 'block';
results.style.display = 'none';
const formData = new FormData();
formData.append('file', selectedFile);
try {
const response = await fetch('http://localhost:8000/api/analyze', {
method: 'POST',
body: formData
});
const data = await response.json();
if (data.success) {
displayResults(data.extracted_data);
} else {
showError('๋ถ์์ ์คํจํ์ต๋๋ค.');
}
} catch (error) {
showError('์๋ฒ ์ฐ๊ฒฐ์ ์คํจํ์ต๋๋ค: ' + error.message);
} finally {
loading.style.display = 'none';
analyzeBtn.disabled = false;
}
});
function displayResults(data) {
results.innerHTML = '';
// ๊ณ์ฝ ๋น์ฌ์
if (data.parties) {
addResultSection('๊ณ์ฝ ๋น์ฌ์', `
<strong>๊ฐ:</strong> ${data.parties.party_a || '๋ช
์๋์ง ์์'}<br>
<strong>์:</strong> ${data.parties.party_b || '๋ช
์๋์ง ์์'}
`);
}
// ๊ณ์ฝ ๋ชฉ์
if (data.purpose) {
addResultSection('๊ณ์ฝ ๋ชฉ์ ', data.purpose);
}
// ๊ณ์ฝ ๊ธฐ๊ฐ
if (data.duration) {
const duration = data.duration;
addResultSection('๊ณ์ฝ ๊ธฐ๊ฐ', `
<strong>์์์ผ:</strong> ${duration.start_date || '๋ช
์๋์ง ์์'}<br>
<strong>์ข
๋ฃ์ผ:</strong> ${duration.end_date || '๋ช
์๋์ง ์์'}<br>
<strong>๊ธฐ๊ฐ:</strong> ${duration.period || '๋ช
์๋์ง ์์'}
`);
}
// ๊ณ์ฝ ๊ธ์ก
if (data.amount) {
const amount = data.amount;
let amountHtml = `<strong>์ด์ก:</strong> ${amount.total || '๋ช
์๋์ง ์์'}`;
if (amount.breakdown && amount.breakdown.length > 0) {
amountHtml += '<br><strong>์ธ๋ถ๋ด์ญ:</strong><ul>';
amount.breakdown.forEach(item => {
amountHtml += `<li>${item}</li>`;
});
amountHtml += '</ul>';
}
addResultSection('๊ณ์ฝ ๊ธ์ก', amountHtml);
}
// ์์ฝ ์กฐ๊ฑด
if (data.penalty_clauses) {
addResultSection('์์ฝ ์กฐ๊ฑด', data.penalty_clauses);
}
// ํด์ง ์กฐ๊ฑด
if (data.termination_clauses) {
addResultSection('ํด์ง ์กฐ๊ฑด', data.termination_clauses);
}
results.style.display = 'block';
}
function addResultSection(title, content) {
const section = document.createElement('div');
section.className = 'result-section';
section.innerHTML = `
<div class="result-title">${title}</div>
<div class="result-content">${content}</div>
`;
results.appendChild(section);
}
function showError(message) {
results.innerHTML = `
<div class="result-section error">
<div class="result-title">์ค๋ฅ ๋ฐ์</div>
<div class="result-content">${message}</div>
</div>
`;
results.style.display = 'block';
}
</script>
</body>
</html>
ํด๊ฒฐ ๋ฐฉ๋ฒ:
1. ๊ฐ๋จํ HTTP ์๋ฒ ์คํ:
python -m http.server 30002. FastAPI์ CORS ๋ฏธ๋ค์จ์ด ์ถ๊ฐ (์ ์ฝ๋์ ์ด๋ฏธ ํฌํจ๋จ)
3. ๋ธ๋ผ์ฐ์ ํ์ฅ ํ๋ก๊ทธ๋จ ์ฌ์ฉ (๊ฐ๋ฐ ์์๋ง!)
๐ง ๊ณ ๊ธ ๊ธฐ๋ฅ ์ถ๊ฐํ๊ธฐ
๊ธฐ๋ณธ ๊ธฐ๋ฅ์ด ์์ฑ๋์ผ๋, ์ด์ ์์คํ
์ ๋ ๊ฐ๋ ฅํ๊ฒ ๋ง๋ค์ด๋ณด์! ๐ช
์ค๋ฌด์์ ์ ์ฉํ ๊ณ ๊ธ ๊ธฐ๋ฅ๋ค์ ์ถ๊ฐํด๋ณผ๊ฒ.
์ฌ๋ฌ ๊ณ์ฝ์๋ฅผ ๋น๊ตํด์ ์ฐจ์ด์ ์ ์ฐพ์๋ด๋ ๊ธฐ๋ฅ์ด์ผ.
์๋ฅผ ๋ค์ด, ํ์ค ๊ณ์ฝ์์ ์ค์ ๊ณ์ฝ์๋ฅผ ๋น๊ตํ๊ฑฐ๋, ์ฌ๋ฌ ๊ณต๊ธ์ ์ฒด์ ๊ณ์ฝ ์กฐ๊ฑด์ ๋น๊ตํ ๋ ์ ์ฉํด.
def compare_contracts(self, contract1_text: str, contract2_text: str) -> Dict:
"""๋ ๊ณ์ฝ์๋ฅผ ๋น๊ตํ์ฌ ์ฐจ์ด์ ๋ถ์"""
prompt = f"""๋ค์ ๋ ๊ณ์ฝ์๋ฅผ ๋น๊ตํ์ฌ ์ฃผ์ ์ฐจ์ด์ ์ ๋ถ์ํด์ฃผ์ธ์.
๊ณ์ฝ์ A:
{contract1_text[:5000]} # ํ ํฐ ์ ํ ๊ณ ๋ ค
๊ณ์ฝ์ B:
{contract2_text[:5000]}
๋ค์ ํญ๋ชฉ๋ค์ ๋ํด ๋น๊ต ๋ถ์ํด์ฃผ์ธ์:
1. ๊ณ์ฝ ๊ธ์ก์ ์ฐจ์ด
2. ๊ณ์ฝ ๊ธฐ๊ฐ์ ์ฐจ์ด
3. ์๋ฌด์ฌํญ์ ์ฐจ์ด
4. ์์ฝ ์กฐ๊ฑด์ ์ฐจ์ด
5. ๊ธฐํ ์ค์ํ ์ฐจ์ด์
JSON ํ์์ผ๋ก ๋ฐํ:
{{
"differences": [
{{
"category": "์นดํ
๊ณ ๋ฆฌ",
"contract_a": "๊ณ์ฝ์ A์ ๋ด์ฉ",
"contract_b": "๊ณ์ฝ์ B์ ๋ด์ฉ",
"significance": "high/medium/low"
}}
],
"summary": "์ ์ฒด ๋น๊ต ์์ฝ"
}}"""
message = self.client.messages.create(
model=self.model,
max_tokens=4096,
messages=[{"role": "user", "content": prompt}]
)
return self._parse_response(message.content[0].text)
๊ณ์ฝ์์์ ์ ์ฌ์ ์ธ ๋ฆฌ์คํฌ๋ฅผ ์๋์ผ๋ก ์ฐพ์๋ด๋ ๊ธฐ๋ฅ์ด์ผ.
๋ถ๋ฆฌํ ์กฐํญ์ด๋ ๋ชจํธํ ํํ, ๋ฒ์ ๋ฌธ์ ๊ฐ๋ฅ์ฑ ๋ฑ์ ์ฒดํฌํด์ค.
def analyze_risks(self, contract_text: str) -> Dict:
"""๊ณ์ฝ์์ ์ ์ฌ์ ๋ฆฌ์คํฌ ๋ถ์"""
prompt = f"""๋ค์ ๊ณ์ฝ์๋ฅผ ๋ฒ๋ฅ ์ ๋ฌธ๊ฐ ๊ด์ ์์ ๋ถ์ํ์ฌ ์ ์ฌ์ ๋ฆฌ์คํฌ๋ฅผ ์ฐพ์์ฃผ์ธ์.
๊ณ์ฝ์ ๋ด์ฉ:
{contract_text}
๋ค์ ๊ด์ ์์ ๋ฆฌ์คํฌ๋ฅผ ํ๊ฐํด์ฃผ์ธ์:
1. ๋ถ๊ณต์ ํ ์กฐํญ (์ผ๋ฐฉ์ ์ผ๋ก ๋ถ๋ฆฌํ ๋ด์ฉ)
2. ๋ชจํธํ ํํ (ํด์์ ์ฌ์ง๊ฐ ์๋ ๋ถ๋ถ)
3. ๋๋ฝ๋ ์ค์ ์กฐํญ (์ผ๋ฐ์ ์ผ๋ก ํฌํจ๋์ด์ผ ํ๋๋ฐ ์๋ ๊ฒ)
4. ๊ณผ๋ํ ์ฑ
์ ๋ถ๋ด
5. ๋ถ๋ช
ํํ ํด์ง ์กฐ๊ฑด
6. ๋ถ์ ๋ฐ์ ๊ฐ๋ฅ์ฑ
๊ฐ ๋ฆฌ์คํฌ์ ๋ํด ์ฌ๊ฐ๋(high/medium/low)์ ๊ฐ์ ์ ์์ ํฌํจํด์ฃผ์ธ์.
JSON ํ์:
{{
"risks": [
{{
"category": "๋ฆฌ์คํฌ ์นดํ
๊ณ ๋ฆฌ",
"description": "๋ฆฌ์คํฌ ์ค๋ช
",
"severity": "high/medium/low",
"location": "ํด๋น ์กฐํญ ์์น",
"recommendation": "๊ฐ์ ์ ์"
}}
],
"overall_risk_score": "1-10์ ",
"summary": "์ ์ฒด ๋ฆฌ์คํฌ ํ๊ฐ ์์ฝ"
}}"""
message = self.client.messages.create(
model=self.model,
max_tokens=4096,
temperature=0.3, # ์ฝ๊ฐ์ ์ฐฝ์์ฑ ํ์ฉ
messages=[{"role": "user", "content": prompt}]
)
return self._parse_response(message.content[0].text)
๊ธด ๊ณ์ฝ์๋ฅผ ํ ํ์ด์ง๋ก ์์ฝํด์ฃผ๋ ๊ธฐ๋ฅ์ด์ผ.
๋ฐ์ ์์๋ค์ด๋ ๋น ๋ฅธ ๊ฒํ ๊ฐ ํ์ํ ๋ ์ ๋ง ์ ์ฉํด.
def generate_summary(self, contract_text: str, summary_type: str = "executive") -> str:
"""
๊ณ์ฝ์ ์์ฝ ์์ฑ
Args:
contract_text: ๊ณ์ฝ์ ์ ๋ฌธ
summary_type: "executive" (์์์ฉ), "technical" (์ค๋ฌด์์ฉ), "legal" (๋ฒ๋ฌดํ์ฉ)
"""
summary_instructions = {
"executive": "์์์ง์ด ๋น ๋ฅด๊ฒ ์์ฌ๊ฒฐ์ ํ ์ ์๋๋ก ํต์ฌ๋ง ๊ฐ๋จ๋ช
๋ฃํ๊ฒ",
"technical": "์ค๋ฌด ๋ด๋น์๊ฐ ์
๋ฌด ์ํ์ ํ์ํ ์ธ๋ถ์ฌํญ ํฌํจ",
"legal": "๋ฒ๋ฌดํ์ด ๊ฒํ ํ ๋ฒ์ ์์ ๊ณผ ๋ฆฌ์คํฌ ์ค์ฌ์ผ๋ก"
}
instruction = summary_instructions.get(summary_type, summary_instructions["executive"])
prompt = f"""๋ค์ ๊ณ์ฝ์๋ฅผ {instruction} ์์ฝํด์ฃผ์ธ์.
๊ณ์ฝ์ ๋ด์ฉ:
{contract_text}
์์ฝ ํ์:
1. ํ ์ค ์์ฝ (30์ ์ด๋ด)
2. ํต์ฌ ๋ด์ฉ (3-5๊ฐ ๋ถ๋ฆฟ ํฌ์ธํธ)
3. ์ฃผ์ ์์น (๊ธ์ก, ๊ธฐ๊ฐ ๋ฑ)
4. ์ฃผ์์ฌํญ (์๋ค๋ฉด)
๊ฐ๊ฒฐํ๊ณ ๋ช
ํํ๊ฒ ์์ฑํด์ฃผ์ธ์."""
message = self.client.messages.create(
model=self.model,
max_tokens=1024,
messages=[{"role": "user", "content": prompt}]
)
return message.content[0].text
์์ฃผ ์ฌ์ฉํ๋ ๊ณ์ฝ์ ์ ํ๋ณ๋ก ์ถ์ถ ํ ํ๋ฆฟ์ ๋ง๋ค์ด๋๋ฉด ์ ํ๋๊ฐ ๋์์ ธ.
์: ๊ทผ๋ก๊ณ์ฝ์, ์๋์ฐจ๊ณ์ฝ์, ๊ณต๊ธ๊ณ์ฝ์ ๋ฑ
2. ํ์คํ ๋ฆฌ ๊ด๋ฆฌ:
๋ถ์ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ์ ์ฅํด์ ๋์ค์ ๊ฒ์ํ๊ฑฐ๋ ํต๊ณ๋ฅผ ๋ผ ์ ์์ด.
"์ง๋ 6๊ฐ์๊ฐ ์ฐ๋ฆฌ ํ์ฌ๊ฐ ์ฒด๊ฒฐํ ๊ณ์ฝ์ ํ๊ท ๊ธ์ก์?" ๊ฐ์ ์ง๋ฌธ์ ๋ตํ ์ ์์ง.
3. ์๋ฆผ ์์คํ :
๊ณ์ฝ ๋ง๋ฃ์ผ์ด ๋ค๊ฐ์ค๊ฑฐ๋, ๊ฐฑ์ ์๊ธฐ๊ฐ ๋๋ฉด ์๋์ผ๋ก ์๋ฆผ์ ๋ณด๋ด๋ ๊ธฐ๋ฅ์ ์ถ๊ฐํ๋ฉด ์ข์.
4. ์น์ธ ์ํฌํ๋ก์ฐ:
์ถ์ถ๋ ์ ๋ณด๋ฅผ ๋ด๋น์๊ฐ ๊ฒํ ํ๊ณ ์น์ธํ๋ ํ๋ก์ธ์ค๋ฅผ ๋ง๋ค๋ฉด ๋ ์์ ํด.
๐ ๋ณด์ ๋ฐ ๊ฐ์ธ์ ๋ณด ๋ณดํธ
๊ณ์ฝ์๋ ๋ฏผ๊ฐํ ์ ๋ณด๊ฐ ๋ง์ด ํฌํจ๋ ๋ฌธ์์ผ. ๋ณด์์ ๊ฐ๋ณํ ์ ๊ฒฝ ์จ์ผ ํด! ๐ก๏ธ
โข ์ ์ก ์ค: HTTPS/TLS ์ฌ์ฉ (Let's Encrypt๋ก ๋ฌด๋ฃ SSL ์ธ์ฆ์ ๋ฐ๊ธ)
โข ์ ์ฅ ์: ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ํธํ, ํ์ผ ์์คํ ์ํธํ
โข API ํค: ํ๊ฒฝ๋ณ์๋ ๋น๋ฐ ๊ด๋ฆฌ ์์คํ (AWS Secrets Manager, HashiCorp Vault) ์ฌ์ฉ
2. ์ ๊ทผ ์ ์ด
โข ์ฌ์ฉ์ ์ธ์ฆ: JWT ํ ํฐ ๊ธฐ๋ฐ ์ธ์ฆ ๊ตฌํ
โข ๊ถํ ๊ด๋ฆฌ: RBAC(Role-Based Access Control) ์ ์ฉ
โข IP ํ์ดํธ๋ฆฌ์คํธ: ํน์ IP์์๋ง ์ ๊ทผ ํ์ฉ
3. ๋ฐ์ดํฐ ๋ณด์กด ์ ์ฑ
โข ์ ๋ก๋๋ ํ์ผ์ ๋ถ์ ํ ์ฆ์ ์ญ์ ํ๊ฑฐ๋ ์ํธํ ์ ์ฅ
โข ๋ก๊ทธ๋ ๊ฐ์ธ์ ๋ณด๋ฅผ ์ ์ธํ๊ณ ๊ธฐ๋ก
โข ์ ๊ธฐ์ ์ธ ๋ฐ์ดํฐ ์ญ์ ์ค์ผ์ค ์ด์
4. Claude API ๋ณด์
โข API ํค ๋ ธ์ถ ๋ฐฉ์ง (์ ๋ ์ฝ๋์ ํ๋์ฝ๋ฉ ๊ธ์ง!)
โข Rate limiting ์ค์ ์ผ๋ก ๊ณผ๋ํ ์์ฒญ ๋ฐฉ์ง
โข ์๋ฌ ๋ฉ์์ง์ ๋ฏผ๊ฐ ์ ๋ณด ํฌํจ ๊ธ์ง
# ํ์ผ ์
๋ก๋ ๋ณด์ ๊ฒ์ฆ
import hashlib
import magic # python-magic ๋ผ์ด๋ธ๋ฌ๋ฆฌ
def validate_file_security(file_path: str) -> bool:
"""ํ์ผ ๋ณด์ ๊ฒ์ฆ"""
# 1. ์ค์ ํ์ผ ํ์
ํ์ธ (ํ์ฅ์ ์์ด๊ธฐ ๋ฐฉ์ง)
mime = magic.Magic(mime=True)
file_type = mime.from_file(file_path)
allowed_types = [
'application/pdf',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'image/png',
'image/jpeg'
]
if file_type not in allowed_types:
logger.warning(f"ํ์ฉ๋์ง ์์ ํ์ผ ํ์
: {file_type}")
return False
# 2. ํ์ผ ํฌ๊ธฐ ๊ฒ์ฆ
file_size = os.path.getsize(file_path)
if file_size > 10 * 1024 * 1024: # 10MB
logger.warning(f"ํ์ผ ํฌ๊ธฐ ์ด๊ณผ: {file_size}")
return False
# 3. ์
์ฑ ์ฝ๋ ์ค์บ (ClamAV ๋ฑ ์ฌ์ฉ)
# scan_result = scan_with_clamav(file_path)
# if not scan_result.is_clean:
# return False
return True
# JWT ์ธ์ฆ ๋ฏธ๋ค์จ์ด
from fastapi import Depends, HTTPException, status
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
import jwt
security = HTTPBearer()
def verify_token(credentials: HTTPAuthorizationCredentials = Depends(security)):
"""JWT ํ ํฐ ๊ฒ์ฆ"""
try:
token = credentials.credentials
payload = jwt.decode(token, SECRET_KEY, algorithms=["HS256"])
return payload
except jwt.ExpiredSignatureError:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="ํ ํฐ์ด ๋ง๋ฃ๋์์ต๋๋ค"
)
except jwt.InvalidTokenError:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="์ ํจํ์ง ์์ ํ ํฐ์
๋๋ค"
)
# ๋ณดํธ๋ ์๋ํฌ์ธํธ
@app.post("/api/analyze")
async def analyze_contract(
file: UploadFile = File(...),
user: dict = Depends(verify_token) # ์ธ์ฆ ํ์
):
# ์ฌ์ฉ์ ๊ถํ ํ์ธ
if "contract:analyze" not in user.get("permissions", []):
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN,
detail="๊ถํ์ด ์์ต๋๋ค"
)
# ... ๋ถ์ ๋ก์ง
๐ ์ฑ๋ฅ ์ต์ ํ ์ ๋ต
์์คํ
์ด ๋ง์ ์ฌ์ฉ์๋ฅผ ์ฒ๋ฆฌํ๋ ค๋ฉด ์ฑ๋ฅ ์ต์ ํ๊ฐ ํ์์ผ! โก
ํนํ Claude API ํธ์ถ์ ๋น์ฉ์ด ๋ฐ์ํ๋๊น ํจ์จ์ ์ผ๋ก ์ฌ์ฉํด์ผ ํด.
1. ์บ์ฑ ์ ๋ต ๐พ
๊ฐ์ ๊ณ์ฝ์๋ฅผ ์ฌ๋ฌ ๋ฒ ๋ถ์ํ๋ ๊ฑด ๋ญ๋น์ผ. ๊ฒฐ๊ณผ๋ฅผ ์บ์ฑํด๋์!
import hashlib
import redis
import json
# Redis ํด๋ผ์ด์ธํธ ์ค์
redis_client = redis.Redis(host='localhost', port=6379, db=0)
def get_file_hash(file_content: bytes) -> str:
"""ํ์ผ ๋ด์ฉ์ ํด์๊ฐ ์์ฑ"""
return hashlib.sha256(file_content).hexdigest()
def analyze_with_cache(file_content: bytes, file_name: str) -> Dict:
"""์บ์๋ฅผ ํ์ฉํ ๋ถ์"""
# ํ์ผ ํด์ ์์ฑ
file_hash = get_file_hash(file_content)
cache_key = f"contract_analysis:{file_hash}"
# ์บ์ ํ์ธ
cached_result = redis_client.get(cache_key)
if cached_result:
logger.info(f"์บ์์์ ๊ฒฐ๊ณผ ๋ฐํ: {file_name}")
return json.loads(cached_result)
# ์บ์ ๋ฏธ์ค - ์ค์ ๋ถ์ ์ํ
logger.info(f"์๋ก์ด ๋ถ์ ์ํ: {file_name}")
result = analyzer.extract_contract_clauses(file_content.decode())
# ๊ฒฐ๊ณผ ์บ์ฑ (24์๊ฐ ์ ์ง)
redis_client.setex(
cache_key,
86400, # 24์๊ฐ
json.dumps(result)
)
return result
2. ๋ฐฐ์น ์ฒ๋ฆฌ ๐ฆ์ฌ๋ฌ ๊ณ์ฝ์๋ฅผ ํ ๋ฒ์ ์ฒ๋ฆฌํ ๋๋ ๋ณ๋ ฌ ์ฒ๋ฆฌ๋ฅผ ํ์ฉํด!
from concurrent.futures import ThreadPoolExecutor, as_completed
import asyncio
async def batch_analyze_async(files: List[UploadFile]) -> List[Dict]:
"""๋น๋๊ธฐ ๋ฐฐ์น ๋ถ์"""
async def analyze_single(file: UploadFile) -> Dict:
try:
content = await file.read()
text = parser.extract_text_from_bytes(content)
result = analyzer.extract_contract_clauses(text)
return {
"filename": file.filename,
"status": "success",
"data": result
}
except Exception as e:
return {
"filename": file.filename,
"status": "error",
"error": str(e)
}
# ๋์์ ์ต๋ 5๊ฐ๊น์ง ์ฒ๋ฆฌ
semaphore = asyncio.Semaphore(5)
async def analyze_with_limit(file):
async with semaphore:
return await analyze_single(file)
tasks = [analyze_with_limit(file) for file in files]
results = await asyncio.gather(*tasks)
return results
3. ํ
์คํธ ์ฒญํน ์ ๋ต โ๏ธ๊ณ์ฝ์๊ฐ ๋๋ฌด ๊ธธ๋ฉด ํ ํฐ ์ ํ์ ๊ฑธ๋ฆด ์ ์์ด. ๋๋ํ๊ฒ ๋๋์!
def smart_chunk_text(text: str, max_tokens: int = 8000) -> List[str]:
"""์๋ฏธ ๋จ์๋ก ํ
์คํธ ๋ถํ """
# ์น์
๊ตฌ๋ถ์๋ก ๋จผ์ ๋ถํ ์๋
section_markers = [
"์ 1 ์กฐ", "์ 2 ์กฐ", "์ 1์กฐ", "์ 2์กฐ",
"Article 1", "Article 2",
"1.", "2.", "3."
]
chunks = []
current_chunk = ""
paragraphs = text.split('\n\n')
for para in paragraphs:
# ํ์ฌ ์ฒญํฌ์ ์ถ๊ฐํ์ ๋ ํ ํฐ ์ ์์ธก
estimated_tokens = len(current_chunk + para) // 4 # ๋๋ต์ ์ธ ์ถ์
if estimated_tokens > max_tokens:
if current_chunk:
chunks.append(current_chunk.strip())
current_chunk = para
else:
current_chunk += "\n\n" + para
if current_chunk:
chunks.append(current_chunk.strip())
return chunks
def analyze_long_contract(text: str) -> Dict:
"""๊ธด ๊ณ์ฝ์ ๋ถ์ (์ฒญํน ํ์ฉ)"""
chunks = smart_chunk_text(text)
if len(chunks) == 1:
# ํ ๋ฒ์ ์ฒ๋ฆฌ ๊ฐ๋ฅ
return analyzer.extract_contract_clauses(text)
# ์ฌ๋ฌ ์ฒญํฌ๋ก ๋๋ ์ ์ฒ๋ฆฌ ํ ๋ณํฉ
results = []
for i, chunk in enumerate(chunks):
logger.info(f"์ฒญํฌ {i+1}/{len(chunks)} ๋ถ์ ์ค...")
result = analyzer.extract_contract_clauses(chunk)
results.append(result)
# ๊ฒฐ๊ณผ ๋ณํฉ ๋ก์ง
merged_result = merge_analysis_results(results)
return merged_result
4. ๋ชจ๋ธ ์ ํ ์ ๋ต ๐ฏ๋ชจ๋ ์์ ์ Opus๋ฅผ ์ธ ํ์๋ ์์ด. ์์ ์ ๋ง๋ ๋ชจ๋ธ์ ์ ํํ์!
class AdaptiveAnalyzer:
"""์์
๋ณต์ก๋์ ๋ฐ๋ผ ๋ชจ๋ธ์ ์ ํํ๋ ๋ถ์๊ธฐ"""
def __init__(self):
self.models = {
"simple": "claude-3-haiku-20240307", # ๋น ๋ฅด๊ณ ์ ๋ ด
"standard": "claude-3-sonnet-20240229", # ๊ท ํ์กํ ์ฑ๋ฅ
"complex": "claude-3-opus-20240229" # ์ต๊ณ ์ฑ๋ฅ
}
def estimate_complexity(self, text: str) -> str:
"""๊ณ์ฝ์ ๋ณต์ก๋ ์ถ์ """
# ๊ฐ๋จํ ํด๋ฆฌ์คํฑ
word_count = len(text.split())
# ๋ฒ๋ฅ ์ฉ์ด ๋น๋ ์ฒดํฌ
legal_terms = ["์ํด๋ฐฐ์", "์์ฝ๊ธ", "๋ถ๊ฐํญ๋ ฅ", "์ค์ฌ", "๊ดํ "]
legal_term_count = sum(text.count(term) for term in legal_terms)
# ํ๋ ๋ณต์กํ ๊ตฌ์กฐ ์ฒดํฌ
has_tables = "โ" in text or "โ" in text or "\t" in text
if word_count < 1000 and legal_term_count < 5:
return "simple"
elif word_count > 5000 or legal_term_count > 20 or has_tables:
return "complex"
else:
return "standard"
def analyze(self, text: str) -> Dict:
"""๋ณต์ก๋์ ๋ง๋ ๋ชจ๋ธ๋ก ๋ถ์"""
complexity = self.estimate_complexity(text)
model = self.models[complexity]
logger.info(f"๋ณต์ก๋: {complexity}, ์ฌ์ฉ ๋ชจ๋ธ: {model}")
# ํด๋น ๋ชจ๋ธ๋ก ๋ถ์ ์ํ
analyzer = ClaudeContractAnalyzer()
analyzer.model = model
return analyzer.extract_contract_clauses(text)
โข Haiku ์ฐ์ ์ฌ์ฉ: ๊ฐ๋จํ ์์ ์ Haiku๋ก ์ถฉ๋ถํด (Opus ๋๋น 1/60 ๊ฐ๊ฒฉ!)
โข ํ๋กฌํํธ ์ต์ ํ: ๋ถํ์ํ ์ค๋ช ์ ๊ฑฐ, ๊ฐ๊ฒฐํ๊ฒ ์์ฑ
โข ์บ์ฑ ์ ๊ทน ํ์ฉ: ๊ฐ์ ๋ฌธ์ ์ฌ๋ถ์ ๋ฐฉ์ง
โข ๋ฐฐ์น ์ฒ๋ฆฌ: ์ฌ๋ฌ ๋ฌธ์๋ฅผ ํ ๋ฒ์ ์ฒ๋ฆฌํ ๋ ํจ์จ์
โข ๊ฒฐ๊ณผ ์ฌ์ฌ์ฉ: ํ ๋ฒ ์ถ์ถํ ์ ๋ณด๋ DB์ ์ ์ฅํด์ ์ฌํ์ฉ
๐งช ํ ์คํธ ๋ฐ ํ์ง ๊ด๋ฆฌ
AI ์์คํ
์ ์์ธก ๋ถ๊ฐ๋ฅํ ๋ถ๋ถ์ด ์์ด์ ์ฒ ์ ํ ํ
์คํธ๊ฐ ์ค์ํด! ๐ฌ
ํนํ ๋ฒ๋ฅ ๋ฌธ์ ๊ฐ์ ์ค์ํ ๋ฐ์ดํฐ๋ฅผ ๋ค๋ฃฐ ๋๋ ๋์ฑ ๊ทธ๋.
1. ๋จ์ ํ ์คํธ (Unit Tests)
๊ฐ ํจ์๊ฐ ์ ๋๋ก ๋์ํ๋์ง ํ์ธํด.
import pytest
from document_parser import DocumentParser
def test_pdf_extraction():
"""PDF ํ
์คํธ ์ถ์ถ ํ
์คํธ"""
parser = DocumentParser()
# ํ
์คํธ์ฉ PDF ํ์ผ
test_file = "tests/samples/test_contract.pdf"
text = parser.extract_text(test_file)
assert text is not None
assert len(text) > 100
assert "๊ณ์ฝ" in text or "contract" in text.lower()
def test_text_preprocessing():
"""ํ
์คํธ ์ ์ฒ๋ฆฌ ํ
์คํธ"""
parser = DocumentParser()
raw_text = " ์ด๊ฒ์ ํ
์คํธ ์
๋๋ค. \n\n - 1 - \n\n Page 1 "
processed = parser.preprocess_text(raw_text)
assert " " not in processed # ์ฐ์ ๊ณต๋ฐฑ ์ ๊ฑฐ
assert "- 1 -" not in processed # ํ์ด์ง ๋ฒํธ ์ ๊ฑฐ
assert "Page 1" not in processed
def test_claude_api_connection():
"""Claude API ์ฐ๊ฒฐ ํ
์คํธ"""
analyzer = ClaudeContractAnalyzer()
# ๊ฐ๋จํ ํ
์คํธ ํ
์คํธ
test_text = "๊ฐ๊ณผ ์์ 2024๋
1์ 1์ผ๋ถํฐ 1๋
๊ฐ ๊ณ์ฝํ๋ค."
result = analyzer.extract_contract_clauses(test_text)
assert result is not None
assert "duration" in result
2. ํตํฉ ํ
์คํธ (Integration Tests)์ ์ฒด ์์คํ ์ด ํจ๊ป ์ ๋์ํ๋์ง ํ์ธํด.
from fastapi.testclient import TestClient
from main import app
client = TestClient(app)
def test_full_analysis_workflow():
"""์ ์ฒด ๋ถ์ ์ํฌํ๋ก์ฐ ํ
์คํธ"""
# ํ
์คํธ ํ์ผ ์
๋ก๋
with open("tests/samples/test_contract.pdf", "rb") as f:
response = client.post(
"/api/analyze",
files={"file": ("test.pdf", f, "application/pdf")}
)
assert response.status_code == 200
data = response.json()
assert data["success"] is True
assert "extracted_data" in data
assert "parties" in data["extracted_data"]
def test_batch_processing():
"""๋ฐฐ์น ์ฒ๋ฆฌ ํ
์คํธ"""
files = [
("file", ("test1.pdf", open("tests/samples/test1.pdf", "rb"), "application/pdf")),
("file", ("test2.pdf", open("tests/samples/test2.pdf", "rb"), "application/pdf"))
]
response = client.post("/api/batch-analyze", files=files)
assert response.status_code == 200
data = response.json()
assert data["total_files"] == 2
3. ์ ํ๋ ํ
์คํธ (Accuracy Tests)AI๊ฐ ์ผ๋ง๋ ์ ํํ๊ฒ ์ถ์ถํ๋์ง ์ธก์ ํด.
def test_extraction_accuracy():
"""์ถ์ถ ์ ํ๋ ํ
์คํธ"""
# ์ ๋ต์ด ์๋ ํ
์คํธ ๋ฐ์ดํฐ์
test_cases = [
{
"file": "tests/samples/contract1.pdf",
"expected": {
"parties": {"party_a": "์ฃผ์ํ์ฌ ABC", "party_b": "์ฃผ์ํ์ฌ XYZ"},
"amount": {"total": "1์ต์"},
"duration": {"start_date": "2024-01-01", "end_date": "2024-12-31"}
}
},
# ... ๋ ๋ง์ ํ
์คํธ ์ผ์ด์ค
]
correct_count = 0
total_fields = 0
for case in test_cases:
text = parser.extract_text(case["file"])
result = analyzer.extract_contract_clauses(text)
# ๊ฐ ํ๋ ๋น๊ต
for field, expected_value in case["expected"].items():
total_fields += 1
if result.get(field) == expected_value:
correct_count += 1
accuracy = correct_count / total_fields
print(f"์ ํ๋: {accuracy * 100:.2f}%")
assert accuracy > 0.85 # 85% ์ด์ ์ ํ๋ ์๊ตฌ
4. ์ฑ๋ฅ ํ
์คํธ (Performance Tests)์์คํ ์ด ๋ถํ๋ฅผ ๊ฒฌ๋ ์ ์๋์ง ํ์ธํด.
import time
from locust import HttpUser, task, between
class ContractAnalysisUser(HttpUser):
"""๋ถํ ํ
์คํธ์ฉ ์ฌ์ฉ์ ์๋ฎฌ๋ ์ด์
"""
wait_time = between(1, 3) # ์์ฒญ ๊ฐ 1-3์ด ๋๊ธฐ
@task
def analyze_contract(self):
"""๊ณ์ฝ์ ๋ถ์ ์์ฒญ"""
with open("tests/samples/test_contract.pdf", "rb") as f:
files = {"file": ("test.pdf", f, "application/pdf")}
start_time = time.time()
response = self.client.post("/api/analyze", files=files)
end_time = time.time()
# ์๋ต ์๊ฐ ์ฒดํฌ
response_time = end_time - start_time
if response_time > 30: # 30์ด ์ด์ ๊ฑธ๋ฆฌ๋ฉด ๊ฒฝ๊ณ
print(f"โ ๏ธ ๋๋ฆฐ ์๋ต: {response_time:.2f}์ด")
# ์คํ: locust -f tests/load_test.py --host=http://localhost:8000
โข ํ ์คํธ ๋ฐ์ดํฐ ๊ด๋ฆฌ: ์ค์ ๊ณ์ฝ์๋ฅผ ํ ์คํธ์ ์ฌ์ฉํ๋ฉด ๊ฐ์ธ์ ๋ณด ์ ์ถ ์ํ์ด ์์ด. ์ต๋ช ํ๋ ์ํ ๋ฐ์ดํฐ๋ฅผ ๋ง๋ค์ด์ ์ฌ์ฉํด.
โข CI/CD ํตํฉ: GitHub Actions๋ GitLab CI์ ํ ์คํธ๋ฅผ ํตํฉํด์ ์๋์ผ๋ก ์คํ๋๊ฒ ํด.
โข ์ ๊ธฐ์ ์ธ ์ฌํ ์คํธ: Claude ๋ชจ๋ธ์ด ์ ๋ฐ์ดํธ๋๋ฉด ๊ฒฐ๊ณผ๊ฐ ๋ฌ๋ผ์ง ์ ์์ผ๋ ์ ๊ธฐ์ ์ผ๋ก ์ฌํ ์คํธํด.
๐ ๋ฐฐํฌ ๋ฐ ์ด์
๊ฐ๋ฐ์ด ๋๋ฌ์ผ๋ฉด ์ด์ ์ค์ ์๋น์ค๋ก ๋ฐฐํฌํด์ผ์ง! โ๏ธ
ํด๋ผ์ฐ๋ ํ๋ซํผ์ ํ์ฉํ๋ฉด ์ฝ๊ฒ ๋ฐฐํฌํ๊ณ ๊ด๋ฆฌํ ์ ์์ด.
1. Docker ์ปจํ ์ด๋ํ ๐ณ
์ด๋์๋ ๋์ผํ๊ฒ ์คํ๋๋๋ก Docker๋ก ํจํค์งํ์!
# Dockerfile
FROM python:3.11-slim
WORKDIR /app
# ์์คํ
ํจํค์ง ์ค์น
RUN apt-get update && apt-get install -y \
tesseract-ocr \
tesseract-ocr-kor \
&& rm -rf /var/lib/apt/lists/*
# Python ํจํค์ง ์ค์น
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# ์ ํ๋ฆฌ์ผ์ด์
์ฝ๋ ๋ณต์ฌ
COPY . .
# ํฌํธ ๋
ธ์ถ
EXPOSE 8000
# ์คํ ๋ช
๋ น
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
# docker-compose.yml
version: '3.8'
services:
api:
build: .
ports:
- "8000:8000"
environment:
- ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
- DATABASE_URL=postgresql://user:pass@db:5432/contracts
depends_on:
- db
- redis
volumes:
- ./uploads:/app/uploads
db:
image: postgres:15
environment:
- POSTGRES_DB=contracts
- POSTGRES_USER=user
- POSTGRES_PASSWORD=pass
volumes:
- postgres_data:/var/lib/postgresql/data
redis:
image: redis:7-alpine
ports:
- "6379:6379"
volumes:
postgres_data:
2. AWS ๋ฐฐํฌ (ECS/Fargate) โ๏ธ์๋ฒ๋ฆฌ์ค๋ก ์ฝ๊ฒ ์ค์ผ์ผ๋งํ ์ ์์ด!
# AWS ECS Task Definition (JSON)
{
"family": "contract-analyzer",
"networkMode": "awsvpc",
"requiresCompatibilities": ["FARGATE"],
"cpu": "1024",
"memory": "2048",
"containerDefinitions": [
{
"name": "api",
"image": "your-ecr-repo/contract-analyzer:latest",
"portMappings": [
{
"containerPort": 8000,
"protocol": "tcp"
}
],
"environment": [
{
"name": "ANTHROPIC_API_KEY",
"value": "your-api-key"
}
],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/ecs/contract-analyzer",
"awslogs-region": "ap-northeast-2",
"awslogs-stream-prefix": "ecs"
}
}
}
]
}
3. Kubernetes ๋ฐฐํฌ โ๋๊ท๋ชจ ์ด์์ด ํ์ํ๋ฉด K8s๋ฅผ ์ฌ์ฉํด!
# kubernetes/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: contract-analyzer
spec:
replicas: 3
selector:
matchLabels:
app: contract-analyzer
template:
metadata:
labels:
app: contract-analyzer
spec:
containers:
- name: api
image: your-registry/contract-analyzer:latest
ports:
- containerPort: 8000
env:
- name: ANTHROPIC_API_KEY
valueFrom:
secretKeyRef:
name: api-secrets
key: anthropic-key
resources:
requests:
memory: "1Gi"
cpu: "500m"
limits:
memory: "2Gi"
cpu: "1000m"
---
apiVersion: v1
kind: Service
metadata:
name: contract-analyzer-service
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 8000
selector:
app: contract-analyzer
์ด์ ์ค์๋ ์์คํ ์ํ๋ฅผ ๊ณ์ ๋ชจ๋ํฐ๋งํด์ผ ํด!
# ๋ก๊น
์ค์ (logging_config.py)
import logging
from logging.handlers import RotatingFileHandler
import json
def setup_logging():
"""๊ตฌ์กฐํ๋ ๋ก๊น
์ค์ """
# JSON ํฌ๋งทํฐ
class JsonFormatter(logging.Formatter):
def format(self, record):
log_data = {
"timestamp": self.formatTime(record),
"level": record.levelname,
"message": record.getMessage(),
"module": record.module,
"function": record.funcName
}
if hasattr(record, 'user_id'):
log_data['user_id'] = record.user_id
if record.exc_info:
log_data['exception'] = self.formatException(record.exc_info)
return json.dumps(log_data, ensure_ascii=False)
# ํ์ผ ํธ๋ค๋ฌ (10MB๋ง๋ค ๋กํ
์ด์
)
file_handler = RotatingFileHandler(
'logs/app.log',
maxBytes=10*1024*1024,
backupCount=10
)
file_handler.setFormatter(JsonFormatter())
# ์ฝ์ ํธ๋ค๋ฌ
console_handler = logging.StreamHandler()
console_handler.setFormatter(logging.Formatter(
'%(asctime)s - %(name)s - %(levelname)s - %(message)s'
))
# ๋ฃจํธ ๋ก๊ฑฐ ์ค์
root_logger = logging.getLogger()
root_logger.setLevel(logging.INFO)
root_logger.addHandler(file_handler)
root_logger.addHandler(console_handler)
# ๋ฉํธ๋ฆญ ์์ง (Prometheus)
from prometheus_client import Counter, Histogram, Gauge
import time
# ๋ฉํธ๋ฆญ ์ ์
request_count = Counter('contract_analysis_requests_total', 'Total analysis requests')
request_duration = Histogram('contract_analysis_duration_seconds', 'Analysis duration')
active_analyses = Gauge('contract_analysis_active', 'Currently active analyses')
error_count = Counter('contract_analysis_errors_total', 'Total errors', ['error_type'])
@app.middleware("http")
async def metrics_middleware(request, call_next):
"""๋ฉํธ๋ฆญ ์์ง ๋ฏธ๋ค์จ์ด"""
if request.url.path == "/api/analyze":
request_count.inc()
active_analyses.inc()
start_time = time.time()
try:
response = await call_next(request)
return response
except Exception as e:
error_count.labels(error_type=type(e).__name__).inc()
raise
finally:
duration = time.time() - start_time
request_duration.observe(duration)
active_analyses.dec()
else:
return await call_next(request)
# ํฌ์ค์ฒดํฌ ์๋ํฌ์ธํธ
@app.get("/health")
async def health_check():
"""์์คํ
์ํ ํ์ธ"""
health_status = {
"status": "healthy",
"timestamp": datetime.now().isoformat(),
"checks": {}
}
# Claude API ์ฐ๊ฒฐ ํ์ธ
try:
test_client = anthropic.Anthropic(api_key=os.getenv('ANTHROPIC_API_KEY'))
# ๊ฐ๋จํ ํ
์คํธ ์์ฒญ
health_status["checks"]["claude_api"] = "ok"
except Exception as e:
health_status["checks"]["claude_api"] = f"error: {str(e)}"
health_status["status"] = "degraded"
# ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ฐ๊ฒฐ ํ์ธ
try:
# DB ์ฟผ๋ฆฌ ํ
์คํธ
health_status["checks"]["database"] = "ok"
except Exception as e:
health_status["checks"]["database"] = f"error: {str(e)}"
health_status["status"] = "degraded"
# Redis ์ฐ๊ฒฐ ํ์ธ
try:
redis_client.ping()
health_status["checks"]["redis"] = "ok"
except Exception as e:
health_status["checks"]["redis"] = f"error: {str(e)}"
health_status["status"] = "degraded"
return health_status
โข Slack ํตํฉ: ์๋ฌ ๋ฐ์ ์ Slack ์ฑ๋๋ก ์๋ฆผ
โข ์ด๋ฉ์ผ ์๋ฆผ: ์์คํ ๋ค์ดํ์์ด๋ ์ฌ๊ฐํ ์ค๋ฅ ๋ฐ์ ์
โข PagerDuty: 24/7 ์จ์ฝ ๋์์ด ํ์ํ ๊ฒฝ์ฐ
โข CloudWatch Alarms: AWS ๋ฆฌ์์ค ๋ชจ๋ํฐ๋ง ๋ฐ ์๋ ์๋ฆผ
๐ก ์ค์ ํ์ฉ ์ฌ๋ก ๋ฐ ํ
์ด๋ก ์ ์ถฉ๋ถํ ๋ฐฐ์ ์ผ๋, ์ด์ ์ค์ ๋ก ์ด๋ป๊ฒ ํ์ฉํ๋์ง ์์๋ณด์! ๐ผ
๋ค์ํ ์ฐ์
๊ณผ ์ํฉ์์ ์ด ์์คํ
์ ์ด๋ป๊ฒ ์ ์ฉํ ์ ์์๊น?
1. ๋ฒ๋ฅ ์๋น์ค (๋กํ, ๋ฒ๋ฌด๋ฒ์ธ) โ๏ธ
โข ์ ๊ท ์๋ขฐ์ธ ๊ณ์ฝ์ ์ด๊ธฐ ๊ฒํ ์๋ํ
โข ๊ณ์ฝ์ ์ ํ๋ณ ํ์ค ์กฐํญ ์ค์ ์ฌ๋ถ ์ฒดํฌ
โข ๊ณผ๊ฑฐ ์ ์ฌ ๊ณ์ฝ์์ ๋น๊ต ๋ถ์
โข ์์ก ๊ด๋ จ ๊ณ์ฝ์ ์ฆ๊ฑฐ ์๋ฃ ์ ๋ฆฌ
2. ๋ถ๋์ฐ (์ค๊ฐ, ๊ฐ๋ฐ) ๐๏ธ
โข ์๋์ฐจ ๊ณ์ฝ์ ํต์ฌ ์กฐํญ ์ฆ์ ์ถ์ถ
โข ๋งค๋งค ๊ณ์ฝ์ ํน์ฝ์ฌํญ ์๋ ์ ๋ฆฌ
โข ๋ค์์ ๋ถ์ ๊ณ์ฝ์ ์ผ๊ด ๋ถ์
โข ๊ณ์ฝ ๊ฐฑ์ ์๊ธฐ ์๋ ์๋ฆผ
3. ๊ธฐ์ ๊ตฌ๋งค/์กฐ๋ฌ ๋ถ์ ๐ฆ
โข ๊ณต๊ธ์ ์ฒด ๊ณ์ฝ ์กฐ๊ฑด ๋น๊ต ๋ถ์
โข ๊ตฌ๋งค ๊ณ์ฝ์ ์น์ธ ์ํฌํ๋ก์ฐ ์๋ํ
โข ๊ณ์ฝ ๊ธ์ก ๋ฐ ๋ฉ๊ธฐ ์ผ์ ์ถ์
โข ๊ณ์ฝ ์๋ฐ ์กฐํญ ๋ชจ๋ํฐ๋ง
4. HR/์ธ์ฌํ ๐ฅ
โข ๊ทผ๋ก๊ณ์ฝ์ ํ์ ์กฐํญ ๋๋ฝ ์ฒดํฌ
โข ํด์ง๊ธ, ์ฐ์ฐจ ๋ฑ ๋ณต๋ฆฌํ์ ์กฐ๊ฑด ์ ๋ฆฌ
โข ๋น๋ฐ์ ์ง๊ณ์ฝ(NDA) ์๋ ๊ฒํ
โข ํ๋ฆฌ๋์/๊ณ์ฝ์ง ๊ณ์ฝ ๊ด๋ฆฌ
5. ์คํํธ์ /๋ฒค์ฒ์บํผํ ๐
โข ํฌ์๊ณ์ฝ์(Term Sheet) ํต์ฌ ์กฐ๊ฑด ์ถ์ถ
โข ์ฃผ์ฃผ๊ฐ ๊ณ์ฝ์ ๊ถ๋ฆฌ ์๋ฌด ์ ๋ฆฌ
โข M&A ์ค์ฌ ์ ๋ค์ ๊ณ์ฝ์ ์ ์ ๊ฒํ
โข ๋ผ์ด์ ์ค ๊ณ์ฝ ์กฐ๊ฑด ๋น๊ต
์ฌ๋ฅ๋ท์๋ AI ์๋ํ, ํ๋กฌํํธ ์์ง๋์ด๋ง, ๋ฐฑ์๋ ๊ฐ๋ฐ ๋ฑ ๋ค์ํ ๋ถ์ผ์ ์ ๋ฌธ๊ฐ๋ค์ด ์์ด์:
โข ๋ง์ถคํ ํ๋กฌํํธ ์ค๊ณ ๋ฐ ์ต์ ํ
โข ํน์ ์ฐ์ /์ ์ข ์ ํนํ๋ ์ถ์ถ ๋ก์ง ๊ฐ๋ฐ
โข ๊ธฐ์กด ์์คํ ๊ณผ์ ์ฐ๋ ์์
โข ์ฑ๋ฅ ํ๋ ๋ฐ ๋น์ฉ ์ต์ ํ
ํผ์ ๊ณ ๋ฏผํ์ง ๋ง๊ณ ์ ๋ฌธ๊ฐ์ ๋ ธํ์ฐ๋ฅผ ํ์ฉํด๋ณด์! ๐ค
1. ๊ณ์ฝ์ ํ ํ๋ฆฟ ์๋ ์์ฑ
์ถ์ถํ ์ ๋ณด๋ฅผ ๋ฐํ์ผ๋ก ์ญ์ผ๋ก ๊ณ์ฝ์ ์ด์์ ์์ฑํ ์๋ ์์ด!
def generate_contract_draft(extracted_data: Dict, template_type: str) -> str:
"""์ถ์ถ๋ ์ ๋ณด๋ก ๊ณ์ฝ์ ์ด์ ์์ฑ"""
prompt = f"""๋ค์ ์ ๋ณด๋ฅผ ๋ฐํ์ผ๋ก {template_type} ๊ณ์ฝ์ ์ด์์ ์์ฑํด์ฃผ์ธ์.
๊ณ์ฝ ์ ๋ณด:
{json.dumps(extracted_data, ensure_ascii=False, indent=2)}
ํ๊ตญ ๋ฒ๋ฅ ์ ๋ง๋ ํ์ค ์์์ผ๋ก ์์ฑํ๋, ๋ค์ ์ฌํญ์ ํฌํจํด์ฃผ์ธ์:
- ๊ณ์ฝ ๋น์ฌ์ ์ ๋ณด
- ๊ณ์ฝ์ ๋ชฉ์ ๋ฐ ๋ฒ์
- ๊ณ์ฝ ๊ธฐ๊ฐ ๋ฐ ๊ฐฑ์ ์กฐ๊ฑด
- ๋๊ธ ์ง๊ธ ์กฐ๊ฑด
- ๊ฐ ๋น์ฌ์์ ๊ถ๋ฆฌ์ ์๋ฌด
- ๊ณ์ฝ ํด์ง ์กฐ๊ฑด
- ๋ถ์ ํด๊ฒฐ ๋ฐฉ๋ฒ
- ๊ธฐํ ํ์ํ ์กฐํญ
์ ๋ฌธ์ ์ด๊ณ ๋ช
ํํ ๋ฒ๋ฅ ์ฉ์ด๋ฅผ ์ฌ์ฉํด์ฃผ์ธ์."""
message = client.messages.create(
model="claude-3-opus-20240229", # ๋ฌธ์ ์์ฑ์ Opus ์ถ์ฒ
max_tokens=8000,
messages=[{"role": "user", "content": prompt}]
)
return message.content[0].text
2. ๋ค๊ตญ์ด ๊ณ์ฝ์ ์ง์์๋ฌธ ๊ณ์ฝ์๋ ํ๊ธ๋ก ๋ฒ์ญํ๋ฉด์ ๋์์ ๋ถ์ํ ์ ์์ด!
def analyze_multilingual_contract(text: str, source_lang: str = "auto") -> Dict:
"""๋ค๊ตญ์ด ๊ณ์ฝ์ ๋ถ์ (๋ฒ์ญ + ์ถ์ถ)"""
prompt = f"""๋ค์ ๊ณ์ฝ์๋ฅผ ๋ถ์ํด์ฃผ์ธ์.
์๋ฌธ์ด ํ๊ตญ์ด๊ฐ ์๋๋ผ๋ฉด ๋จผ์ ํ๊ตญ์ด๋ก ๋ฒ์ญํ ํ ๋ถ์ํด์ฃผ์ธ์.
๊ณ์ฝ์ ์๋ฌธ:
{text}
๋ถ์ ๊ฒฐ๊ณผ๋ฅผ ๋ค์ ํ์์ผ๋ก ๋ฐํ:
{{
"detected_language": "๊ฐ์ง๋ ์ธ์ด",
"translation": "ํ๊ตญ์ด ๋ฒ์ญ (ํ์ํ ๊ฒฝ์ฐ)",
"extracted_data": {{
// ์ถ์ถ๋ ๊ณ์ฝ ์ ๋ณด
}}
}}"""
# Claude๋ ๋ค๊ตญ์ด๋ฅผ ์์ฐ์ค๋ฝ๊ฒ ์ฒ๋ฆฌํ ์ ์์ด
message = client.messages.create(
model="claude-3-sonnet-20240229",
max_tokens=8000,
messages=[{"role": "user", "content": prompt}]
)
return json.loads(message.content[0].text)
3. ๊ณ์ฝ์ ๋ฒ์ ๋น๊ต๊ณ์ฝ์๊ฐ ์์ ๋ ๋๋ง๋ค ๋ณ๊ฒฝ์ฌํญ์ ์๋์ผ๋ก ์ถ์ ํด!
def track_contract_changes(original_text: str, revised_text: str) -> Dict:
"""๊ณ์ฝ์ ๋ฒ์ ๊ฐ ๋ณ๊ฒฝ์ฌํญ ์ถ์ """
prompt = f"""๋ค์ ๋ ๋ฒ์ ์ ๊ณ์ฝ์๋ฅผ ๋น๊ตํ์ฌ ๋ณ๊ฒฝ์ฌํญ์ ์์ธํ ๋ถ์ํด์ฃผ์ธ์.
[์๋ณธ ๋ฒ์ ]
{original_text}
[์์ ๋ฒ์ ]
{revised_text}
๋ค์ ํ์์ผ๋ก ๋ณ๊ฒฝ์ฌํญ์ ์ ๋ฆฌ:
{{
"changes": [
{{
"section": "๋ณ๊ฒฝ๋ ์กฐํญ",
"change_type": "added/modified/deleted",
"original": "์๋ณธ ๋ด์ฉ",
"revised": "์์ ๋ ๋ด์ฉ",
"impact": "๋ณ๊ฒฝ์ ์ํฅ๋ (high/medium/low)",
"explanation": "๋ณ๊ฒฝ ์ฌํญ ์ค๋ช
"
}}
],
"summary": "์ ์ฒด ๋ณ๊ฒฝ์ฌํญ ์์ฝ",
"recommendation": "๊ฒํ ๊ถ์ฅ์ฌํญ"
}}"""
message = client.messages.create(
model="claude-3-opus-20240229",
max_tokens=6000,
messages=[{"role": "user", "content": prompt}]
)
return json.loads(message.content[0].text)
4. ๊ณ์ฝ์ Q&A ์ฑ๋ด๊ณ์ฝ์ ๋ด์ฉ์ ๋ํด ์์ฐ์ด๋ก ์ง๋ฌธํ๊ณ ๋ต๋ณ๋ฐ์ ์ ์์ด!
class ContractQABot:
"""๊ณ์ฝ์ ๋ด์ฉ ์ง์์๋ต ๋ด"""
def __init__(self, contract_text: str):
self.contract_text = contract_text
self.conversation_history = []
def ask(self, question: str) -> str:
"""๊ณ์ฝ์์ ๋ํ ์ง๋ฌธ"""
# ๋ํ ์ปจํ
์คํธ ๊ตฌ์ฑ
context = f"""๊ณ์ฝ์ ๋ด์ฉ:
{self.contract_text}
์ ๊ณ์ฝ์๋ฅผ ๋ฐํ์ผ๋ก ์ง๋ฌธ์ ๋ต๋ณํด์ฃผ์ธ์.
๋ต๋ณ์ ๊ณ์ฝ์์ ๋ช
์๋ ๋ด์ฉ์ ๊ทผ๊ฑฐ๋ก ํ๋, ํด๋น ์กฐํญ์ ์ธ์ฉํด์ฃผ์ธ์."""
# ์ด์ ๋ํ ํฌํจ
messages = [{"role": "user", "content": context}]
for qa in self.conversation_history:
messages.append({"role": "user", "content": qa["question"]})
messages.append({"role": "assistant", "content": qa["answer"]})
messages.append({"role": "user", "content": question})
# Claude์๊ฒ ์ง๋ฌธ
response = client.messages.create(
model="claude-3-sonnet-20240229",
max_tokens=2000,
messages=messages
)
answer = response.content[0].text
# ๋ํ ๊ธฐ๋ก ์ ์ฅ
self.conversation_history.append({
"question": question,
"answer": answer
})
return answer
# ์ฌ์ฉ ์์
bot = ContractQABot(contract_text)
answer1 = bot.ask("๊ณ์ฝ ๊ธฐ๊ฐ์ ์ธ์ ๊น์ง์ธ๊ฐ์?")
answer2 = bot.ask("์ค๋ ํด์ง๊ฐ ๊ฐ๋ฅํ๊ฐ์?")
answer3 = bot.ask("์์ฝ๊ธ์ ์ผ๋ง์ธ๊ฐ์?")
๐ ํ์ต ๋ฆฌ์์ค ๋ฐ ๋ค์ ๋จ๊ณ
์ฌ๊ธฐ๊น์ง ์๋ค๋ฉด ์ด๋ฏธ ๊ณ์ฝ์ ์๋์ถ์ถ ๋ด์ ํต์ฌ์ ๋ค ๋ฐฐ์ด ๊ฑฐ์ผ! ๐
ํ์ง๋ง AI ๊ธฐ์ ์ ๊ณ์ ๋ฐ์ ํ๊ณ ์์ผ๋, ์ง์์ ์ธ ํ์ต์ด ์ค์ํด.
๊ณต์ ๋ฌธ์ ๐
โข Anthropic Claude ๊ณต์ ๋ฌธ์: https://docs.anthropic.com
โข FastAPI ๊ณต์ ๋ฌธ์: https://fastapi.tiangolo.com
โข LangChain ๋ฌธ์: https://python.langchain.com
์จ๋ผ์ธ ๊ฐ์ ๐ฅ
โข "LLM์ ํ์ฉํ ์ค์ AI ์ ํ๋ฆฌ์ผ์ด์ ๊ฐ๋ฐ"
โข "ํ๋กฌํํธ ์์ง๋์ด๋ง ๋ง์คํฐ ํด๋์ค"
โข "FastAPI๋ก ๋ง๋๋ ํ๋ก๋์ ๋ ๋ฒจ API"
์ปค๋ฎค๋ํฐ ๐ฅ
โข Anthropic Discord ์ปค๋ฎค๋ํฐ
โข Reddit r/LangChain, r/MachineLearning
โข ํ๊ตญ AI ๊ฐ๋ฐ์ ๋ชจ์
๋ธ๋ก๊ทธ ๋ฐ ์ํฐํด โ๏ธ
โข Anthropic ๊ณต์ ๋ธ๋ก๊ทธ
โข Towards Data Science (Medium)
โข AI ๊ด๋ จ ๊ธฐ์ ๋ธ๋ก๊ทธ๋ค
1๋จ๊ณ: ๊ธฐ๋ณธ ์์คํ ์์ฑ โ
โข PDF/DOCX ํ์ผ์์ ํ ์คํธ ์ถ์ถ
โข Claude API๋ก ์ฃผ์ ์กฐํญ ์ถ์ถ
โข ๊ฐ๋จํ ์น ์ธํฐํ์ด์ค ๊ตฌ์ถ
2๋จ๊ณ: ๊ธฐ๋ฅ ํ์ฅ ๐ง
โข ๋ค์ํ ๊ณ์ฝ์ ์ ํ ์ง์
โข ๋ฆฌ์คํฌ ๋ถ์ ๊ธฐ๋ฅ ์ถ๊ฐ
โข ๊ณ์ฝ์ ๋น๊ต ๊ธฐ๋ฅ ๊ตฌํ
โข ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ฐ๋
3๋จ๊ณ: ํ๋ก๋์ ์ค๋น ๐ญ
โข ๋ณด์ ๊ฐํ (์ธ์ฆ, ์ํธํ)
โข ์ฑ๋ฅ ์ต์ ํ (์บ์ฑ, ๋ฐฐ์น ์ฒ๋ฆฌ)
โข ๋ชจ๋ํฐ๋ง ๋ฐ ๋ก๊น ์์คํ
โข ์๋ํ๋ ํ ์คํธ ๊ตฌ์ถ
4๋จ๊ณ: ๊ณ ๋ํ ๐
โข AI ์์ด์ ํธ๋ก ๋ฐ์ (์์จ์ ์์ฌ๊ฒฐ์ )
โข ๋ค๋ฅธ ์์คํ ๊ณผ ํตํฉ (ERP, CRM)
โข ๋ชจ๋ฐ์ผ ์ฑ ๊ฐ๋ฐ
โข ์์ฑ ์ธํฐํ์ด์ค ์ถ๊ฐ
5๋จ๊ณ: ๋น์ฆ๋์คํ ๐ผ
โข SaaS ์ ํ์ผ๋ก ์ถ์
โข API ์๋น์ค ์ ๊ณต
โข ์ฐ์ ๋ณ ํนํ ๋ฒ์ ๊ฐ๋ฐ
โข ํํธ๋์ญ ๋ฐ B2B ์์
2. ์ ์ง์ ๊ฐ์ : ์ฒ์๋ถํฐ ์๋ฒฝํ ์ ์์ด. ์๊ฒ ์์ํด์ ๊ณ์ ๋ฐ์ ์์ผ.
3. ๋๋ฉ์ธ ์ง์: ๋ฒ๋ฅ , ๊ณ์ฝ ๊ด๋ จ ์ ๋ฌธ ์ง์์ ์์ผ๋ฉด ๋ ์ข์ ์์คํ ์ ๋ง๋ค ์ ์์ด.
4. ๋น์ฉ ๊ด๋ฆฌ: Claude API ๋น์ฉ์ ํญ์ ๋ชจ๋ํฐ๋งํ๊ณ ์ต์ ํํด.
5. ๋ณด์ ์ฐ์ : ๋ฏผ๊ฐํ ์ ๋ณด๋ฅผ ๋ค๋ฃจ๋๊น ๋ณด์์ ์ ๋ ํํํ์ง ๋ง.
6. ๋ฌธ์ํ: ์ฝ๋์ ์์คํ ์ ์ ๋ฌธ์ํํด๋๋ฉด ๋์ค์ ์ ์ง๋ณด์๊ฐ ํจ์ฌ ์ฌ์.
7. ์ปค๋ฎค๋ํฐ ํ์ฉ: ํผ์ ๊ณ ๋ฏผํ์ง ๋ง๊ณ ์ปค๋ฎค๋ํฐ์์ ๋์์ ๊ตฌํด.
๐ฌ ๋ง๋ฌด๋ฆฌํ๋ฉฐ
์! ์ฌ๊ธฐ๊น์ง ์ ๋ง ๊ธด ์ฌ์ ์ด์์ด. ๐
๊ณ์ฝ์ ์๋์ถ์ถ ๋ด์ ๋ง๋๋ ์ ๊ณผ์ ์ ํจ๊ป ์ดํด๋ดค๋๋ฐ, ์ด๋? ์๊ฐ๋ณด๋ค ์ด๋ ต์ง ์์ง? ๐
Claude ๊ฐ์ ๊ฐ๋ ฅํ AI ๋ชจ๋ธ ๋๋ถ์, ์์ ์๋ ์์๋ ๋ชปํ๋ ์๋ํ๊ฐ ๊ฐ๋ฅํด์ก์ด.
์์ญ ํ์ด์ง์ ๋ณต์กํ ๊ณ์ฝ์๋ฅผ ๋ช ์ด ๋ง์ ๋ถ์ํ๊ณ , ํต์ฌ ์ ๋ณด๋ฅผ ๊น๋ํ๊ฒ ์ ๋ฆฌํด์ฃผ๋ ์์คํ
์
์ด์ ๋๊ตฌ๋ ๋ง๋ค ์ ์๊ฒ ๋ ๊ฑฐ์ผ. ์ ๋ง ๋๋ผ์ด ์๋์ ์ด๊ณ ์๋ ๊ฑฐ์ง! ๐
๋ฌผ๋ก ์ฒ์๋ถํฐ ์๋ฒฝํ ์์คํ
์ ๋ง๋ค ์ ์์ด.
ํ์ง๋ง ์ด ๊ธ์์ ๋ฐฐ์ด ๋ด์ฉ์ ๋ฐํ์ผ๋ก ํ๋์ฉ ๊ตฌํํด๋๊ฐ๋ค ๋ณด๋ฉด,
์ด๋์ ์ค๋ฌด์์ ์ ๋ง ์ ์ฉํ๊ฒ ์ธ ์ ์๋ ๋๊ตฌ๊ฐ ์์ฑ๋ ๊ฑฐ์ผ. ๐ช
ํนํ ๋ฒ๋ฌดํ, ๊ตฌ๋งคํ, HRํ์ฒ๋ผ ๊ณ์ฝ์๋ฅผ ์์ฃผ ๋ค๋ฃจ๋ ๋ถ์์์๋
์ด๋ฐ ์๋ํ ์์คํ
์ด ์ ๋ง ํฐ ๋์์ด ๋ ๊ฑฐ์ผ.
๋ฐ๋ณต์ ์ด๊ณ ์ง๋ฃจํ ์์
์์ ํด๋ฐฉ๋์ด, ๋ ์ค์ํ ์์ฌ๊ฒฐ์ ์ ์ง์คํ ์ ์๊ฒ ๋๋๊น! ๐ฏ
ํน์ ๊ตฌํํ๋ค๊ฐ ๋งํ๋ ๋ถ๋ถ์ด ์๊ฑฐ๋, ๋ ๊ณ ๊ธ ๊ธฐ๋ฅ์ด ํ์ํ๋ค๋ฉด
์ฌ๋ฅ๋ท์์ ์ ๋ฌธ๊ฐ๋ค์ ๋์์ ๋ฐ์๋ณด๋ ๊ฒ๋ ์ข์ ๋ฐฉ๋ฒ์ด์ผ.
AI ์๋ํ ๋ถ์ผ๋ ๋น ๋ฅด๊ฒ ๋ฐ์ ํ๊ณ ์์ด์, ์ต์ ํธ๋ ๋๋ฅผ ์๋ ์ ๋ฌธ๊ฐ์ ์กฐ์ธ์ด ํฐ ๋์์ด ๋ ๊ฑฐ์ผ! ๐ค
์, ์ด์ ๋น์ ์ฐจ๋ก์ผ!
์ด ๊ธ์ ์ฝ๊ธฐ๋ง ํ์ง ๋ง๊ณ , ์ง์ ์ฝ๋๋ฅผ ์์ฑํด๋ณด๊ณ , ์คํํด๋ณด๊ณ , ์คํจ๋ ํด๋ณด๋ฉด์
๋๋ง์ ๊ณ์ฝ์ ์๋์ถ์ถ ๋ด์ ๋ง๋ค์ด๋ด. ๐ป
์์์ด ๋ฐ์ด๋ผ๊ณ ํ์์?
์ง๊ธ ๋ฐ๋ก ํฐ๋ฏธ๋์ ์ด๊ณ pip install anthropic๋ถํฐ ์ณ๋ณด์! ๐
ํ์ด์ ๋น์ด! ํ์ดํ
! ๐ชโจ
๊ด๋ จ ํค์๋
๋๊ธ ์์ฑ
์ด ๊ธ์ ๋ํ ์ฌ๋ฌ๋ถ์ ์๊ฐ์ ๋ค๋ ค์ฃผ์ธ์
๋ก๊ทธ์ธ์ด ํ์ํฉ๋๋ค
๋๊ธ์ ์์ฑํ๋ ค๋ฉด ๋จผ์ ๋ก๊ทธ์ธํด์ฃผ์ธ์.
๋๊ธ 0
์ง์์ธ์ ์ฒ - ์ง์ ์ฌ์ฐ๊ถ ๋ณดํธ ๊ณ ์ง
์ง์ ์ฌ์ฐ๊ถ ๋ณดํธ ๊ณ ์ง
- ์ ์๊ถ ๋ฐ ์์ ๊ถ: ๋ณธ ์ปจํ ์ธ ๋ ์ฌ๋ฅ๋ท์ ๋ ์ AI ๊ธฐ์ ๋ก ์์ฑ๋์์ผ๋ฉฐ, ๋ํ๋ฏผ๊ตญ ์ ์๊ถ๋ฒ ๋ฐ ๊ตญ์ ์ ์๊ถ ํ์ฝ์ ์ํด ๋ณดํธ๋ฉ๋๋ค.
- AI ์์ฑ ์ปจํ ์ธ ์ ๋ฒ์ ์ง์: ๋ณธ AI ์์ฑ ์ปจํ ์ธ ๋ ์ฌ๋ฅ๋ท์ ์ง์ ์ฐฝ์๋ฌผ๋ก ์ธ์ ๋๋ฉฐ, ๊ด๋ จ ๋ฒ๊ท์ ๋ฐ๋ผ ์ ์๊ถ ๋ณดํธ๋ฅผ ๋ฐ์ต๋๋ค.
- ์ฌ์ฉ ์ ํ: ์ฌ๋ฅ๋ท์ ๋ช ์์ ์๋ฉด ๋์ ์์ด ๋ณธ ์ปจํ ์ธ ๋ฅผ ๋ณต์ , ์์ , ๋ฐฐํฌ, ๋๋ ์์ ์ ์ผ๋ก ํ์ฉํ๋ ํ์๋ ์๊ฒฉํ ๊ธ์ง๋ฉ๋๋ค.
- ๋ฐ์ดํฐ ์์ง ๊ธ์ง: ๋ณธ ์ปจํ ์ธ ์ ๋ํ ๋ฌด๋จ ์คํฌ๋ํ, ํฌ๋กค๋ง, ๋ฐ ์๋ํ๋ ๋ฐ์ดํฐ ์์ง์ ๋ฒ์ ์ ์ฌ์ ๋์์ด ๋ฉ๋๋ค.
- AI ํ์ต ์ ํ: ์ฌ๋ฅ๋ท์ AI ์์ฑ ์ปจํ ์ธ ๋ฅผ ํ AI ๋ชจ๋ธ ํ์ต์ ๋ฌด๋จ ์ฌ์ฉํ๋ ํ์๋ ๊ธ์ง๋๋ฉฐ, ์ด๋ ์ง์ ์ฌ์ฐ๊ถ ์นจํด๋ก ๊ฐ์ฃผ๋ฉ๋๋ค.
์์ง ๋๊ธ์ด ์์ต๋๋ค.