From 2ee7fe3497525f0cdaa4ad619639ee828d6d7db0 Mon Sep 17 00:00:00 2001 From: I748376 Date: Mon, 24 Jun 2024 10:06:45 +0000 Subject: [PATCH] sets default enabled rules to phase 1 rules --- prospector/core/prospector.py | 4 ++-- prospector/llm/models/gemini.py | 1 + prospector/llm/models/mistral.py | 1 + prospector/llm/models/openai.py | 4 ++-- prospector/rules/rules.py | 28 +--------------------------- 5 files changed, 7 insertions(+), 31 deletions(-) diff --git a/prospector/core/prospector.py b/prospector/core/prospector.py index b92e53b7d..d1dc9c865 100644 --- a/prospector/core/prospector.py +++ b/prospector/core/prospector.py @@ -20,7 +20,7 @@ from git.version_to_tag import get_possible_tags from llm.llm_service import LLMService from log.logger import get_level, logger, pretty_log -from rules.rules import apply_rules +from rules.rules import RULES_PHASE_1, apply_rules from stats.execution import ( Counter, ExecutionTimer, @@ -66,7 +66,7 @@ def prospector( # noqa: C901 use_backend: str = USE_BACKEND_ALWAYS, git_cache: str = "/tmp/git_cache", limit_candidates: int = MAX_CANDIDATES, - enabled_rules: List[str] = [], + enabled_rules: List[str] = [rule.id for rule in RULES_PHASE_1], tag_commits: bool = True, silent: bool = False, use_llm_repository_url: bool = False, diff --git a/prospector/llm/models/gemini.py b/prospector/llm/models/gemini.py index 147086254..ab8135729 100644 --- a/prospector/llm/models/gemini.py +++ b/prospector/llm/models/gemini.py @@ -60,6 +60,7 @@ def _call( try: response = requests.post(endpoint, headers=headers, json=data) + response.raise_for_status() return self.parse(response.json()) except requests.exceptions.HTTPError as http_error: logger.error( diff --git a/prospector/llm/models/mistral.py b/prospector/llm/models/mistral.py index 9708d8e31..42a90dcc3 100644 --- a/prospector/llm/models/mistral.py +++ b/prospector/llm/models/mistral.py @@ -41,6 +41,7 @@ def _call( try: response = requests.post(endpoint, headers=headers, json=data) + response.raise_for_status() return self.parse(response.json()) except requests.exceptions.HTTPError as http_error: logger.error( diff --git a/prospector/llm/models/openai.py b/prospector/llm/models/openai.py index e34b647e0..ae78fbc28 100644 --- a/prospector/llm/models/openai.py +++ b/prospector/llm/models/openai.py @@ -30,8 +30,7 @@ def _identifying_params(self) -> Dict[str, Any]: def _call( self, prompt: str, stop: Optional[List[str]] = None, **kwargs: Any ) -> str: - # endpoint = f"{self.deployment_url}/chat/completions?api-version=2023-05-15" - endpoint = f"{self.deployment_url}/chat/cpletions?api-version=2023-05-15" + endpoint = f"{self.deployment_url}/chat/completions?api-version=2023-05-15" headers = instantiation.get_headers(self.ai_core_sk_filepath) data = { "messages": [ @@ -45,6 +44,7 @@ def _call( try: response = requests.post(endpoint, headers=headers, json=data) + response.raise_for_status() return self.parse(response.json()) except requests.exceptions.HTTPError as http_error: logger.error( diff --git a/prospector/rules/rules.py b/prospector/rules/rules.py index 0c083e31c..56977d574 100644 --- a/prospector/rules/rules.py +++ b/prospector/rules/rules.py @@ -412,30 +412,6 @@ def apply(self, candidate: Commit, advisory_record: AdvisoryRecord): return False -class CommitIsSecurityRelevant(Rule): - """Matches commits that are deemed security relevant by the commit classification service.""" - - def apply( - self, - candidate: Commit, - ) -> bool: - # temperature saved in LLMService's model - temperature = self.llm_service.model._identifying_params.get("temperature") - data = { - "temperature": temperature, - "diff": "\n".join(candidate.diff), - } - - response = requests.get("http://127.0.0.1:8001/predict", json=data) - - prediction = response.json()["prediction"] - if prediction == "1": - self.message = "The commit was deemed security relevant by the commit classification service." - return True - else: - return False - - RULES_PHASE_1: List[Rule] = [ VulnIdInMessage("VULN_ID_IN_MESSAGE", 64), # CommitMentionedInAdv("COMMIT_IN_ADVISORY", 64), @@ -456,6 +432,4 @@ def apply( CommitHasTwins("COMMIT_HAS_TWINS", 2), ] -RULES_PHASE_2: List[Rule] = [ - CommitIsSecurityRelevant("COMMIT_IS_SECURITY_RELEVANT", 32) -] +RULES_PHASE_2: List[Rule] = []