Skip to content

Commit eccaf70

Browse files
Diana StraussDiana Strauss
authored andcommitted
Added more documentation and data types
1 parent 8c30359 commit eccaf70

File tree

7 files changed

+235
-176
lines changed

7 files changed

+235
-176
lines changed

‎src/hackingBuddyGPT/usecases/web_api_testing/prompt_generation/prompts/in_context_learning_prompt.py‎

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
from hackingBuddyGPT.usecases.web_api_testing.prompt_generation.information.prompt_information import PromptStrategy
1+
from typing import List, Dict, Optional
2+
3+
from hackingBuddyGPT.usecases.web_api_testing.prompt_generation.information.prompt_information import PromptStrategy, \
4+
PromptContext, PromptPurpose
25
from hackingBuddyGPT.usecases.web_api_testing.prompt_generation.prompts.basic_prompt import BasicPrompt
6+
from hackingBuddyGPT.usecases.web_api_testing.prompt_generation.utils import PromptGenerationHelper
7+
38

49
class InContextLearningPrompt(BasicPrompt):
510
"""
@@ -12,33 +17,34 @@ class InContextLearningPrompt(BasicPrompt):
1217
Attributes:
1318
context (PromptContext): The context in which prompts are generated.
1419
prompt_helper (PromptHelper): A helper object for managing and generating prompts.
15-
prompt (dict): A dictionary containing the prompts for each round.
20+
prompt (Dict[int, Dict[str, str]]): A dictionary containing the prompts for each round.
21+
round (int): The round number for which the prompt is being generated.
22+
purpose (Optional[PromptPurpose]): The purpose of the prompt generation, which can be set during the process.
1623
"""
1724

18-
def __init__(self, context, prompt_helper, prompt, round):
25+
def __init__(self, context: PromptContext, prompt_helper: PromptGenerationHelper, prompt: Dict[int, Dict[str, str]], round: int) -> None:
1926
"""
2027
Initializes the InContextLearningPrompt with a specific context, prompt helper, and initial prompt.
2128
2229
Args:
2330
context (PromptContext): The context in which prompts are generated.
2431
prompt_helper (PromptHelper): A helper object for managing and generating prompts.
25-
prompt (dict): A dictionary containing the prompts for each round.
26-
round (int): Number of round.
32+
prompt (Dict[int, Dict[str, str]]): A dictionary containing the prompts for each round.
33+
round (int): The round number for which the prompt is being generated.
2734
"""
2835
super().__init__(context, prompt_helper, PromptStrategy.IN_CONTEXT)
29-
self.round = round
30-
self.prompt = prompt
31-
self.purpose = None
32-
36+
self.round: int = round
37+
self.prompt: Dict[int, Dict[str, str]] = prompt
38+
self.purpose: Optional[PromptPurpose] = None
3339

34-
def generate_prompt(self, move_type, hint, previous_prompt): # still work in progress
40+
def generate_prompt(self, move_type: str, hint: Optional[str], previous_prompt: List[Dict[str, str]]) -> str:
3541
"""
3642
Generates a prompt using the in-context learning strategy.
3743
3844
Args:
3945
move_type (str): The type of move to generate.
40-
hint (str): An optional hint to guide the prompt generation.
41-
previous_prompt (list): A list of previous prompt entries, each containing a "content" key.
46+
hint (Optional[str]): An optional hint to guide the prompt generation.
47+
previous_prompt (List[Dict[str, str]]): A list of previous prompt entries, each containing a "content" key.
4248
4349
Returns:
4450
str: The generated prompt.

‎src/hackingBuddyGPT/usecases/web_api_testing/prompt_generation/prompts/tree_of_thought_prompt.py‎

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
from hackingBuddyGPT.usecases.web_api_testing.prompt_generation.information.prompt_information import PromptStrategy, PromptContext, \
2-
PromptPurpose
1+
from typing import List, Optional
2+
3+
from hackingBuddyGPT.usecases.web_api_testing.prompt_generation.information.prompt_information import (
4+
PromptStrategy, PromptContext, PromptPurpose
5+
)
36
from hackingBuddyGPT.usecases.web_api_testing.prompt_generation.prompts.basic_prompt import BasicPrompt
47

58
class TreeOfThoughtPrompt(BasicPrompt):
@@ -13,52 +16,55 @@ class TreeOfThoughtPrompt(BasicPrompt):
1316
Attributes:
1417
context (PromptContext): The context in which prompts are generated.
1518
prompt_helper (PromptHelper): A helper object for managing and generating prompts.
19+
rest_api (str): The REST API endpoint for which prompts are generated.
20+
round (int): The round number for the prompt generation process.
21+
purpose (Optional[PromptPurpose]): The purpose of the prompt generation, which can be set during the process.
1622
"""
1723

18-
def __init__(self, context, prompt_helper, rest_api, round):
24+
def __init__(self, context: PromptContext, prompt_helper: 'PromptHelper', rest_api: str, round: int) -> None:
1925
"""
2026
Initializes the TreeOfThoughtPrompt with a specific context and prompt helper.
2127
2228
Args:
2329
context (PromptContext): The context in which prompts are generated.
2430
prompt_helper (PromptHelper): A helper object for managing and generating prompts.
25-
rest_api (str): The REST API endpoint
26-
round (int): The round number
31+
rest_api (str): The REST API endpoint.
32+
round (int): The round number for the prompt generation process.
2733
"""
2834
super().__init__(context, prompt_helper, PromptStrategy.TREE_OF_THOUGHT)
29-
self.rest_api = rest_api
30-
self.round = round
31-
self.purpose = None
35+
self.rest_api: str = rest_api
36+
self.round: int = round
37+
self.purpose: Optional[PromptPurpose] = None
3238

33-
def generate_prompt(self, move_type, hint, previous_prompt): # still work in progress
39+
def generate_prompt(self, move_type: str, hint: str, previous_prompt: List[dict]) -> str:
3440
"""
3541
Generates a prompt using the tree-of-thought strategy.
3642
3743
Args:
3844
move_type (str): The type of move to generate.
3945
hint (str): An optional hint to guide the prompt generation.
40-
previous_prompt (list): A list of previous prompt entries, each containing a "content" key.
46+
previous_prompt (List[dict]): A list of previous prompt entries, each containing a "content" key.
4147
4248
Returns:
4349
str: The generated prompt.
4450
"""
4551
if self.context == PromptContext.DOCUMENTATION:
4652
tree_of_thoughts_steps = [(
47-
"Imagine three different OpenAPI specification specialist.\n"
48-
"All experts will write down one step of their thinking,\n"
49-
"then share it with the group.\n"
50-
"After that, all remaining specialists will proceed to the next step, and so on.\n"
51-
"If any specialist realizes they're wrong at any point, they will leave.\n"
52-
f"The question is: Create an OpenAPI specification for this REST API {self.rest_api} "
53+
"Imagine three different OpenAPI specification specialists.\n"
54+
"All experts will write down one step of their thinking,\n"
55+
"then share it with the group.\n"
56+
"After that, all remaining specialists will proceed to the next step, and so on.\n"
57+
"If any specialist realizes they're wrong at any point, they will leave.\n"
58+
f"The question is: Create an OpenAPI specification for this REST API {self.rest_api} "
5359
)]
5460
else:
5561
tree_of_thoughts_steps = [(
56-
"Imagine three different Pentest experts are answering this question.\n"
57-
"All experts will write down one step of their thinking,\n"
58-
"then share it with the group.\n"
59-
"After that, all experts will proceed to the next step, and so on.\n"
60-
"If any expert realizes they're wrong at any point, they will leave.\n"
61-
f"The question is: Create pentests for this REST API {self.rest_api} "
62+
"Imagine three different Pentest experts are answering this question.\n"
63+
"All experts will write down one step of their thinking,\n"
64+
"then share it with the group.\n"
65+
"After that, all experts will proceed to the next step, and so on.\n"
66+
"If any expert realizes they're wrong at any point, they will leave.\n"
67+
f"The question is: Create pentests for this REST API {self.rest_api} "
6268
)]
6369
self.purpose = PromptPurpose.AUTHENTICATION_AUTHORIZATION
6470

0 commit comments

Comments
 (0)