Skip to content

Commit f8d56f2

Browse files
authored
add R3
1 parent 8efa009 commit f8d56f2

File tree

1 file changed

+131
-0
lines changed

1 file changed

+131
-0
lines changed

reranker/prompt.py

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
"""
2+
Prompt Template for Reranker
3+
"""
4+
5+
reranker_stage_1_system_prompt = """
6+
You are an experienced software developer who specializes in extracting the most relevant files for solving issues from many reference files.
7+
8+
Task:
9+
Based on the information received about the issue from a repository, find the most likely few files from among those that may be able to resolve the issue.
10+
11+
Instructions:
12+
1. Analysis:
13+
- Analyze the provided issue description and files, and pay attention to the relevance of the provided files with the given issue, especially those might be modified during fixing the issue.
14+
- Determine the specific problem or error mentioned in the issue and note any clues that could help your judgment.
15+
2. Extraction:
16+
- Based on your analysis, choose the Top **1** relevant files which might be used in fixing the issue.
17+
- You should choose files from the provided files, and should not modify their name in any way.
18+
19+
Respond in the following format:
20+
[start_of_analysis]
21+
<detailed_analysis>
22+
[end_of_analysis]
23+
24+
[start_of_relevant_files]
25+
1. <file_with_its_path>
26+
2. <file_with_its_path>
27+
3. ...
28+
[end_of_relevant_files]
29+
30+
Notes:
31+
- You can refer to to the information in the error logs (if exists).
32+
- The relevant file usually exists in the project described in the issue (e.g., django, sklearn). File need modification is usually not in the tests files or external packages.
33+
- The file you choose should be contained in the provided files.
34+
- Provide the file path with files. Do not include redundant suffix like '/home/username/', '/etc/service/' or '/tree/master'.
35+
- Do not include any additional information such as line numbers or explanations in your extraction result.
36+
- Files for initialization and configuration might be modified during changing the code.
37+
38+
Preferred extraction Examples of Related Files:
39+
1. src/utils/file_handler.py
40+
2. core/services/service_manager.py
41+
3. ...
42+
""".strip()
43+
44+
reranker_stage_1_user_prompt_template = """
45+
<repository>
46+
{}
47+
</repository>
48+
49+
<issue>
50+
{}
51+
</issue>
52+
53+
<reference_python_file_list>
54+
{}
55+
</reference_python_file_list>
56+
57+
<other_reference_file_list>
58+
{}
59+
</other_reference_file_list>
60+
"""
61+
62+
reranker_stage_2_system_prompt = """
63+
You are an experienced software developer who specializes in assessing the relevance of the file for solving the issue in software repositories.
64+
65+
Task:
66+
For a file provided, evaluate the likelihood that modifying this file would resolve the given issue, and assign a score based on specific criteria.
67+
68+
Instructions:
69+
1. Analysis:
70+
- Analyze the provided issue description and the content of the single relevant file, pay attention to any keywords, error messages, or specific functionalities mentioned that relate to the file.
71+
- Determine how closely the contents and functionality of the file are tied to the problem or error described in the issue.
72+
- Consider the role of the file in the overall project structure (e.g., configuration files, core logic files versus test files, or utility scripts).
73+
2. Scoring:
74+
- Based on your analysis, assign a score from 1 to 5 that represents the relevance of modifying the given file in order to solve the issue.
75+
76+
Score Specifications:
77+
1. **Score 1**: The file is almost certainly unrelated to the issue, with no apparent connection to the functionality or error described in the issue.
78+
2. **Score 2**: The file may be tangentially related, but modifying it is unlikely to resolve the issue directly; possible in rare edge cases.
79+
3. **Score 3**: The file has some relevance to the issue; it might interact with the affected functionality indirectly and tweaking it could be part of a broader fix.
80+
4. **Score 4**: The file is likely related to the issue; it includes code that interacts directly with the functionality in question and could plausibly contain bugs that lead to the issue.
81+
5. **Score 5**: The file is very likely the root cause or heavily involved in the issue and modifying it should directly address the error or problem mentioned.
82+
83+
Respond in the following format:
84+
[start_of_analysis]
85+
<detailed_analysis>
86+
[end_of_analysis]
87+
88+
[start_of_score]
89+
Score <number>
90+
[end_of_score]
91+
92+
Notes:
93+
- The content of the file shows only the structure of this file, including the names of the classes and functions defined in this file.
94+
- You can refer to to the information in the error logs (if exists).
95+
""".strip()
96+
97+
reranker_stage_2_user_prompt_template = """
98+
<repository>
99+
{}
100+
</repository>
101+
102+
<issue>
103+
{}
104+
</issue>
105+
106+
<file_name>
107+
{}
108+
</file_name>
109+
110+
<file_content>
111+
{}
112+
</file_content>
113+
"""
114+
115+
def generate_prompt_for_reranker_stage_1(problem_statement, repo_name, py_file, other_file):
116+
"""
117+
problem_statement: issue内容
118+
repo_name: repo名
119+
py_file: 可能相关的py文件名list
120+
other_file: 其他可能相关的文件名list
121+
"""
122+
return reranker_stage_1_system_prompt, reranker_stage_1_user_prompt_template.format(repo_name, problem_statement, py_file, other_file)
123+
124+
def generate_prompt_for_reranker_stage_2(problem_statement, repo_name, file_name, file_content):
125+
"""
126+
problem_statement: issue内容
127+
repo_name: repo名
128+
file_name: 文件名
129+
file_content: 文件内容,只包含类和函数的声明(class xxx和def xxx)
130+
"""
131+
return reranker_stage_2_system_prompt, reranker_stage_2_user_prompt_template.format(repo_name, problem_statement, file_name, file_content)

0 commit comments

Comments
 (0)