Skip to content

Commit

Permalink
Enhance AI handler logging and add main PR language attribute to AI h…
Browse files Browse the repository at this point in the history
…andler in various tools
  • Loading branch information
mrT23 committed Mar 16, 2024
1 parent 1593d89 commit 7434528
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 4 deletions.
15 changes: 13 additions & 2 deletions pr_agent/algo/ai_handlers/litellm_ai_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,21 @@ async def chat_completion(self, model: str, system: str, user: str, temperature:
else:
resp = response["choices"][0]['message']['content']
finish_reason = response["choices"][0]["finish_reason"]
# usage = response.get("usage")
get_logger().debug(f"\nAI response:\n{resp}")
get_logger().debug("Full_response", artifact=response)

# log the full response for debugging, including the system and user prompts
response_log = response.dict()
response_log['system'] = system
response_log['user'] = user
response_log['output'] = resp
response_log['finish_reason'] = finish_reason
if hasattr(self, 'main_pr_language'):
response_log['main_pr_language'] = self.main_pr_language
else:
response_log['main_pr_language'] = 'unknown'
get_logger().debug("Full_response", artifact=response_log)

# for CLI debugging
if get_settings().config.verbosity_level >= 2:
get_logger().info(f"\nAI response:\n{resp}")

Expand Down
2 changes: 2 additions & 0 deletions pr_agent/tools/pr_add_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def __init__(self, pr_url: str, cli_mode=False, args: list = None,
)

self.ai_handler = ai_handler()
self.ai_handler.main_pr_language = self.main_language

self.patches_diff = None
self.prediction = None
self.cli_mode = cli_mode
Expand Down
1 change: 1 addition & 0 deletions pr_agent/tools/pr_code_suggestions.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def __init__(self, pr_url: str, cli_mode=False, args: list = None,
num_code_suggestions = get_settings().pr_code_suggestions.num_code_suggestions

self.ai_handler = ai_handler()
self.ai_handler.main_pr_language = self.main_language
self.patches_diff = None
self.prediction = None
self.cli_mode = cli_mode
Expand Down
1 change: 1 addition & 0 deletions pr_agent/tools/pr_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def __init__(self, pr_url: str, args: list = None,

# Initialize the AI handler
self.ai_handler = ai_handler()
self.ai_handler.main_pr_language = self.main_pr_language


# Initialize the variables dictionary
Expand Down
3 changes: 2 additions & 1 deletion pr_agent/tools/pr_generate_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def __init__(self, pr_url: str, args: list = None,

# Initialize the AI handler
self.ai_handler = ai_handler()

self.ai_handler.main_pr_language = self.main_pr_language

# Initialize the variables dictionary
self.vars = {
"title": self.git_provider.pr.title,
Expand Down
2 changes: 2 additions & 0 deletions pr_agent/tools/pr_information_from_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def __init__(self, pr_url: str, args: list = None,
self.git_provider.get_languages(), self.git_provider.get_files()
)
self.ai_handler = ai_handler()
self.ai_handler.main_pr_language = self.main_pr_language

self.vars = {
"title": self.git_provider.pr.title,
"branch": self.git_provider.get_pr_branch(),
Expand Down
5 changes: 4 additions & 1 deletion pr_agent/tools/pr_line_questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ class PR_LineQuestions:
def __init__(self, pr_url: str, args=None, ai_handler: partial[BaseAiHandler,] = LiteLLMAIHandler):
self.question_str = self.parse_args(args)
self.git_provider = get_git_provider()(pr_url)

self.main_pr_language = get_main_pr_language(
self.git_provider.get_languages(), self.git_provider.get_files()
)
self.ai_handler = ai_handler()
self.ai_handler.main_pr_language = self.main_pr_language

self.vars = {
"title": self.git_provider.pr.title,
Expand Down
2 changes: 2 additions & 0 deletions pr_agent/tools/pr_questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def __init__(self, pr_url: str, args=None, ai_handler: partial[BaseAiHandler,] =
self.git_provider.get_languages(), self.git_provider.get_files()
)
self.ai_handler = ai_handler()
self.ai_handler.main_pr_language = self.main_pr_language

self.question_str = question_str
self.vars = {
"title": self.git_provider.pr.title,
Expand Down
2 changes: 2 additions & 0 deletions pr_agent/tools/pr_reviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def __init__(self, pr_url: str, is_answer: bool = False, is_auto: bool = False,
if self.is_answer and not self.git_provider.is_supported("get_issue_comments"):
raise Exception(f"Answer mode is not supported for {get_settings().config.git_provider} for now")
self.ai_handler = ai_handler()
self.ai_handler.main_pr_language = self.main_language

self.patches_diff = None
self.prediction = None

Expand Down
3 changes: 3 additions & 0 deletions pr_agent/tools/pr_update_changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ def __init__(self, pr_url: str, cli_mode=False, args=None, ai_handler: partial[B
)
self.commit_changelog = get_settings().pr_update_changelog.push_changelog_changes
self._get_changlog_file() # self.changelog_file_str

self.ai_handler = ai_handler()
self.ai_handler.main_pr_language = self.main_language

self.patches_diff = None
self.prediction = None
self.cli_mode = cli_mode
Expand Down

0 comments on commit 7434528

Please sign in to comment.