Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CERT-7874 Handle LLM key crash #51

Merged
merged 4 commits into from
Dec 29, 2024
Merged

Conversation

nivcertora
Copy link
Collaborator

@nivcertora nivcertora commented Dec 29, 2024

https://certora.atlassian.net/browse/CERT-7874

Summary of Changes

Purpose:
Enhance the application's robustness by handling scenarios where the Anthropic API key (ANTHROPIC_API_KEY) is not configured. This ensures that dependent checks are gracefully skipped, and users are appropriately informed.


1. Quorum/checks/new_listing.py

  • Imported Configuration Module:

    • Added import Quorum.config as config to access configuration settings.
  • Conditional Execution in NewListingCheck:

    • Before Performing First Deposit Check:
      • Check for Anthropic API Key:
        • If ANTHROPIC_API_KEY is not set in the environment:
          • Print Warning:
            Displays a warning message indicating that the first deposit check is skipped due to the missing API key.
          • Skip Further Processing:
            Exits the new_listing_check method early to prevent executing dependent checks without the necessary API key.

Impact:
Prevents the tool from attempting to perform operations that rely on the Anthropic API when the API key is not available, thereby avoiding potential errors and informing the user of the skipped functionality.


2. Quorum/config.py

  • Imported Pretty Printer:

    • Added import Quorum.utils.pretty_printer as pp to utilize the pretty printing utility for displaying messages.
  • Configuration Validation for Anthropic API Key:

    • After Retrieving ANTHROPIC_API_KEY:
      • Check for API Key Presence:
        • If ANTHROPIC_API_KEY is not set:
          • Print Warning:
            Displays a warning message informing the user that the ANTHROPIC_API_KEY environment variable is not set and that all dependent checks will be skipped.

Impact:
Alerts users during the configuration phase if the Anthropic API key is missing, ensuring they are aware that certain features will not be available until the API key is provided.


Overall Benefits:

  • Improved User Experience:
    Users receive clear and immediate feedback about missing configurations, preventing confusion and unexpected behavior.

  • Enhanced Stability:
    By conditionally skipping dependent checks when necessary, the application avoids runtime errors and maintains smooth operation.

  • Maintainable Codebase:
    Centralizing the API key check in the configuration and conditionally handling it in dependent modules promotes cleaner and more maintainable code.


Example Warning Messages:

  • From config.py:

    Warning: ANTHROPIC_API_KEY environment variable is not set. All dependent checks will be skipped.
    
  • From new_listing.py:

    first deposit check is skipped. If you have an LLM API key, you can add it to your environment to enable this check
    

@nivcertora nivcertora self-assigned this Dec 29, 2024
@nivcertora nivcertora requested a review from a team as a code owner December 29, 2024 14:46
@yoav-el-certora
Copy link
Collaborator

This comment will trigger CI?

@nivcertora nivcertora merged commit 39c62c4 into main Dec 29, 2024
1 check passed
@nivcertora nivcertora deleted the niv/CERT-7874-Handle-LLM-Key-Crash branch December 29, 2024 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants