Merge pull request #495 from Codium-ai/tr/review_protection

Enhanced Exception Handling and Code Suggestion Formatting
This commit is contained in:
mrT23
2023-12-03 00:11:02 -08:00
committed by GitHub
3 changed files with 33 additions and 18 deletions

View File

@ -233,7 +233,7 @@ To use a different model than the default (GPT-4), you need to edit [configurati
For models and environments not from OPENAI, you might need to provide additional keys and other parameters. See below for instructions. For models and environments not from OPENAI, you might need to provide additional keys and other parameters. See below for instructions.
#### Azure #### Azure
To use Azure, set in your .secrets.toml: To use Azure, set in your `.secrets.toml` (working from CLI), or in the GitHub `Settings > Secrets and variables` (working from GitHub App or GitHub Action):
``` ```
api_key = "" # your azure api key api_key = "" # your azure api key
api_type = "azure" api_type = "azure"
@ -242,12 +242,11 @@ api_base = "" # The base URL for your Azure OpenAI resource. e.g. "https://<you
openai.deployment_id = "" # The deployment name you chose when you deployed the engine openai.deployment_id = "" # The deployment name you chose when you deployed the engine
``` ```
and and set in your configuration file:
``` ```
[config] [config]
model="" # the OpenAI model you've deployed on Azure (e.g. gpt-3.5-turbo) model="" # the OpenAI model you've deployed on Azure (e.g. gpt-3.5-turbo)
``` ```
in the configuration.toml
#### Huggingface #### Huggingface

View File

@ -60,6 +60,8 @@ class GithubProvider(GitProvider):
get_logger().info(f"Skipping merge commit {commit.commit.message}") get_logger().info(f"Skipping merge commit {commit.commit.message}")
continue continue
self.file_set.update({file.filename: file for file in commit.files}) self.file_set.update({file.filename: file for file in commit.files})
else:
raise ValueError("No previous review found")
def get_commit_range(self): def get_commit_range(self):
last_review_time = self.previous_review.created_at last_review_time = self.previous_review.created_at

View File

@ -251,7 +251,16 @@ class PRCodeSuggestions:
def publish_summarizes_suggestions(self, data: Dict): def publish_summarizes_suggestions(self, data: Dict):
try: try:
data_markdown = "## PR Code Suggestions\n\n" data_markdown = "## PR Code Suggestions\n\n"
language_extension_map_org = get_settings().language_extension_map_org
extension_to_language = {}
for language, extensions in language_extension_map_org.items():
for ext in extensions:
extension_to_language[ext] = language
for s in data['Code suggestions']: for s in data['Code suggestions']:
try:
extension_s = s['relevant file'].rsplit('.')[-1]
code_snippet_link = self.git_provider.get_line_link(s['relevant file'], s['relevant lines start'], code_snippet_link = self.git_provider.get_line_link(s['relevant file'], s['relevant lines start'],
s['relevant lines end']) s['relevant lines end'])
data_markdown += f"\n💡 Suggestion:\n\n**{s['suggestion content']}**\n\n" data_markdown += f"\n💡 Suggestion:\n\n**{s['suggestion content']}**\n\n"
@ -262,11 +271,16 @@ class PRCodeSuggestions:
if self.git_provider.is_supported("gfm_markdown"): if self.git_provider.is_supported("gfm_markdown"):
data_markdown += "<details> <summary> Example code:</summary>\n\n" data_markdown += "<details> <summary> Example code:</summary>\n\n"
data_markdown += f"___\n\n" data_markdown += f"___\n\n"
data_markdown += f"Existing code:\n```{self.main_language}\n{s['existing code']}\n```\n" language_name = "python"
data_markdown += f"Improved code:\n```{self.main_language}\n{s['improved code']}\n```\n" if extension_s and (extension_s in extension_to_language):
language_name = extension_to_language[extension_s]
data_markdown += f"Existing code:\n```{language_name}\n{s['existing code']}\n```\n"
data_markdown += f"Improved code:\n```{language_name}\n{s['improved code']}\n```\n"
if self.git_provider.is_supported("gfm_markdown"): if self.git_provider.is_supported("gfm_markdown"):
data_markdown += "</details>\n" data_markdown += "</details>\n"
data_markdown += "\n___\n\n" data_markdown += "\n___\n\n"
except Exception as e:
get_logger().error(f"Could not parse suggestion: {s}, error: {e}")
self.git_provider.publish_comment(data_markdown) self.git_provider.publish_comment(data_markdown)
except Exception as e: except Exception as e:
get_logger().info(f"Failed to publish summarized code suggestions, error: {e}") get_logger().info(f"Failed to publish summarized code suggestions, error: {e}")