Skip to content

Commit

Permalink
Check available models before access
Browse files Browse the repository at this point in the history
  • Loading branch information
rbx committed Oct 14, 2024
1 parent 7c16c21 commit 0d15b59
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/pearbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from storage import get_or_create_session
from agents import Agent
from review_github import GitHubReviewer
from ollama_utils import is_model_available, get_available_models

def extract_commit_info(diff_content):
commit_range = None
Expand Down Expand Up @@ -72,6 +73,17 @@ def analyze_diff(diff_content, initial_review_models, final_review_model):

print(f"\n\nImproved feedback:\n{improved_feedback}\n\n")

def validate_models(initial_review_models, final_review_model):
all_models = initial_review_models + [final_review_model]
unavailable_models = [model for model in all_models if not is_model_available(model)]

if unavailable_models:
print(f"Error: The following models are not available: {', '.join(unavailable_models)}")
print("Available models:")
print(", ".join(get_available_models()))
return False
return True

def main():
parser = argparse.ArgumentParser(description="Pearbot Code Review")
parser.add_argument("--server", action="store_true", help="Run as a server")
Expand All @@ -84,6 +96,11 @@ def main():
initial_review_models = args.initial_review_models.split(',')
final_review_model = args.model

print(f"Available models: {', '.join(get_available_models())}")

if not validate_models(initial_review_models, final_review_model):
sys.exit(1)

if args.server:
print("Running as a server...")
code_review_agent = Agent(role="code_reviewer", use_post_request=True)
Expand Down

0 comments on commit 0d15b59

Please sign in to comment.