Skip to content

Commit

Permalink
validate models upon request
Browse files Browse the repository at this point in the history
  • Loading branch information
rbx committed Oct 15, 2024
1 parent c4ad691 commit fd3e4c1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
11 changes: 11 additions & 0 deletions src/ollama_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,14 @@ def get_available_models():
except requests.RequestException as e:
print(f"Error connecting to Ollama API: {e}")
return []

def validate_models(models):
all_models = set(models)
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
18 changes: 2 additions & 16 deletions src/pearbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,7 @@
from agents import Agent
from review_github import GitHubReviewer
from review_local import analyze_diff
from ollama_utils import is_model_available, get_available_models

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
from ollama_utils import get_available_models

def main():
parser = argparse.ArgumentParser(description="Pearbot Code Review")
Expand All @@ -34,10 +23,7 @@ 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)
print(f"Available models: {', '.join(get_available_models()) or 'NONE'}")

code_review_agent = Agent(role="code_reviewer", use_post_request=True)
feedback_improver_agent = Agent(role="feedback_improver", use_post_request=True)
Expand Down
5 changes: 5 additions & 0 deletions src/review_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from github import Github, GithubException
from flask import Flask, request, abort

from ollama_utils import validate_models

class GitHubReviewer:
def __init__(self, code_review_agent, feedback_improver_agent):
try:
Expand Down Expand Up @@ -106,6 +108,9 @@ def handle_issue_comment(self, payload):
print(f"Review condition not found")

def perform_review(self, pr_number, repo_full_name, installation_id):
if not validate_models(self.app.config['INITIAL_REVIEW_MODELS'] + [self.app.config['FINAL_REVIEW_MODEL']]):
sys.exit(1)

access_token = self.get_installation_access_token(installation_id)
g = Github(access_token)
repo_obj = g.get_repo(repo_full_name)
Expand Down
6 changes: 6 additions & 0 deletions src/review_local.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import json
import re
import sys

from colorama import Fore, Style

from ollama_utils import validate_models

def extract_commit_info(diff_content):
commit_range = None
commit_messages = []
Expand All @@ -26,6 +29,9 @@ def extract_commit_info(diff_content):
return commit_messages

def analyze_diff(diff_content, code_review_agent, feedback_improver_agent, initial_review_models, final_review_model):
if not validate_models(initial_review_models + [final_review_model]):
sys.exit(1)

extracted_messages = extract_commit_info(diff_content)

if not extracted_messages:
Expand Down

0 comments on commit fd3e4c1

Please sign in to comment.