Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f0109a3
Refactored code so that documentation is handled by separate class
DianaStrauss Jun 10, 2024
630f571
refactored code
DianaStrauss Jun 10, 2024
bef16c0
Adjusted prompt_engineer to create better prompts
DianaStrauss Jun 13, 2024
74062ff
Refactored documentation_handler.py to update .yaml file when it get …
DianaStrauss Jun 13, 2024
7591be3
Created SubmitHTTPMethod.py for better separation
DianaStrauss Jun 13, 2024
73fe5c4
Created Converter and parser for handeling yaml and json files
DianaStrauss Jun 13, 2024
430cb1f
Refactored converter and parser
DianaStrauss Jun 14, 2024
cef43e9
Added token count so that prompts are not too long -> WIP shorten pro…
DianaStrauss Jun 14, 2024
89956d7
Refactored code and added yamlFile.py
DianaStrauss Jun 17, 2024
e7ce9ae
Refactored code
DianaStrauss Jun 19, 2024
995b199
Added simple scoring to prompt engineer
DianaStrauss Jul 4, 2024
cbafdf2
changed order of setuo methods in simple_openai_documentation
DianaStrauss Jul 4, 2024
34593e3
changed order of setuo methods in simple_openai_documentation
DianaStrauss Jul 4, 2024
b95dd31
changed order of setuo methods in simple_openai_documentation
DianaStrauss Jul 4, 2024
e267621
Addition of examples works with redocly
DianaStrauss Jul 9, 2024
56bc5ff
Added yaml file assistant
DianaStrauss Jul 9, 2024
7c681af
Can create openapi spec with examples
DianaStrauss Jul 9, 2024
120b09f
Cleaned up code
DianaStrauss Jul 12, 2024
2fcca09
Refactor code
DianaStrauss Jul 12, 2024
29aa192
Refactor code
DianaStrauss Jul 12, 2024
b2632ab
Cleaned up code
DianaStrauss Jul 12, 2024
3af909a
Cleaned up code
DianaStrauss Jul 12, 2024
b1f9886
Cleaned up code
DianaStrauss Jul 12, 2024
5915187
Merge branch 'main' of https://github.com/DianaStrauss/hackingBuddyGP…
andreashappe Jul 22, 2024
8e58cad
Merge branch 'development' into DianaStrauss-main
andreashappe Jul 22, 2024
bbb8133
update dependencies
andreashappe Jul 22, 2024
fd4323e
some simple renames
andreashappe Jul 22, 2024
ec3a0ee
Fixed attribute initialization of use_cases and transparent types
Neverbolt Jul 26, 2024
0babd39
Refactored code and fixed import bugs in simple_web_api_testing and s…
DianaStrauss Aug 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ src/hackingBuddyGPT.egg-info/
build/
dist/
.coverage
src/hackingBuddyGPT/usecases/web_api_testing/openapi_spec/
src/hackingBuddyGPT/usecases/web_api_testing/converted_files/
/src/hackingBuddyGPT/usecases/web_api_testing/utils/openapi_spec/
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@ dependencies = [
'requests == 2.32.0',
'rich == 13.7.1',
'tiktoken == 0.6.0',
'instructor == 1.2.2',
'instructor == 1.3.5',
'PyYAML == 6.0.1',
'python-dotenv == 1.0.1',
'pypsexec == 0.3.0',
'pydantic == 2.8.2',
'openai == 1.28.0',
'spacy',
'BeautifulSoup4'
]

[project.urls]
Expand Down
11 changes: 10 additions & 1 deletion src/hackingBuddyGPT/capabilities/http_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,16 @@ def __call__(self,
) -> str:
if body is not None and body_is_base64:
body = base64.b64decode(body).decode()

if self.host[-1] != "/":
path = "/" + path
resp = self._client.request(
method,
self.host + path,
params=query,
data=body,
headers=headers,
allow_redirects=self.follow_redirects,
)
try:
resp = self._client.request(
method,
Expand Down
73 changes: 73 additions & 0 deletions src/hackingBuddyGPT/capabilities/submit_http_method.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import base64
from dataclasses import dataclass, field
from typing import Set, Dict, Callable, Literal, Optional
import inspect

import requests
from pydantic import create_model, BaseModel

from . import Capability


@dataclass
class SubmitHTTPMethod(Capability):
http_methods_format: str
valid_http_methods: Set[str]
_client = requests.Session()
host: str
follow_redirects: bool = False


submitted_valid_http_methods: Set[str] = field(default_factory=set, init=False)

def describe(self) -> str:
return f"Submits a HTTP methods, which is the goal of all activities. The HTTP methods format is {self.http_methods_format}. If you find a flag following the that format, that you have not yet submitted, then the most important first step is to submit it, ignoring all other possibilities of further action"

def to_model(self) -> BaseModel:
"""
Converts the parameters of the `__call__` function of the capability to a pydantic model, that can be used to
interface with an LLM using eg instructor or the openAI function calling API.
The model will have the same name as the capability class and will have the same fields as the `__call__`,
the `__call__` method can then be accessed by calling the `execute` method of the model.
"""
sig = inspect.signature(self.__call__)
fields = {param: (param_info.annotation, ...) for param, param_info in sig.parameters.items()}
model_type = create_model(self.__class__.__name__, __doc__=self.describe(), **fields)

def execute(model):
m = model.dict()
return self(**m)

model_type.execute = execute

return model_type

def __call__(self, method: Literal["GET", "HEAD", "POST", "PUT", "DELETE", "OPTION", "PATCH"],
path: str,
query: Optional[str] = None,
body: Optional[str] = None,
body_is_base64: Optional[bool] = False,
headers: Optional[Dict[str, str]] = None
) -> str:

if body is not None and body_is_base64:
body = base64.b64decode(body).decode()

resp = self._client.request(
method,
self.host + path,
params=query,
data=body,
headers=headers,
allow_redirects=self.follow_redirects,
)
try:
resp.raise_for_status()
except requests.exceptions.HTTPError as e:
return str(e)

headers = "\r\n".join(f"{k}: {v}" for k, v in resp.headers.items())

# turn the response into "plain text format" for responding to the prompt
return f"HTTP/1.1 {resp.status_code} {resp.reason}\r\n{headers}\r\n\r\n{resp.text}"""

44 changes: 44 additions & 0 deletions src/hackingBuddyGPT/capabilities/yamlFile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from dataclasses import dataclass, field
from typing import Tuple, List

import yaml

from . import Capability

@dataclass
class YAMLFile(Capability):

def describe(self) -> str:
return "Takes a Yaml file and updates it with the given information"

def __call__(self, yaml_str: str) -> str:
"""
Updates a YAML string based on provided inputs and returns the updated YAML string.

Args:
yaml_str (str): Original YAML content in string form.
updates (dict): A dictionary representing the updates to be applied.

Returns:
str: Updated YAML content as a string.
"""
try:
# Load the YAML content from string
data = yaml.safe_load(yaml_str)

print(f'Updates:{yaml_str}')

# Apply updates from the updates dictionary
#for key, value in updates.items():
# if key in data:
# data[key] = value
# else:
# print(f"Warning: Key '{key}' not found in the original data. Adding new key.")
# data[key] = value
#
## Convert the updated dictionary back into a YAML string
#updated_yaml_str = yaml.safe_dump(data, sort_keys=False)
#return updated_yaml_str
except yaml.YAMLError as e:
print(f"Error processing YAML data: {e}")
return "None"
1 change: 1 addition & 0 deletions src/hackingBuddyGPT/usecases/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ def perform_round(self, turn: int):

def use_case(description):
def inner(cls):
cls = dataclass(cls)
name = cls.__name__.removesuffix("UseCase")
if name in use_cases:
raise IndexError(f"Use case with name {name} already exists")
Expand Down
Loading