From 3b47c75c3250f8a7c73c06c333f4a773a2d973c4 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Fri, 25 Oct 2024 12:27:59 +0300 Subject: [PATCH] Improve handling of empty markdown headers in PR help message tool and update prompt instructions in pr_help_prompts.toml --- pr_agent/settings/pr_help_prompts.toml | 3 ++- pr_agent/tools/pr_help_message.py | 9 ++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pr_agent/settings/pr_help_prompts.toml b/pr_agent/settings/pr_help_prompts.toml index cc3b5153..1911db9c 100644 --- a/pr_agent/settings/pr_help_prompts.toml +++ b/pr_agent/settings/pr_help_prompts.toml @@ -6,13 +6,14 @@ Your goal is to provide the best answer to the question using the documentation Additional instructions: - Try to be short and concise in your answers. Try to give examples if needed. - The main tools of PR-Agent are 'describe', 'review', 'improve'. If there is ambiguity to which tool the user is referring to, prioritize snippets of these tools over others. +- If the question has ambiguity and can relate to different tools or platfroms, provide the best answer possible based on what is available, but also state in your answer what additional information would be needed to give a more accurate answer. The output must be a YAML object equivalent to type $DocHelper, according to the following Pydantic definitions: ===== class relevant_section(BaseModel): file_name: str = Field(description="The name of the relevant file") - relevant_section_header_string: str = Field(description="Exact text of the relevant section heading") + relevant_section_header_string: str = Field(description="From the relevant file, exact text of the relevant section heading. If no markdown heading is relevant, return empty string") class DocHelper(BaseModel): user_question: str = Field(description="The user's question") diff --git a/pr_agent/tools/pr_help_message.py b/pr_agent/tools/pr_help_message.py index a99b20e9..f35b8173 100644 --- a/pr_agent/tools/pr_help_message.py +++ b/pr_agent/tools/pr_help_message.py @@ -99,7 +99,7 @@ class PRHelpMessage: try: with open(file, 'r') as f: file_path = str(file).replace(str(docs_path), '') - docs_prompt += f"==file name:==\n\n{file_path}\n\n==file content:==\n\n{f.read().strip()}\n=========\n\n" + docs_prompt += f"\n==file name==\n\n{file_path}\n\n==file content==\n\n{f.read().strip()}\n=========\n\n" except Exception as e: get_logger().error(f"Error while reading the file {file}: {e}") token_count = self.token_handler.count_tokens(docs_prompt) @@ -137,8 +137,11 @@ class PRHelpMessage: base_path = "https://qodo-merge-docs.qodo.ai/" for section in relevant_sections: file = section.get('file_name').strip().removesuffix('.md') - markdown_header = section['relevant_section_header_string'].strip().strip('#').strip().lower().replace(' ', '-') - answer_str += f"> - {base_path}{file}#{markdown_header}\n" + if str(section['relevant_section_header_string']).strip(): + markdown_header = section['relevant_section_header_string'].strip().strip('#').strip().lower().replace(' ', '-') + answer_str += f"> - {base_path}{file}#{markdown_header}\n" + else: + answer_str += f"> - {base_path}{file}\n" # publish the answer