Skip to content

Commit ea8795b

Browse files
committed
Updated Tree of thought so that documentation works like chain of thought
1 parent 53e5c42 commit ea8795b

File tree

1 file changed

+53
-2
lines changed

1 file changed

+53
-2
lines changed

‎src/hackingBuddyGPT/usecases/web_api_testing/prompt_generation/prompt_generation_helper.py‎

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,50 @@ def __init__(self, response_handler: ResponseHandler = None, schemas: dict = Non
3636
self.schemas = schemas
3737
self.endpoints = endpoints
3838

39+
import re
40+
41+
import re
42+
43+
def find_missing_endpoints(self, endpoints: list) -> list:
44+
"""
45+
Identifies and returns the actual missing endpoint paths.
46+
47+
Args:
48+
endpoints (dict): A dictionary of endpoint paths (e.g., {'/resources/': {...}, '/resources/:id': {...}}).
49+
50+
Returns:
51+
list: A list of missing endpoint paths.
52+
Example: ['/resources/:id', '/products/']
53+
"""
54+
general_endpoints = set()
55+
parameterized_endpoints = set()
56+
57+
# Extract resource names and categorize them
58+
for endpoint in endpoints:
59+
match = re.match(r'^/([^/]+)/?$', endpoint) # Match general endpoints like /resources/
60+
if match:
61+
general_endpoints.add(match.group(1))
62+
63+
match = re.match(r'^/([^/]+)/:id$', endpoint) # Match parameterized endpoints like /resources/:id
64+
if match:
65+
parameterized_endpoints.add(match.group(1))
66+
67+
# Find resources that are missing either general or parameterized endpoints
68+
missing_endpoints = []
69+
all_resources = general_endpoints | parameterized_endpoints
70+
71+
for resource in all_resources:
72+
if resource not in general_endpoints:
73+
missing_endpoints.append(f'/{resource}/')
74+
if resource not in parameterized_endpoints:
75+
missing_endpoints.append(f'/{resource}/:id')
76+
77+
# If only one missing endpoint is needed, break early
78+
if len(missing_endpoints) == 1:
79+
break
80+
81+
return missing_endpoints
82+
3983
def get_endpoints_needing_help(self, info=""):
4084
"""
4185
Identifies endpoints that need additional HTTP methods and returns guidance for the first missing method.
@@ -67,8 +111,15 @@ def get_endpoints_needing_help(self, info=""):
67111
f"For endpoint {first_endpoint}, find this missing method: {needed_method}. "
68112
#f"If all HTTP methods have already been found for an endpoint, do not include this endpoint in your search."
69113
]
70-
71-
return []
114+
else:
115+
missing_endpoints = self.find_missing_endpoints(endpoints=self.found_endpoints)
116+
if missing_endpoints:
117+
needed_method = "GET"
118+
return [
119+
info + "/n",
120+
f"For endpoint {missing_endpoints[0]}, find this missing method: {needed_method}. "
121+
# f"If all HTTP methods have already been found for an endpoint, do not include this endpoint in your search."
122+
]
72123

73124
def get_http_action_template(self, method):
74125
"""

0 commit comments

Comments
 (0)