Initial commit: O2O 저작권 침해 여부 탐지 API
PDF v1.2 요구사항 반영 완료: - 10종 법령 메타 태그 + 39개 케이스 분류체계 - 3단 캐스케이딩: MinHash+LSH → 삼중 유사도 → 분류 - 자서전 특화: 공통 표현 사전 제거 + NER 마스킹 - KoSimCSE 한국어 임베딩 (자체 산출물 방어) - 보수적 임계값 0.85 - 검토 콘솔 UI (탐지 + 코퍼스 관리 탭) - Docker 배포 패키지 + 31개 테스트 통과
This commit is contained in:
commit
3b69bdf0f0
50 files changed
+4662
No files matched your search
Whitespace-only changes.
@@ -0,0 +1,13 @@
|
||||
from fastapi import Header, HTTPException, status
|
||||
|
||||
from app.core.config import get_settings
|
||||
|
||||
|
||||
async def require_api_key(x_api_key: str | None = Header(default=None)) -> str:
|
||||
settings = get_settings()
|
||||
if not x_api_key or x_api_key not in settings.api_key_set:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="Invalid or missing X-API-Key header",
|
||||
)
|
||||
return x_api_key
|
||||
@@ -0,0 +1,65 @@
|
||||
from functools import lru_cache
|
||||
from pathlib import Path
|
||||
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8", extra="ignore")
|
||||
|
||||
api_keys: str = "combooks-key-change-me,baikal-key-change-me"
|
||||
engine_version: str = "o2o-plagiarism-2.0.0-pdf-v1.2"
|
||||
reference_corpus_dir: str = "./data/reference"
|
||||
taxonomy_dir: str = "./data/taxonomy"
|
||||
autobiography_patterns_path: str = "./data/autobiography/common_patterns.txt"
|
||||
|
||||
# PDF VII-4 권장: 정밀도 우선 보수적 임계값
|
||||
similarity_threshold: float = 0.85
|
||||
|
||||
# KoSimCSE / KoSBERT (PDF VII-3 권장) - 한국어 오픈소스 임베딩
|
||||
use_kosimcse: bool = True
|
||||
kosimcse_model: str = "BM-K/KoSimCSE-roberta-multitask"
|
||||
kosimcse_max_length: int = 512
|
||||
|
||||
# OpenAI (옵션 - 자체 모델 없을 때 폴백)
|
||||
openai_api_key: str = ""
|
||||
openai_extraction_model: str = "gpt-4o-mini"
|
||||
openai_embedding_model: str = "text-embedding-3-small"
|
||||
use_llm_extractor: bool = False
|
||||
use_embedding_similarity: bool = False
|
||||
|
||||
# 삼중 유사도 가중치 (실측 기반)
|
||||
weight_text_sim: float = 0.30
|
||||
weight_lemma_sim: float = 0.45
|
||||
weight_char_sim: float = 0.15
|
||||
weight_motif_sim: float = 0.10
|
||||
|
||||
# PDF VII-3 캐스케이딩
|
||||
use_lsh_filter: bool = True
|
||||
lsh_threshold: float = 0.3 # 1차 필터는 느슨하게 (재현율 우선)
|
||||
lsh_top_k: int = 50
|
||||
|
||||
# PDF VII-4 자서전 모드
|
||||
autobiography_mode: bool = True
|
||||
enable_entity_masking: bool = True
|
||||
|
||||
@property
|
||||
def api_key_set(self) -> set[str]:
|
||||
return {k.strip() for k in self.api_keys.split(",") if k.strip()}
|
||||
|
||||
@property
|
||||
def corpus_path(self) -> Path:
|
||||
return Path(self.reference_corpus_dir).resolve()
|
||||
|
||||
@property
|
||||
def taxonomy_path(self) -> Path:
|
||||
return Path(self.taxonomy_dir).resolve()
|
||||
|
||||
@property
|
||||
def has_openai(self) -> bool:
|
||||
return bool(self.openai_api_key.strip())
|
||||
|
||||
|
||||
@lru_cache
|
||||
def get_settings() -> Settings:
|
||||
return Settings()
|
||||
Reference in new issue
Block a user