From 016eab3b3b896ac3892679220961ff281841af20 Mon Sep 17 00:00:00 2001 From: niv vaknin Date: Sun, 29 Dec 2024 16:46:38 +0200 Subject: [PATCH] CERT-7874 Handle LLM key crash --- Quorum/checks/new_listing.py | 11 +++++++++++ Quorum/config.py | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/Quorum/checks/new_listing.py b/Quorum/checks/new_listing.py index a665f1b..b4346df 100644 --- a/Quorum/checks/new_listing.py +++ b/Quorum/checks/new_listing.py @@ -1,8 +1,10 @@ from Quorum.checks.check import Check import Quorum.utils.pretty_printer as pp +import Quorum.config as config from Quorum.llm.chains.first_deposit_chain import FirstDepositChain, ListingArray + class NewListingCheck(Check): def new_listing_check(self) -> None: @@ -15,6 +17,15 @@ def new_listing_check(self) -> None: functions = self._get_functions_from_source_codes() if functions.get("newListings", functions.get("newListingsCustom")): pp.pretty_print(f"New listings detected for {self.proposal_address}", pp.Colors.WARNING) + + # Check if Anthropic API key is configured + if not config.ANTHROPIC_API_KEY: + pp.pretty_print( + "first deposit check is skipped. If you have an LLM API key, you can add it to you env to enable this check", + pp.Colors.WARNING + ) + return + proposal_code = self.source_codes[0].file_content proposal_code_str = '\n'.join(proposal_code) listings: ListingArray | None = FirstDepositChain().execute(proposal_code_str) diff --git a/Quorum/config.py b/Quorum/config.py index f82d4a0..6ccce67 100644 --- a/Quorum/config.py +++ b/Quorum/config.py @@ -2,6 +2,7 @@ import shutil from pathlib import Path +import Quorum.utils.pretty_printer as pp main_path = os.getenv("QUORUM_PATH") if not main_path: @@ -19,4 +20,10 @@ shutil.copy(DEFAULT_REPOS, GROUND_TRUTH_PATH) ANTHROPIC_API_KEY = os.getenv('ANTHROPIC_API_KEY') +if not ANTHROPIC_API_KEY: + pp.pretty_print( + "Warning: ANTHROPIC_API_KEY environment variable is not set. All dependent checks will be skipped.", + pp.Colors.WARNING + ) + ANTHROPIC_MODEL = os.getenv('ANTROPIC_MDOEL', 'claude-3-5-sonnet-20241022')