개요

Promptify는 NLP 태스크를 위한 프롬프트 기반 추론을 쉽게 구현할 수 있는 Python 라이브러리. 텍스트 분류·NER·감정 분석 등을 LLM으로 처리할 때 프롬프트 템플릿을 관리.


주요 기능

기능설명
NLP 파이프라인분류·NER·요약·번역 등 사전 구성
프롬프트 템플릿태스크별 최적화된 프롬프트 관리
다중 LLM 지원OpenAI, GPT 계열
구조화된 출력JSON 형태 파싱 지원

설치

pip install promptify

사용 예시

from promptify import OpenAI, Prompter
 
# OpenAI 모델 설정
model = OpenAI(api_key="your-api-key")
nlp_prompter = Prompter(model)
 
# NER (개체명 인식)
sentence = "Barack Obama was born in Hawaii and was the 44th president of the United States."
result = nlp_prompter.fit(
    'ner.jinja',
    domain='General',
    text_input=sentence,
    labels=['Person', 'Location', 'Organization']
)
print(result)
# [{"E": "Barack Obama", "T": "Person"}, {"E": "Hawaii", "T": "Location"}, ...]
 
# 감정 분석
result = nlp_prompter.fit(
    'sentiment.jinja',
    text_input="I love this product! Amazing quality.",
    labels=['Positive', 'Negative', 'Neutral']
)
 
# 텍스트 분류
result = nlp_prompter.fit(
    'classification.jinja',
    text_input="주식 시장이 오늘 큰 폭으로 하락했습니다.",
    labels=['Finance', 'Sports', 'Technology', 'Politics']
)

커스텀 템플릿 (Jinja2)

{# custom_ner.jinja #}
You are an expert Named Entity Recognition system.
 
Extract entities from the following text and return as JSON array.
Labels: {{ labels | join(', ') }}
 
Text: {{ text_input }}
 
Return format:
[{"entity": "entity_name", "type": "entity_type"}]
result = nlp_prompter.fit(
    'custom_ner.jinja',
    text_input="삼성전자가 새로운 AI 칩을 발표했습니다.",
    labels=['Company', 'Product', 'Technology']
)

대안 비교

도구특징
PromptifyNLP 태스크 특화, 템플릿 관리
LangChain범용 LLM 파이프라인, 에이전트
LlamaIndexRAG, 문서 검색 특화
Outlines구조화된 출력 생성
InstructorPydantic 기반 구조화 출력

주의사항

  • 현재(2025) 활발한 유지보수가 이루어지지 않을 수 있음
  • OpenAI API 버전 변경 시 호환성 확인 필요
  • 복잡한 파이프라인은 LangChain이 더 적합

관련 항목