|
6 | 6 | import logging |
7 | 7 |
|
8 | 8 | from macaron.ai.clients.ai_factory import AIClientFactory |
| 9 | +from macaron.config.defaults import defaults |
9 | 10 | from macaron.errors import HeuristicAnalyzerValueError |
10 | 11 | from macaron.json_tools import JsonType, json_extract |
11 | 12 | from macaron.malware_analyzer.pypi_heuristics.base_analyzer import BaseHeuristicAnalyzer |
@@ -35,8 +36,6 @@ class InconsistentDescriptionAnalyzer(BaseHeuristicAnalyzer): |
35 | 36 | } |
36 | 37 | """ |
37 | 38 |
|
38 | | - THRESHOLD = 60 |
39 | | - |
40 | 39 | RESPONSE_FORMAT = { |
41 | 40 | "type": "json_schema", |
42 | 41 | "json_schema": { |
@@ -65,9 +64,18 @@ def __init__(self) -> None: |
65 | 64 | super().__init__( |
66 | 65 | name="inconsistent_description_analyzer", heuristic=Heuristics.INCONSISTENT_DESCRIPTION, depends_on=None |
67 | 66 | ) |
| 67 | + self.threshold = self._load_defaults() |
68 | 68 | factory = AIClientFactory() |
69 | 69 | self.client = factory.create_client(self.SYSTEM_PROMPT.strip()) |
70 | 70 |
|
| 71 | + def _load_defaults(self) -> int: |
| 72 | + """Load the default values from defaults.ini.""" |
| 73 | + section_name = "heuristic.pypi" |
| 74 | + if defaults.has_section(section_name): |
| 75 | + section = defaults[section_name] |
| 76 | + return section.getint("score_threshold", 70) |
| 77 | + return 70 |
| 78 | + |
71 | 79 | def analyze(self, pypi_package_json: PyPIPackageJsonAsset) -> tuple[HeuristicResult, dict[str, JsonType]]: |
72 | 80 | """Analyze the package. |
73 | 81 |
|
@@ -100,7 +108,7 @@ def analyze(self, pypi_package_json: PyPIPackageJsonAsset) -> tuple[HeuristicRes |
100 | 108 | response_format=self.RESPONSE_FORMAT, |
101 | 109 | ) |
102 | 110 |
|
103 | | - if analysis_result["score"] < self.THRESHOLD: |
| 111 | + if analysis_result["score"] < self.threshold: |
104 | 112 | return HeuristicResult.FAIL, { |
105 | 113 | "message": f"inconsistent description with score {analysis_result['score']}. because {analysis_result['reason']}" |
106 | 114 | } |
|
0 commit comments