From 6d91f446343d2f3163ab5d8eaa1dfc0b4f02fc2a Mon Sep 17 00:00:00 2001 From: zmeir Date: Tue, 18 Jul 2023 16:32:49 +0300 Subject: [PATCH 1/6] Added configuration option to control publishing review progress This can be useful in a few situations: 1. To reduce the number of GitHub API calls (thus avoiding hitting the rate limit) 2. When the trigger for the agent is an external process (e.g. some external CI job), so there is no need to publish a message like "preparing review..." because it's not a part of a natual conversation with the user --- pr_agent/git_providers/github_provider.py | 5 ++++- pr_agent/settings/configuration.toml | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pr_agent/git_providers/github_provider.py b/pr_agent/git_providers/github_provider.py index fea1ae69..52f7fb83 100644 --- a/pr_agent/git_providers/github_provider.py +++ b/pr_agent/git_providers/github_provider.py @@ -50,6 +50,9 @@ class GithubProvider(GitProvider): # self.pr.create_issue_comment(pr_comment) def publish_comment(self, pr_comment: str, is_temporary: bool = False): + if is_temporary and not settings.config.publish_output_progress: + logging.debug(f"Skipping publish_comment for temporary comment: {pr_comment}") + return response = self.pr.create_issue_comment(pr_comment) if hasattr(response, "user") and hasattr(response.user, "login"): self.github_user_id = response.user.login @@ -140,7 +143,7 @@ class GithubProvider(GitProvider): def remove_initial_comment(self): try: - for comment in self.pr.comments_list: + for comment in getattr(self.pr, 'comments_list', []): if comment.is_temporary: comment.delete() except Exception as e: diff --git a/pr_agent/settings/configuration.toml b/pr_agent/settings/configuration.toml index fc2fa2b8..4cb6055f 100644 --- a/pr_agent/settings/configuration.toml +++ b/pr_agent/settings/configuration.toml @@ -2,6 +2,7 @@ model="gpt-4-0613" git_provider="github" publish_output=true +publish_output_progress=true verbosity_level=0 # 0,1,2 [pr_reviewer] From 2f9546e14430d1be2e2c446e2bc41358a24f90dd Mon Sep 17 00:00:00 2001 From: Ori Kotek Date: Thu, 20 Jul 2023 15:01:12 +0300 Subject: [PATCH 2/6] Retry on rate limit error on OpenAI calls --- pr_agent/algo/ai_handler.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pr_agent/algo/ai_handler.py b/pr_agent/algo/ai_handler.py index a97b97ac..085d9ba6 100644 --- a/pr_agent/algo/ai_handler.py +++ b/pr_agent/algo/ai_handler.py @@ -1,12 +1,12 @@ import logging import openai -from openai.error import APIError, Timeout, TryAgain +from openai.error import APIError, Timeout, TryAgain, RateLimitError from retry import retry from pr_agent.config_loader import settings -OPENAI_RETRIES=2 +OPENAI_RETRIES=5 class AiHandler: """ @@ -34,7 +34,7 @@ class AiHandler: except AttributeError as e: raise ValueError("OpenAI key is required") from e - @retry(exceptions=(APIError, Timeout, TryAgain, AttributeError), + @retry(exceptions=(APIError, Timeout, TryAgain, AttributeError, RateLimitError), tries=OPENAI_RETRIES, delay=2, backoff=2, jitter=(1, 3)) async def chat_completion(self, model: str, temperature: float, system: str, user: str): """ @@ -69,6 +69,9 @@ class AiHandler: except (APIError, Timeout, TryAgain) as e: logging.error("Error during OpenAI inference: ", e) raise + except (RateLimitError) as e: + logging.error("Rate limit error during OpenAI inference: ", e) + raise if response is None or len(response.choices) == 0: raise TryAgain resp = response.choices[0]['message']['content'] From 2e246869d07929f5dcd841c50cf7d3b1ade96282 Mon Sep 17 00:00:00 2001 From: Ori Kotek Date: Thu, 20 Jul 2023 15:02:34 +0300 Subject: [PATCH 3/6] Retry on rate limit error on OpenAI calls --- pr_agent/algo/ai_handler.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pr_agent/algo/ai_handler.py b/pr_agent/algo/ai_handler.py index 085d9ba6..8ab22e05 100644 --- a/pr_agent/algo/ai_handler.py +++ b/pr_agent/algo/ai_handler.py @@ -72,6 +72,9 @@ class AiHandler: except (RateLimitError) as e: logging.error("Rate limit error during OpenAI inference: ", e) raise + except (Exception) as e: + logging.error("Unknown error during OpenAI inference: ", e) + raise TryAgain from e if response is None or len(response.choices) == 0: raise TryAgain resp = response.choices[0]['message']['content'] From 1f0df47b4df479e28e1fb89121e511d8243b1ac6 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Thu, 20 Jul 2023 16:39:28 +0300 Subject: [PATCH 4/6] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e116a20c..9e445912 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@
-Making pull-requests less painful with an AI agent +Making pull requests less painful with an AI agent [![GitHub license](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://github.com/Codium-ai/pr-agent/blob/main/LICENSE) @@ -12,7 +12,7 @@ Making pull-requests less painful with an AI agent
-CodiumAI `PR-Agent` is an open-source tool aiming to help developers review pull-requests faster and more efficiently. It automatically analyzes the pull-request and can provide several types of feedback: +CodiumAI `PR-Agent` is an open-source tool aiming to help developers review pull requests faster and more efficiently. It automatically analyzes the pull request and can provide several types of feedback: **Auto-Description**: Automatically generating PR description - title, type, summary, code walkthrough and PR labels. \ From e99f9fd59fe56e22e6652d20c6ca4e516454f072 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Thu, 20 Jul 2023 17:36:40 +0300 Subject: [PATCH 5/6] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 9e445912..4da04a4b 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,9 @@ Making pull requests less painful with an AI agent [![GitHub license](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://github.com/Codium-ai/pr-agent/blob/main/LICENSE) [![Discord](https://badgen.net/badge/icon/discord?icon=discord&label&color=purple)](https://discord.com/channels/1057273017547378788/1126104260430528613) + + GitHub +
From 05f29cc4068ebf2f6c274d561a85bbc268698114 Mon Sep 17 00:00:00 2001 From: sambone Date: Thu, 20 Jul 2023 11:48:38 -0500 Subject: [PATCH 6/6] Fix TypeError for GitlabProvider --- pr_agent/git_providers/gitlab_provider.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pr_agent/git_providers/gitlab_provider.py b/pr_agent/git_providers/gitlab_provider.py index d9efe1d8..1ab4db89 100644 --- a/pr_agent/git_providers/gitlab_provider.py +++ b/pr_agent/git_providers/gitlab_provider.py @@ -259,4 +259,7 @@ class GitLabProvider(GitProvider): return None def publish_labels(self, labels): + pass + + def publish_inline_comments(self, comments: list[dict]): pass \ No newline at end of file