diff --git a/pr_agent/algo/token_handler.py b/pr_agent/algo/token_handler.py index 935e6da5f..100a22ced 100644 --- a/pr_agent/algo/token_handler.py +++ b/pr_agent/algo/token_handler.py @@ -65,7 +65,7 @@ def _get_system_user_tokens(self, pr, encoder, vars: dict, system, user): The sum of the number of tokens in the system and user strings. """ try: - environment = Environment(undefined=StrictUndefined) + environment = Environment(undefined=StrictUndefined, autoescape=True) system_prompt = environment.from_string(system).render(vars) user_prompt = environment.from_string(user).render(vars) system_prompt_tokens = len(encoder.encode(system_prompt)) @@ -85,4 +85,4 @@ def count_tokens(self, patch: str) -> int: Returns: The number of tokens in the patch string. """ - return len(self.encoder.encode(patch, disallowed_special=())) \ No newline at end of file + return len(self.encoder.encode(patch, disallowed_special=())) diff --git a/pr_agent/tools/pr_add_docs.py b/pr_agent/tools/pr_add_docs.py index 3ec97b31c..9e16c408e 100644 --- a/pr_agent/tools/pr_add_docs.py +++ b/pr_agent/tools/pr_add_docs.py @@ -83,7 +83,7 @@ async def _prepare_prediction(self, model: str): async def _get_prediction(self, model: str): variables = copy.deepcopy(self.vars) variables["diff"] = self.patches_diff # update diff - environment = Environment(undefined=StrictUndefined) + environment = Environment(undefined=StrictUndefined, autoescape=True) system_prompt = environment.from_string(get_settings().pr_add_docs_prompt.system).render(variables) user_prompt = environment.from_string(get_settings().pr_add_docs_prompt.user).render(variables) if get_settings().config.verbosity_level >= 2: diff --git a/pr_agent/tools/pr_code_suggestions.py b/pr_agent/tools/pr_code_suggestions.py index 25f512951..91954b165 100644 --- a/pr_agent/tools/pr_code_suggestions.py +++ b/pr_agent/tools/pr_code_suggestions.py @@ -311,7 +311,7 @@ async def _prepare_prediction(self, model: str) -> dict: async def _get_prediction(self, model: str, patches_diff: str) -> dict: variables = copy.deepcopy(self.vars) variables["diff"] = patches_diff # update diff - environment = Environment(undefined=StrictUndefined) + environment = Environment(undefined=StrictUndefined, autoescape=True) system_prompt = environment.from_string(self.pr_code_suggestions_prompt_system).render(variables) user_prompt = environment.from_string(get_settings().pr_code_suggestions_prompt.user).render(variables) response, finish_reason = await self.ai_handler.chat_completion( @@ -573,7 +573,7 @@ async def rank_suggestions(self, data: List) -> List: variables = {'suggestion_list': suggestion_list, 'suggestion_str': suggestion_str} model = get_settings().config.model - environment = Environment(undefined=StrictUndefined) + environment = Environment(undefined=StrictUndefined, autoescape=True) system_prompt = environment.from_string(get_settings().pr_sort_code_suggestions_prompt.system).render( variables) user_prompt = environment.from_string(get_settings().pr_sort_code_suggestions_prompt.user).render(variables) @@ -735,7 +735,7 @@ async def self_reflect_on_suggestions(self, suggestion_list: List, patches_diff: 'suggestion_str': suggestion_str, "diff": patches_diff, 'num_code_suggestions': len(suggestion_list)} - environment = Environment(undefined=StrictUndefined) + environment = Environment(undefined=StrictUndefined, autoescape=True) system_prompt_reflect = environment.from_string( get_settings().pr_code_suggestions_reflect_prompt.system).render( variables) diff --git a/pr_agent/tools/pr_description.py b/pr_agent/tools/pr_description.py index 1b3f33c1a..f6e28a953 100644 --- a/pr_agent/tools/pr_description.py +++ b/pr_agent/tools/pr_description.py @@ -344,7 +344,7 @@ async def _get_prediction(self, model: str, patches_diff: str, prompt="pr_descri variables = copy.deepcopy(self.vars) variables["diff"] = patches_diff # update diff - environment = Environment(undefined=StrictUndefined) + environment = Environment(undefined=StrictUndefined, autoescape=True) set_custom_labels(variables, self.git_provider) self.variables = variables diff --git a/pr_agent/tools/pr_generate_labels.py b/pr_agent/tools/pr_generate_labels.py index 1911e0cd9..9c8c86ac5 100644 --- a/pr_agent/tools/pr_generate_labels.py +++ b/pr_agent/tools/pr_generate_labels.py @@ -134,7 +134,7 @@ async def _get_prediction(self, model: str) -> str: variables = copy.deepcopy(self.vars) variables["diff"] = self.patches_diff # update diff - environment = Environment(undefined=StrictUndefined) + environment = Environment(undefined=StrictUndefined, autoescape=True) set_custom_labels(variables, self.git_provider) self.variables = variables diff --git a/pr_agent/tools/pr_information_from_user.py b/pr_agent/tools/pr_information_from_user.py index e5bd2f727..9bee971b3 100644 --- a/pr_agent/tools/pr_information_from_user.py +++ b/pr_agent/tools/pr_information_from_user.py @@ -60,7 +60,7 @@ async def _prepare_prediction(self, model): async def _get_prediction(self, model: str): variables = copy.deepcopy(self.vars) variables["diff"] = self.patches_diff # update diff - environment = Environment(undefined=StrictUndefined) + environment = Environment(undefined=StrictUndefined, autoescape=True) system_prompt = environment.from_string(get_settings().pr_information_from_user_prompt.system).render(variables) user_prompt = environment.from_string(get_settings().pr_information_from_user_prompt.user).render(variables) if get_settings().config.verbosity_level >= 2: diff --git a/pr_agent/tools/pr_line_questions.py b/pr_agent/tools/pr_line_questions.py index 56818e1cd..51a7ed6bc 100644 --- a/pr_agent/tools/pr_line_questions.py +++ b/pr_agent/tools/pr_line_questions.py @@ -93,7 +93,7 @@ async def _get_prediction(self, model: str): variables = copy.deepcopy(self.vars) variables["full_hunk"] = self.patch_with_lines # update diff variables["selected_lines"] = self.selected_lines - environment = Environment(undefined=StrictUndefined) + environment = Environment(undefined=StrictUndefined, autoescape=True) system_prompt = environment.from_string(get_settings().pr_line_questions_prompt.system).render(variables) user_prompt = environment.from_string(get_settings().pr_line_questions_prompt.user).render(variables) if get_settings().config.verbosity_level >= 2: diff --git a/pr_agent/tools/pr_questions.py b/pr_agent/tools/pr_questions.py index 8112510ea..d95a4ea30 100644 --- a/pr_agent/tools/pr_questions.py +++ b/pr_agent/tools/pr_questions.py @@ -103,7 +103,7 @@ async def _prepare_prediction(self, model: str): async def _get_prediction(self, model: str): variables = copy.deepcopy(self.vars) variables["diff"] = self.patches_diff # update diff - environment = Environment(undefined=StrictUndefined) + environment = Environment(undefined=StrictUndefined, autoescape=True) system_prompt = environment.from_string(get_settings().pr_questions_prompt.system).render(variables) user_prompt = environment.from_string(get_settings().pr_questions_prompt.user).render(variables) if 'img_path' in variables: diff --git a/pr_agent/tools/pr_reviewer.py b/pr_agent/tools/pr_reviewer.py index 9f34c1130..be02f3a39 100644 --- a/pr_agent/tools/pr_reviewer.py +++ b/pr_agent/tools/pr_reviewer.py @@ -178,7 +178,7 @@ async def _get_prediction(self, model: str) -> str: variables = copy.deepcopy(self.vars) variables["diff"] = self.patches_diff # update diff - environment = Environment(undefined=StrictUndefined) + environment = Environment(undefined=StrictUndefined, autoescape=True) system_prompt = environment.from_string(get_settings().pr_review_prompt.system).render(variables) user_prompt = environment.from_string(get_settings().pr_review_prompt.user).render(variables) diff --git a/pr_agent/tools/pr_update_changelog.py b/pr_agent/tools/pr_update_changelog.py index dfe90a0df..0dbe60e67 100644 --- a/pr_agent/tools/pr_update_changelog.py +++ b/pr_agent/tools/pr_update_changelog.py @@ -100,7 +100,7 @@ async def _prepare_prediction(self, model: str): async def _get_prediction(self, model: str): variables = copy.deepcopy(self.vars) variables["diff"] = self.patches_diff # update diff - environment = Environment(undefined=StrictUndefined) + environment = Environment(undefined=StrictUndefined, autoescape=True) system_prompt = environment.from_string(get_settings().pr_update_changelog_prompt.system).render(variables) user_prompt = environment.from_string(get_settings().pr_update_changelog_prompt.user).render(variables) response, finish_reason = await self.ai_handler.chat_completion(