From a11e97b5f5a60741a6ba680bf0b801c3feb01bea Mon Sep 17 00:00:00 2001 From: Maxnster Date: Wed, 7 May 2025 18:26:12 +0800 Subject: [PATCH] fix: Prevent duplicate language instructions in extra_instructions --- pr_agent/agent/pr_agent.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/pr_agent/agent/pr_agent.py b/pr_agent/agent/pr_agent.py index 54e249b7..0a42a50d 100644 --- a/pr_agent/agent/pr_agent.py +++ b/pr_agent/agent/pr_agent.py @@ -84,10 +84,18 @@ class PRAgent: if str(type(setting)) == "": if hasattr(setting, 'extra_instructions'): current_extra_instructions = setting.extra_instructions - if current_extra_instructions: - setting.extra_instructions = current_extra_instructions+ f"\n======\n\nIn addition, Your response MUST be written in the language corresponding to local code: {response_language}. This is crucial." - else: - setting.extra_instructions = f"Your response MUST be written in the language corresponding to locale code: '{response_language}'. This is crucial." + + # Define the language-specific instruction and the separator + lang_instruction_text = f"Your response MUST be written in the language corresponding to locale code: '{response_language}'. This is crucial." + separator_text = "\n======\n\nIn addition, " + + # Check if the specific language instruction is already present to avoid duplication + if lang_instruction_text not in str(current_extra_instructions): + if current_extra_instructions: # If there's existing text + setting.extra_instructions = str(current_extra_instructions) + separator_text + lang_instruction_text + else: # If extra_instructions was None or empty + setting.extra_instructions = lang_instruction_text + # If lang_instruction_text is already present, do nothing. action = action.lstrip("/").lower() if action not in command2class: