Skip to main content

Korean prompt compressor with semantic preservation guard

Project description

ko-prompt-compressor

한국어 프롬프트 압축기. LLM 토큰 비용 절감을 위해 의미를 보존하면서 프롬프트를 압축합니다.

특징

  • LLM 압축 (기본): GGUF 모델로 30~50% 압축, 의미 보존 가드 내장
  • 규칙+형태소 fallback: LLM 없이도 동작 (kiwipiepy)
  • 의미 보존 검증: 임베딩 유사도로 품질 게이트 (선택)
  • 환경 자동 감지: GPU/CPU/RAM에 맞는 모델·로드 방식 추천

설치

pip install ko-prompt-compressor
ko-compress setup  # 모델 선택 및 다운로드

setup 실행 시 환경(CPU/GPU/RAM)을 감지하고 최적 모델을 추천합니다.

선택적 의존성

pip install ko-prompt-compressor[kiwi]    # 형태소 fallback (kiwipiepy)
pip install ko-prompt-compressor[verify]  # 의미 보존 검증 (sentence-transformers)
pip install ko-prompt-compressor[all]     # 전부

사용법

CLI

ko-compress "회의 참석 부탁드립니다. 감사합니다."
# → 회의 참석 부탁.
# [OK|llm/gemma4] 12→5 tok (58.3% 절약)

ko-compress "텍스트" --json       # JSON 출력
ko-compress --ratio 0.5 "텍스트"  # 목표 50% 유지

Python API

from ko_prompt_compressor import compress

result = compress("Redis로 분산 락 구현하려는데, TTL 만료 후 남의 락을 실수로 푸는 문제 어떻게 해결해")
print(result.text)    # Redis 분산 락. TTL 만료 후 타인 락 잘못 해제 해결법?
print(result.method)  # llm/gemma4
print(result.success) # True

지원 모델

모델 크기 품질 추천 환경
gemma4-E2B Q4 ~3.5GB 최고 (78% guard pass) RAM 8GB+
Qwen3-1.7B Q4 ~1.0GB 보통 RAM 4~8GB
Qwen3-0.6B Q4 ~0.4GB 기본 RAM < 4GB

GPU(CUDA/Apple Silicon) 감지 시 자동으로 GPU 가속 적용.

압축 파이프라인

입력
 └→ LLM 압축 (GGUF + ko-rules-v3-en 프롬프트)
     └→ critical_guard (의미 손실 veto)
         └→ [성공] 출력
         └→ [실패] fallback: rules + kiwi 형태소 압축
             └→ passthrough (압축 불가 시 원문 반환)

설정

ko-compress setup 결과는 ~/.ko_compress/config.json에 저장됩니다.

{
  "model": "gemma4",
  "n_gpu_layers": -1,
  "verify": false
}

요구사항

  • Python 3.10+
  • llama-cpp-python (LLM 압축, CPU pre-built wheel 제공)
  • kiwipiepy (선택, fallback 품질 향상)
  • sentence-transformers + torch (선택, 의미 검증)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ko_prompt_compressor-0.1.0-py3-none-any.whl (33.9 kB view details)

Uploaded Python 3

File details

Details for the file ko_prompt_compressor-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ko_prompt_compressor-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 716b9b649c2fcede283ea581085ac31bede754502075e03ef3141448ff41cc0b
MD5 a9315b22655b0058cd9dae2047b631a2
BLAKE2b-256 eeecae5b67a9d1e5dcfbb351658e7bd4aefa59b43512657bbb48e7884f32da26

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page