-
Notifications
You must be signed in to change notification settings - Fork 108
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
prompt_builder: add list of header files in code fixing prompt #318
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ | |
import requests | ||
import yaml | ||
|
||
from data_prep import project_targets | ||
from data_prep import introspector, project_targets | ||
from experiment.benchmark import Benchmark, FileType | ||
from experiment.fuzz_target_error import SemanticCheckResult | ||
from llm_toolkit import models, prompts | ||
|
@@ -46,6 +46,7 @@ | |
'jansi_colors-problem.txt') | ||
FDP_JVM_EXAMPLE_2_SOLUTION = os.path.join(EXAMPLE_PATH, | ||
'jansi_colors-solution.java') | ||
HEADER_FIXER_PROMPT = os.path.join(DEFAULT_TEMPLATE_DIR, 'header_fixer.txt') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you add this file yet? |
||
|
||
EXAMPLES = { | ||
'c++': [ | ||
|
@@ -271,7 +272,7 @@ def build_fixer_prompt(self, benchmark: Benchmark, raw_code: str, | |
"""Prepares the code-fixing prompt.""" | ||
priming, priming_weight = self._format_fixer_priming() | ||
problem = self._format_fixer_problem(raw_code, error_desc, errors, | ||
priming_weight) | ||
priming_weight, benchmark) | ||
|
||
self._prepare_prompt(priming, problem) | ||
return self._prompt | ||
|
@@ -287,7 +288,8 @@ def _format_fixer_priming(self) -> Tuple[str, int]: | |
return priming, priming_weight | ||
|
||
def _format_fixer_problem(self, raw_code: str, error_desc: Optional[str], | ||
errors: list[str], priming_weight: int) -> str: | ||
errors: list[str], priming_weight: int, | ||
benchmark: Benchmark) -> str: | ||
"""Formats a problem for code fixer based on the template.""" | ||
with open(self.fixer_problem_template_file) as f: | ||
problem = f.read().strip() | ||
|
@@ -297,6 +299,17 @@ def _format_fixer_problem(self, raw_code: str, error_desc: Optional[str], | |
else: | ||
# Build error does not pass error desc. | ||
error_summary = BUILD_ERROR_SUMMARY | ||
headers_to_avoid = introspector.query_introspector_header_files( | ||
benchmark.project) | ||
if len(headers_to_avoid) > 0: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: |
||
with open(HEADER_FIXER_PROMPT, 'r') as f: | ||
header_avoid_string = f.read() | ||
for header_file in headers_to_avoid: | ||
header_avoid_string += '- %s\n' % (os.path.basename(header_file)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. f-string, please :) |
||
else: | ||
header_avoid_string = '' | ||
problem = problem.replace('{ADDITIONAL_MESSAGE}', header_avoid_string) | ||
|
||
problem = problem.replace('{ERROR_SUMMARY}', error_summary) | ||
|
||
problem_prompt = self._prompt.create_prompt_piece(problem, 'user') | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for
()
if this fits into one line.