Skip to content

Commit fde5dda

Browse files
leebeanbincursoragent
andcommitted
refactor: modularity P1-P3
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent f6ae936 commit fde5dda

105 files changed

Lines changed: 1740 additions & 1737 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/beanllm/__init__.py

Lines changed: 2 additions & 378 deletions
Large diffs are not rendered by default.

src/beanllm/_lazy_imports.py

Lines changed: 384 additions & 0 deletions
Large diffs are not rendered by default.

src/beanllm/domain/audio/engines/canary_engine.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@
1919
pip install transformers torch torchaudio nemo_toolkit
2020
"""
2121

22-
import logging
2322
import time
2423
from pathlib import Path
2524
from typing import Dict, Union
2625

2726
import numpy as np
2827

2928
from beanllm.domain.audio.models import STTConfig
29+
from beanllm.utils.logging import get_logger
3030

3131
from .base import BaseSTTEngine
3232

33-
logger = logging.getLogger(__name__)
33+
logger = get_logger(__name__)
3434

3535
# NeMo toolkit 설치 여부 체크
3636
try:

src/beanllm/domain/audio/engines/distil_whisper_engine.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@
1515
pip install transformers torch torchaudio
1616
"""
1717

18-
import logging
1918
import time
2019
from pathlib import Path
2120
from typing import Dict, Union
2221

2322
import numpy as np
2423

2524
from beanllm.domain.audio.models import STTConfig
25+
from beanllm.utils.logging import get_logger
2626

2727
from .base import BaseSTTEngine
2828

29-
logger = logging.getLogger(__name__)
29+
logger = get_logger(__name__)
3030

3131
# transformers 설치 여부 체크
3232
try:

src/beanllm/domain/audio/engines/granite_engine.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@
2323
pip install transformers torch torchaudio
2424
"""
2525

26-
import logging
2726
import time
2827
from pathlib import Path
2928
from typing import Dict, Union
3029

3130
import numpy as np
3231

3332
from beanllm.domain.audio.models import STTConfig
33+
from beanllm.utils.logging import get_logger
3434

3535
from .base import BaseSTTEngine
3636

37-
logger = logging.getLogger(__name__)
37+
logger = get_logger(__name__)
3838

3939
# transformers 설치 여부 체크
4040
try:

src/beanllm/domain/audio/engines/moonshine_engine.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@
2121
pip install transformers torch torchaudio
2222
"""
2323

24-
import logging
2524
import time
2625
from pathlib import Path
2726
from typing import Dict, Union
2827

2928
import numpy as np
3029

3130
from beanllm.domain.audio.models import STTConfig
31+
from beanllm.utils.logging import get_logger
3232

3333
from .base import BaseSTTEngine
3434

35-
logger = logging.getLogger(__name__)
35+
logger = get_logger(__name__)
3636

3737
# transformers 설치 여부 체크
3838
try:

src/beanllm/domain/audio/engines/parakeet_engine.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@
1515
pip install transformers torch torchaudio nemo_toolkit
1616
"""
1717

18-
import logging
1918
import time
2019
from pathlib import Path
2120
from typing import Dict, Union
2221

2322
import numpy as np
2423

2524
from beanllm.domain.audio.models import STTConfig
25+
from beanllm.utils.logging import get_logger
2626

2727
from .base import BaseSTTEngine
2828

29-
logger = logging.getLogger(__name__)
29+
logger = get_logger(__name__)
3030

3131
# NeMo toolkit 설치 여부 체크
3232
try:

src/beanllm/domain/audio/engines/sensevoice_engine.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,18 @@
3030
pip install funasr modelscope torch torchaudio
3131
"""
3232

33-
import logging
3433
import time
3534
from pathlib import Path
3635
from typing import Dict, Union
3736

3837
import numpy as np
3938

4039
from beanllm.domain.audio.models import STTConfig
40+
from beanllm.utils.logging import get_logger
4141

4242
from .base import BaseSTTEngine
4343

44-
logger = logging.getLogger(__name__)
44+
logger = get_logger(__name__)
4545

4646
# FunASR 설치 여부 체크
4747
try:

src/beanllm/domain/audio/engines/whisper_engine.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@
1515
pip install transformers torch torchaudio
1616
"""
1717

18-
import logging
1918
import time
2019
from pathlib import Path
2120
from typing import Dict, Union
2221

2322
import numpy as np
2423

2524
from beanllm.domain.audio.models import STTConfig
25+
from beanllm.utils.logging import get_logger
2626

2727
from .base import BaseSTTEngine
2828

29-
logger = logging.getLogger(__name__)
29+
logger = get_logger(__name__)
3030

3131
# transformers 설치 여부 체크
3232
try:
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
"""
2+
DeepEval Metrics - 메트릭 생성 및 설정
3+
4+
DeepEval 메트릭의 팩토리 로직과 설정 상수를 제공합니다.
5+
deepeval_wrapper.py에서 평가 실행 시 이 모듈을 사용합니다.
6+
"""
7+
8+
from typing import Any, Dict, Type
9+
10+
# DeepEval 메트릭 이름 → 설명 (list_tasks 등에서 사용)
11+
DEEPEVAL_METRIC_DESCRIPTIONS: Dict[str, str] = {
12+
"answer_relevancy": "답변이 질문과 얼마나 관련있는지",
13+
"faithfulness": "답변이 컨텍스트에 충실한지 (Hallucination 방지)",
14+
"contextual_precision": "검색된 컨텍스트의 정밀도",
15+
"contextual_recall": "검색된 컨텍스트의 재현율",
16+
"hallucination": "환각 감지",
17+
"toxicity": "독성 평가",
18+
"bias": "편향 평가",
19+
"summarization": "요약 품질",
20+
"geval": "커스텀 평가 기준",
21+
}
22+
23+
24+
def get_deepeval_metric_map() -> Dict[str, Type[Any]]:
25+
"""
26+
DeepEval 메트릭 클래스 매핑 반환.
27+
28+
Returns:
29+
metric_name → Metric class 매핑
30+
"""
31+
from deepeval.metrics import ( # type: ignore[import-untyped]
32+
AnswerRelevancyMetric,
33+
BiasMetric,
34+
ContextualPrecisionMetric,
35+
ContextualRecallMetric,
36+
FaithfulnessMetric,
37+
GEval,
38+
HallucinationMetric,
39+
SummarizationMetric,
40+
ToxicityMetric,
41+
)
42+
43+
return {
44+
"answer_relevancy": AnswerRelevancyMetric,
45+
"faithfulness": FaithfulnessMetric,
46+
"contextual_precision": ContextualPrecisionMetric,
47+
"contextual_recall": ContextualRecallMetric,
48+
"hallucination": HallucinationMetric,
49+
"toxicity": ToxicityMetric,
50+
"bias": BiasMetric,
51+
"summarization": SummarizationMetric,
52+
"geval": GEval,
53+
}
54+
55+
56+
def create_deepeval_metric(
57+
metric_name: str,
58+
model: str = "gpt-4o-mini",
59+
threshold: float = 0.5,
60+
include_reason: bool = True,
61+
async_mode: bool = True,
62+
**kwargs: Any,
63+
) -> Any:
64+
"""
65+
DeepEval 메트릭 인스턴스 생성.
66+
67+
Args:
68+
metric_name: 메트릭 이름 (answer_relevancy, faithfulness 등)
69+
model: LLM 모델
70+
threshold: 통과 임계값
71+
include_reason: 평가 이유 포함 여부
72+
async_mode: 비동기 모드 사용
73+
**kwargs: 메트릭별 추가 파라미터
74+
75+
Returns:
76+
DeepEval Metric 인스턴스
77+
78+
Raises:
79+
ImportError: deepeval 미설치 시
80+
ValueError: 알 수 없는 메트릭 이름
81+
"""
82+
metric_map = get_deepeval_metric_map()
83+
84+
if metric_name not in metric_map:
85+
raise ValueError(f"Unknown metric: {metric_name}. Available: {list(metric_map.keys())}")
86+
87+
metric_class = metric_map[metric_name]
88+
89+
return metric_class(
90+
model=model,
91+
threshold=threshold,
92+
include_reason=include_reason,
93+
async_mode=async_mode,
94+
**kwargs,
95+
)

0 commit comments

Comments
 (0)