Skip to content

Commit

Permalink
Rename gen code to query llm (#480)
Browse files Browse the repository at this point in the history
The main reason for this is that the `generate_code` does not really
generate any code but rather it queries a given LLM using a specified
prompt. Since we now have prompts of various sort, I feel it might be a
bit misplaced the name. This could also make it a bit more clear which
API to use if you're working on using LLMs for tasks other than explicit
code generation.

This came up while doing #479
where one consideration was to have the LLM generate a corpus explicit
without going a seed-corpus-by-way-of-python generation.

Ref: #482

---------

Signed-off-by: David Korczynski <[email protected]>
  • Loading branch information
DavidKorczynski authored Jul 14, 2024
1 parent eb42759 commit a19eb1a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 25 deletions.
2 changes: 1 addition & 1 deletion experimental/manual/prompter.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ def construct_prompt() -> prompts.Prompt:
model = setup_model()
prompt = construct_prompt()
os.makedirs(args.response_dir, exist_ok=True)
model.generate_code(prompt, response_dir=args.response_dir)
model.query_llm(prompt, response_dir=args.response_dir)
2 changes: 1 addition & 1 deletion llm_toolkit/code_fixer.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ def apply_llm_fix(ai_binary: str,
error_desc, errors, context, instruction)
prompt.save(prompt_path)

fixer_model.generate_code(prompt, response_dir)
fixer_model.query_llm(prompt, response_dir)


def _collect_context(benchmark: benchmarklib.Benchmark,
Expand Down
2 changes: 1 addition & 1 deletion llm_toolkit/crash_triager.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,4 @@ def apply_llm_triage(
crash_func)
prompt.save(prompt_path)

triage_model.generate_code(prompt, response_dir)
triage_model.query_llm(prompt, response_dir)
38 changes: 19 additions & 19 deletions llm_toolkit/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ def estimate_token_num(self, text) -> int:

# ============================== Generation ============================== #
@abstractmethod
def generate_code(self,
prompt: prompts.Prompt,
response_dir: str,
log_output: bool = False) -> None:
"""Generates fuzz targets to the |response_dir|."""
def query_llm(self,
prompt: prompts.Prompt,
response_dir: str,
log_output: bool = False) -> None:
"""Queries the LLM and stores responses in |response_dir|."""

@abstractmethod
def prompt_type(self) -> type[prompts.Prompt]:
Expand Down Expand Up @@ -222,11 +222,11 @@ def prompt_type(self) -> type[prompts.Prompt]:
return prompts.OpenAIPrompt

# ============================== Generation ============================== #
def generate_code(self,
prompt: prompts.Prompt,
response_dir: str,
log_output: bool = False) -> None:
"""Generates code with OpenAI's API."""
def query_llm(self,
prompt: prompts.Prompt,
response_dir: str,
log_output: bool = False) -> None:
"""Queries OpenAI's API and stores response in |response_dir|."""
if self.ai_binary:
print(f'OpenAI does not use local AI binary: {self.ai_binary}')
if self.temperature_list:
Expand Down Expand Up @@ -273,11 +273,11 @@ def estimate_token_num(self, text) -> int:
return int(len(re.split('[^a-zA-Z0-9]+', text)) * 1.5 + 0.5)

# ============================== Generation ============================== #
def generate_code(self,
prompt: prompts.Prompt,
response_dir: str,
log_output: bool = False) -> None:
"""Generates code with internal LLM."""
def query_llm(self,
prompt: prompts.Prompt,
response_dir: str,
log_output: bool = False) -> None:
"""Queries a Google LLM and stores results in |response_dir|."""
if not self.ai_binary:
print(f'Error: This model requires a local AI binary: {self.ai_binary}')
sys.exit(1)
Expand Down Expand Up @@ -349,10 +349,10 @@ def _prepare_parameters(self) -> list[dict]:
self._max_output_tokens
} for index in range(self.num_samples)]

def generate_code(self,
prompt: prompts.Prompt,
response_dir: str,
log_output: bool = False) -> None:
def query_llm(self,
prompt: prompts.Prompt,
response_dir: str,
log_output: bool = False) -> None:
del log_output
if self.ai_binary:
print(f'VertexAI does not use local AI binary: {self.ai_binary}')
Expand Down
4 changes: 1 addition & 3 deletions run_one_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ def generate_targets(benchmark: Benchmark,
"""Generates fuzz target with LLM."""
print(f'Generating targets for {benchmark.project} '
f'{benchmark.function_signature} using {model.name}..')
model.generate_code(prompt,
response_dir=work_dirs.raw_targets,
log_output=debug)
model.query_llm(prompt, response_dir=work_dirs.raw_targets, log_output=debug)

_, target_ext = os.path.splitext(benchmark.target_path)
generated_targets = []
Expand Down

0 comments on commit a19eb1a

Please sign in to comment.