Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Jinja2 Autoescape #12

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pr_agent/algo/token_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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=()))
return len(self.encoder.encode(patch, disallowed_special=()))
2 changes: 1 addition & 1 deletion pr_agent/tools/pr_add_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions pr_agent/tools/pr_code_suggestions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pr_agent/tools/pr_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion pr_agent/tools/pr_generate_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion pr_agent/tools/pr_information_from_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pr_agent/tools/pr_line_questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pr_agent/tools/pr_questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pr_agent/tools/pr_reviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion pr_agent/tools/pr_update_changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading