From 74345284bdc537caf2dba073bbeda55f063327d5 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sat, 16 Mar 2024 13:47:44 +0200 Subject: [PATCH] Enhance AI handler logging and add main PR language attribute to AI handler in various tools --- pr_agent/algo/ai_handlers/litellm_ai_handler.py | 15 +++++++++++++-- pr_agent/tools/pr_add_docs.py | 2 ++ pr_agent/tools/pr_code_suggestions.py | 1 + pr_agent/tools/pr_description.py | 1 + pr_agent/tools/pr_generate_labels.py | 3 ++- pr_agent/tools/pr_information_from_user.py | 2 ++ pr_agent/tools/pr_line_questions.py | 5 ++++- pr_agent/tools/pr_questions.py | 2 ++ pr_agent/tools/pr_reviewer.py | 2 ++ pr_agent/tools/pr_update_changelog.py | 3 +++ 10 files changed, 32 insertions(+), 4 deletions(-) diff --git a/pr_agent/algo/ai_handlers/litellm_ai_handler.py b/pr_agent/algo/ai_handlers/litellm_ai_handler.py index 51f72960..666db1b1 100644 --- a/pr_agent/algo/ai_handlers/litellm_ai_handler.py +++ b/pr_agent/algo/ai_handlers/litellm_ai_handler.py @@ -125,10 +125,21 @@ class LiteLLMAIHandler(BaseAiHandler): 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}") diff --git a/pr_agent/tools/pr_add_docs.py b/pr_agent/tools/pr_add_docs.py index d13a829d..a671dd3b 100644 --- a/pr_agent/tools/pr_add_docs.py +++ b/pr_agent/tools/pr_add_docs.py @@ -26,6 +26,8 @@ class PRAddDocs: ) 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 diff --git a/pr_agent/tools/pr_code_suggestions.py b/pr_agent/tools/pr_code_suggestions.py index d4f3556a..33628123 100644 --- a/pr_agent/tools/pr_code_suggestions.py +++ b/pr_agent/tools/pr_code_suggestions.py @@ -46,6 +46,7 @@ class PRCodeSuggestions: 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 diff --git a/pr_agent/tools/pr_description.py b/pr_agent/tools/pr_description.py index 28df555f..7500efa7 100644 --- a/pr_agent/tools/pr_description.py +++ b/pr_agent/tools/pr_description.py @@ -41,6 +41,7 @@ class PRDescription: # Initialize the AI handler self.ai_handler = ai_handler() + self.ai_handler.main_pr_language = self.main_pr_language # Initialize the variables dictionary diff --git a/pr_agent/tools/pr_generate_labels.py b/pr_agent/tools/pr_generate_labels.py index 1d91d5e0..4111f7c2 100644 --- a/pr_agent/tools/pr_generate_labels.py +++ b/pr_agent/tools/pr_generate_labels.py @@ -35,7 +35,8 @@ class PRGenerateLabels: # 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, diff --git a/pr_agent/tools/pr_information_from_user.py b/pr_agent/tools/pr_information_from_user.py index 1523d737..03537181 100644 --- a/pr_agent/tools/pr_information_from_user.py +++ b/pr_agent/tools/pr_information_from_user.py @@ -21,6 +21,8 @@ class PRInformationFromUser: 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(), diff --git a/pr_agent/tools/pr_line_questions.py b/pr_agent/tools/pr_line_questions.py index e6386fd1..e26e06d5 100644 --- a/pr_agent/tools/pr_line_questions.py +++ b/pr_agent/tools/pr_line_questions.py @@ -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, diff --git a/pr_agent/tools/pr_questions.py b/pr_agent/tools/pr_questions.py index 7d789e2b..3849029d 100644 --- a/pr_agent/tools/pr_questions.py +++ b/pr_agent/tools/pr_questions.py @@ -22,6 +22,8 @@ class PRQuestions: 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, diff --git a/pr_agent/tools/pr_reviewer.py b/pr_agent/tools/pr_reviewer.py index 19f9a163..f0475b82 100644 --- a/pr_agent/tools/pr_reviewer.py +++ b/pr_agent/tools/pr_reviewer.py @@ -46,6 +46,8 @@ class PRReviewer: 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 diff --git a/pr_agent/tools/pr_update_changelog.py b/pr_agent/tools/pr_update_changelog.py index 4e168d5d..399e0599 100644 --- a/pr_agent/tools/pr_update_changelog.py +++ b/pr_agent/tools/pr_update_changelog.py @@ -26,7 +26,10 @@ class PRUpdateChangelog: ) 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