Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/CodeReview.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ def execute(self):
# Append the new data to self.results
self.results.append(pull_request_data)

json_data = self.transform_json(queue_item, self.results)
data = self.transform_json(queue_item, self.results)

extracted_data = [{"filename": item["filename"], "analysis_result": item["results"]["analysis_result"]} for item in json_data["reviews"][0]["results"][0]["data"]]
data = [{"filename": item["filename"], "analysis_result": item["results"]["analysis_result"]} for item in json_data["reviews"][0]["results"][0]["data"]]

long_summary = self.gpt_query.summarize_entire_pr(extracted_data)
short_summary = self.gpt_query.summary_shortener(long_summary)
data = self.gpt_query.summarize_entire_pr(extracted_data)
data = self.gpt_query.summary_shortener(long_summary)

json_data["reviews"][0]["results"][0]["long_summary"] = long_summary
json_data["reviews"][0]["results"][0]["executive_summary"] = short_summary
data["reviews"][0]["results"][0]["long_summary"] = long_summary
data["reviews"][0]["results"][0]["executive_summary"] = short_summary

self.save_results_to_json(json_data)
return json_data
Expand Down
36 changes: 18 additions & 18 deletions lib/GPTBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@ class GPTBase:
def __init__(self, system_prompt, model_name="gpt-3.5-turbo-16k", temperature=0):
self.default_model_name = model_name
self.default_temperature = temperature
self.chat = ChatOpenAI(
model_name=self.default_model_name, temperature=self.default_temperature
)
self.chat = self._initialize_chat(self.default_model_name, self.default_temperature)
self.system_message = SystemMessage(content=system_prompt)

def _initialize_chat(self, model_name, temperature):
"""Initialize a chat with given model name and temperature."""
return ChatOpenAI(model_name=model_name, temperature=temperature)

def _get_chat_config(self, model_name=None, temperature=None):
"""Return the effective model and temperature settings."""
effective_model_name = model_name or self.default_model_name
effective_temperature = temperature if temperature is not None else self.default_temperature
return effective_model_name, effective_temperature

def generate_message(self, human_message, model_name=None, temperature=None):
"""Generates a system response message given a human message."""
if model_name or temperature is not None:
temporary_model_name = model_name if model_name else self.default_model_name
temporary_temperature = (
temperature if temperature is not None else self.default_temperature
)
temporary_chat = ChatOpenAI(
model_name=temporary_model_name, temperature=temporary_temperature
)
effective_model_name, effective_temperature = self._get_chat_config(model_name, temperature)

if effective_model_name != self.default_model_name or effective_temperature != self.default_temperature:
chat_instance = self._initialize_chat(effective_model_name, effective_temperature)
else:
temporary_chat = self.chat

messages = [
self.system_message,
HumanMessage(content=human_message),
]
chat_instance = self.chat

result = temporary_chat(messages)
messages = [self.system_message, HumanMessage(content=human_message)]
result = chat_instance(messages)

return result.content
67 changes: 44 additions & 23 deletions lib/GitHubWrapper.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,47 @@
import os, sys
import github

class GithubWrapper:
def __init__(self):
self.github = github.Github(os.environ.get("GITHUB_API_KEY"))

def get_repo(self, repo_name):
print(f"Fetching repository {repo_name}...")
return self.github.get_repo(repo_name)

def get_repos(self, name, visibility="public"):
print(f"Fetching repositories for {name}...")
import sys

class GitHubHelper:

VISIBILITY_PUBLIC = "public"
# Add more constants if needed

def _print_and_return(self, message: str, func, *args, **kwargs):
"""Helper function to print a message before executing a function."""
print(message)
return func(*args, **kwargs)

def get_repo(self, repo_name: str):
return self._print_and_return(
f"Fetching repository {repo_name}...",
self.github.get_repo,
repo_name
)

def get_repos(self, name: str, visibility: str = VISIBILITY_PUBLIC):
try:
search = self.github.search_users(name)
if name.lower() == search[0].login.lower():
return self.github.get_user(name).get_repos(type=visibility)
return self.github.get_organization(name).get_repos(type=visibility)
except:
sys.stderr.write("No such user or org: {}".format(name))
is_user = name.lower() == search[0].login.lower()

if is_user:
repos = self.github.get_user(name).get_repos(type=visibility)
else:
repos = self.github.get_organization(name).get_repos(type=visibility)

return self._print_and_return(
f"Fetching repositories for {name}...",
lambda: repos
)
except IndexError: # If search result is empty
sys.stderr.write(f"No such user or org: {name}")
return []

def get_pull_request(self, repo, id):
print(f"Fetching pull request {id}...")
repo = self.get_repo(repo)
return repo.get_pull(id)
except Exception as e: # To catch other exceptions and log them
sys.stderr.write(str(e))
return []

def get_pull_request(self, repo: str, id: int):
repo_obj = self.get_repo(repo)
return self._print_and_return(
f"Fetching pull request {id}...",
repo_obj.get_pull,
id
)