hackagent 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hackagent/__init__.py +23 -0
- hackagent/agent.py +193 -0
- hackagent/api/__init__.py +1 -0
- hackagent/api/agent/__init__.py +1 -0
- hackagent/api/agent/agent_create.py +340 -0
- hackagent/api/agent/agent_destroy.py +136 -0
- hackagent/api/agent/agent_list.py +234 -0
- hackagent/api/agent/agent_partial_update.py +354 -0
- hackagent/api/agent/agent_retrieve.py +227 -0
- hackagent/api/agent/agent_update.py +354 -0
- hackagent/api/attack/__init__.py +1 -0
- hackagent/api/attack/attack_create.py +264 -0
- hackagent/api/attack/attack_destroy.py +140 -0
- hackagent/api/attack/attack_list.py +242 -0
- hackagent/api/attack/attack_partial_update.py +278 -0
- hackagent/api/attack/attack_retrieve.py +235 -0
- hackagent/api/attack/attack_update.py +278 -0
- hackagent/api/key/__init__.py +1 -0
- hackagent/api/key/key_create.py +168 -0
- hackagent/api/key/key_destroy.py +97 -0
- hackagent/api/key/key_list.py +158 -0
- hackagent/api/key/key_retrieve.py +150 -0
- hackagent/api/prompt/__init__.py +1 -0
- hackagent/api/prompt/prompt_create.py +160 -0
- hackagent/api/prompt/prompt_destroy.py +98 -0
- hackagent/api/prompt/prompt_list.py +173 -0
- hackagent/api/prompt/prompt_partial_update.py +174 -0
- hackagent/api/prompt/prompt_retrieve.py +151 -0
- hackagent/api/prompt/prompt_update.py +174 -0
- hackagent/api/result/__init__.py +1 -0
- hackagent/api/result/result_create.py +160 -0
- hackagent/api/result/result_destroy.py +98 -0
- hackagent/api/result/result_list.py +233 -0
- hackagent/api/result/result_partial_update.py +178 -0
- hackagent/api/result/result_retrieve.py +151 -0
- hackagent/api/result/result_trace_create.py +178 -0
- hackagent/api/result/result_update.py +174 -0
- hackagent/api/run/__init__.py +1 -0
- hackagent/api/run/run_create.py +172 -0
- hackagent/api/run/run_destroy.py +104 -0
- hackagent/api/run/run_list.py +260 -0
- hackagent/api/run/run_partial_update.py +186 -0
- hackagent/api/run/run_result_create.py +178 -0
- hackagent/api/run/run_retrieve.py +163 -0
- hackagent/api/run/run_run_tests_create.py +172 -0
- hackagent/api/run/run_update.py +186 -0
- hackagent/attacks/AdvPrefix/README.md +7 -0
- hackagent/attacks/AdvPrefix/__init__.py +0 -0
- hackagent/attacks/AdvPrefix/completer.py +438 -0
- hackagent/attacks/AdvPrefix/config.py +59 -0
- hackagent/attacks/AdvPrefix/preprocessing.py +521 -0
- hackagent/attacks/AdvPrefix/scorer.py +259 -0
- hackagent/attacks/AdvPrefix/scorer_parser.py +498 -0
- hackagent/attacks/AdvPrefix/selector.py +246 -0
- hackagent/attacks/AdvPrefix/step1_generate.py +324 -0
- hackagent/attacks/AdvPrefix/step4_compute_ce.py +293 -0
- hackagent/attacks/AdvPrefix/step6_get_completions.py +387 -0
- hackagent/attacks/AdvPrefix/step7_evaluate_responses.py +289 -0
- hackagent/attacks/AdvPrefix/step8_aggregate_evaluations.py +177 -0
- hackagent/attacks/AdvPrefix/step9_select_prefixes.py +59 -0
- hackagent/attacks/AdvPrefix/utils.py +192 -0
- hackagent/attacks/__init__.py +6 -0
- hackagent/attacks/advprefix.py +1136 -0
- hackagent/attacks/base.py +50 -0
- hackagent/attacks/strategies.py +539 -0
- hackagent/branding.py +143 -0
- hackagent/client.py +328 -0
- hackagent/errors.py +31 -0
- hackagent/logger.py +67 -0
- hackagent/models/__init__.py +71 -0
- hackagent/models/agent.py +240 -0
- hackagent/models/agent_request.py +169 -0
- hackagent/models/agent_type_enum.py +12 -0
- hackagent/models/attack.py +154 -0
- hackagent/models/attack_request.py +82 -0
- hackagent/models/evaluation_status_enum.py +14 -0
- hackagent/models/organization_minimal.py +68 -0
- hackagent/models/paginated_agent_list.py +123 -0
- hackagent/models/paginated_attack_list.py +123 -0
- hackagent/models/paginated_prompt_list.py +123 -0
- hackagent/models/paginated_result_list.py +123 -0
- hackagent/models/paginated_run_list.py +123 -0
- hackagent/models/paginated_user_api_key_list.py +123 -0
- hackagent/models/patched_agent_request.py +176 -0
- hackagent/models/patched_attack_request.py +92 -0
- hackagent/models/patched_prompt_request.py +162 -0
- hackagent/models/patched_result_request.py +237 -0
- hackagent/models/patched_run_request.py +138 -0
- hackagent/models/prompt.py +226 -0
- hackagent/models/prompt_request.py +155 -0
- hackagent/models/result.py +294 -0
- hackagent/models/result_list_evaluation_status.py +14 -0
- hackagent/models/result_request.py +232 -0
- hackagent/models/run.py +233 -0
- hackagent/models/run_list_status.py +12 -0
- hackagent/models/run_request.py +133 -0
- hackagent/models/status_enum.py +12 -0
- hackagent/models/step_type_enum.py +14 -0
- hackagent/models/trace.py +121 -0
- hackagent/models/trace_request.py +94 -0
- hackagent/models/user_api_key.py +201 -0
- hackagent/models/user_api_key_request.py +73 -0
- hackagent/models/user_profile_minimal.py +76 -0
- hackagent/py.typed +1 -0
- hackagent/router/__init__.py +11 -0
- hackagent/router/adapters/__init__.py +5 -0
- hackagent/router/adapters/google_adk.py +658 -0
- hackagent/router/adapters/litellm_adapter.py +290 -0
- hackagent/router/base.py +48 -0
- hackagent/router/router.py +753 -0
- hackagent/types.py +46 -0
- hackagent/utils.py +61 -0
- hackagent/vulnerabilities/__init__.py +0 -0
- hackagent-0.1.0.dist-info/LICENSE +202 -0
- hackagent-0.1.0.dist-info/METADATA +173 -0
- hackagent-0.1.0.dist-info/RECORD +117 -0
- hackagent-0.1.0.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
from http import HTTPStatus
|
|
2
|
+
from typing import Any, Optional, Union
|
|
3
|
+
from uuid import UUID
|
|
4
|
+
|
|
5
|
+
import httpx
|
|
6
|
+
|
|
7
|
+
from ... import errors
|
|
8
|
+
from ...client import AuthenticatedClient, Client
|
|
9
|
+
from ...models.result import Result
|
|
10
|
+
from ...models.result_request import ResultRequest
|
|
11
|
+
from ...types import Response
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _get_kwargs(
|
|
15
|
+
id: UUID,
|
|
16
|
+
*,
|
|
17
|
+
body: ResultRequest,
|
|
18
|
+
) -> dict[str, Any]:
|
|
19
|
+
headers: dict[str, Any] = {}
|
|
20
|
+
|
|
21
|
+
_kwargs: dict[str, Any] = {
|
|
22
|
+
"method": "post",
|
|
23
|
+
"url": f"/api/run/{id}/result",
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
_body = body.to_dict()
|
|
27
|
+
|
|
28
|
+
_kwargs["json"] = _body
|
|
29
|
+
headers["Content-Type"] = "application/json"
|
|
30
|
+
|
|
31
|
+
_kwargs["headers"] = headers
|
|
32
|
+
return _kwargs
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _parse_response(
|
|
36
|
+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
|
|
37
|
+
) -> Optional[Result]:
|
|
38
|
+
if response.status_code == 200:
|
|
39
|
+
response_200 = Result.from_dict(response.json())
|
|
40
|
+
|
|
41
|
+
return response_200
|
|
42
|
+
if client.raise_on_unexpected_status:
|
|
43
|
+
raise errors.UnexpectedStatus(response.status_code, response.content)
|
|
44
|
+
else:
|
|
45
|
+
return None
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _build_response(
|
|
49
|
+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
|
|
50
|
+
) -> Response[Result]:
|
|
51
|
+
return Response(
|
|
52
|
+
status_code=HTTPStatus(response.status_code),
|
|
53
|
+
content=response.content,
|
|
54
|
+
headers=response.headers,
|
|
55
|
+
parsed=_parse_response(client=client, response=response),
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def sync_detailed(
|
|
60
|
+
id: UUID,
|
|
61
|
+
*,
|
|
62
|
+
client: AuthenticatedClient,
|
|
63
|
+
body: ResultRequest,
|
|
64
|
+
) -> Response[Result]:
|
|
65
|
+
"""Creates a new Result associated with this Run.
|
|
66
|
+
The run instance is fetched using the 'id' (the lookup_field) from the URL.
|
|
67
|
+
|
|
68
|
+
Args:
|
|
69
|
+
id (UUID):
|
|
70
|
+
body (ResultRequest): Serializer for the Result model, often nested in RunSerializer.
|
|
71
|
+
|
|
72
|
+
Raises:
|
|
73
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
|
74
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
|
75
|
+
|
|
76
|
+
Returns:
|
|
77
|
+
Response[Result]
|
|
78
|
+
"""
|
|
79
|
+
|
|
80
|
+
kwargs = _get_kwargs(
|
|
81
|
+
id=id,
|
|
82
|
+
body=body,
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
response = client.get_httpx_client().request(
|
|
86
|
+
**kwargs,
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
return _build_response(client=client, response=response)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def sync(
|
|
93
|
+
id: UUID,
|
|
94
|
+
*,
|
|
95
|
+
client: AuthenticatedClient,
|
|
96
|
+
body: ResultRequest,
|
|
97
|
+
) -> Optional[Result]:
|
|
98
|
+
"""Creates a new Result associated with this Run.
|
|
99
|
+
The run instance is fetched using the 'id' (the lookup_field) from the URL.
|
|
100
|
+
|
|
101
|
+
Args:
|
|
102
|
+
id (UUID):
|
|
103
|
+
body (ResultRequest): Serializer for the Result model, often nested in RunSerializer.
|
|
104
|
+
|
|
105
|
+
Raises:
|
|
106
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
|
107
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
|
108
|
+
|
|
109
|
+
Returns:
|
|
110
|
+
Result
|
|
111
|
+
"""
|
|
112
|
+
|
|
113
|
+
return sync_detailed(
|
|
114
|
+
id=id,
|
|
115
|
+
client=client,
|
|
116
|
+
body=body,
|
|
117
|
+
).parsed
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
async def asyncio_detailed(
|
|
121
|
+
id: UUID,
|
|
122
|
+
*,
|
|
123
|
+
client: AuthenticatedClient,
|
|
124
|
+
body: ResultRequest,
|
|
125
|
+
) -> Response[Result]:
|
|
126
|
+
"""Creates a new Result associated with this Run.
|
|
127
|
+
The run instance is fetched using the 'id' (the lookup_field) from the URL.
|
|
128
|
+
|
|
129
|
+
Args:
|
|
130
|
+
id (UUID):
|
|
131
|
+
body (ResultRequest): Serializer for the Result model, often nested in RunSerializer.
|
|
132
|
+
|
|
133
|
+
Raises:
|
|
134
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
|
135
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
|
136
|
+
|
|
137
|
+
Returns:
|
|
138
|
+
Response[Result]
|
|
139
|
+
"""
|
|
140
|
+
|
|
141
|
+
kwargs = _get_kwargs(
|
|
142
|
+
id=id,
|
|
143
|
+
body=body,
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
response = await client.get_async_httpx_client().request(**kwargs)
|
|
147
|
+
|
|
148
|
+
return _build_response(client=client, response=response)
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
async def asyncio(
|
|
152
|
+
id: UUID,
|
|
153
|
+
*,
|
|
154
|
+
client: AuthenticatedClient,
|
|
155
|
+
body: ResultRequest,
|
|
156
|
+
) -> Optional[Result]:
|
|
157
|
+
"""Creates a new Result associated with this Run.
|
|
158
|
+
The run instance is fetched using the 'id' (the lookup_field) from the URL.
|
|
159
|
+
|
|
160
|
+
Args:
|
|
161
|
+
id (UUID):
|
|
162
|
+
body (ResultRequest): Serializer for the Result model, often nested in RunSerializer.
|
|
163
|
+
|
|
164
|
+
Raises:
|
|
165
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
|
166
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
|
167
|
+
|
|
168
|
+
Returns:
|
|
169
|
+
Result
|
|
170
|
+
"""
|
|
171
|
+
|
|
172
|
+
return (
|
|
173
|
+
await asyncio_detailed(
|
|
174
|
+
id=id,
|
|
175
|
+
client=client,
|
|
176
|
+
body=body,
|
|
177
|
+
)
|
|
178
|
+
).parsed
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
from http import HTTPStatus
|
|
2
|
+
from typing import Any, Optional, Union
|
|
3
|
+
from uuid import UUID
|
|
4
|
+
|
|
5
|
+
import httpx
|
|
6
|
+
|
|
7
|
+
from ... import errors
|
|
8
|
+
from ...client import AuthenticatedClient, Client
|
|
9
|
+
from ...models.run import Run
|
|
10
|
+
from ...types import Response
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _get_kwargs(
|
|
14
|
+
id: UUID,
|
|
15
|
+
) -> dict[str, Any]:
|
|
16
|
+
_kwargs: dict[str, Any] = {
|
|
17
|
+
"method": "get",
|
|
18
|
+
"url": f"/api/run/{id}",
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return _kwargs
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _parse_response(
|
|
25
|
+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
|
|
26
|
+
) -> Optional[Run]:
|
|
27
|
+
if response.status_code == 200:
|
|
28
|
+
response_200 = Run.from_dict(response.json())
|
|
29
|
+
|
|
30
|
+
return response_200
|
|
31
|
+
if client.raise_on_unexpected_status:
|
|
32
|
+
raise errors.UnexpectedStatus(response.status_code, response.content)
|
|
33
|
+
else:
|
|
34
|
+
return None
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _build_response(
|
|
38
|
+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
|
|
39
|
+
) -> Response[Run]:
|
|
40
|
+
return Response(
|
|
41
|
+
status_code=HTTPStatus(response.status_code),
|
|
42
|
+
content=response.content,
|
|
43
|
+
headers=response.headers,
|
|
44
|
+
parsed=_parse_response(client=client, response=response),
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def sync_detailed(
|
|
49
|
+
id: UUID,
|
|
50
|
+
*,
|
|
51
|
+
client: AuthenticatedClient,
|
|
52
|
+
) -> Response[Run]:
|
|
53
|
+
"""ViewSet for managing Run instances.
|
|
54
|
+
Primarily for listing/retrieving runs.
|
|
55
|
+
Creation of server-side runs is handled by custom actions.
|
|
56
|
+
Runs initiated from Attack definitions are created via AttackViewSet.
|
|
57
|
+
|
|
58
|
+
Args:
|
|
59
|
+
id (UUID):
|
|
60
|
+
|
|
61
|
+
Raises:
|
|
62
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
|
63
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
|
64
|
+
|
|
65
|
+
Returns:
|
|
66
|
+
Response[Run]
|
|
67
|
+
"""
|
|
68
|
+
|
|
69
|
+
kwargs = _get_kwargs(
|
|
70
|
+
id=id,
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
response = client.get_httpx_client().request(
|
|
74
|
+
**kwargs,
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
return _build_response(client=client, response=response)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def sync(
|
|
81
|
+
id: UUID,
|
|
82
|
+
*,
|
|
83
|
+
client: AuthenticatedClient,
|
|
84
|
+
) -> Optional[Run]:
|
|
85
|
+
"""ViewSet for managing Run instances.
|
|
86
|
+
Primarily for listing/retrieving runs.
|
|
87
|
+
Creation of server-side runs is handled by custom actions.
|
|
88
|
+
Runs initiated from Attack definitions are created via AttackViewSet.
|
|
89
|
+
|
|
90
|
+
Args:
|
|
91
|
+
id (UUID):
|
|
92
|
+
|
|
93
|
+
Raises:
|
|
94
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
|
95
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
|
96
|
+
|
|
97
|
+
Returns:
|
|
98
|
+
Run
|
|
99
|
+
"""
|
|
100
|
+
|
|
101
|
+
return sync_detailed(
|
|
102
|
+
id=id,
|
|
103
|
+
client=client,
|
|
104
|
+
).parsed
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
async def asyncio_detailed(
|
|
108
|
+
id: UUID,
|
|
109
|
+
*,
|
|
110
|
+
client: AuthenticatedClient,
|
|
111
|
+
) -> Response[Run]:
|
|
112
|
+
"""ViewSet for managing Run instances.
|
|
113
|
+
Primarily for listing/retrieving runs.
|
|
114
|
+
Creation of server-side runs is handled by custom actions.
|
|
115
|
+
Runs initiated from Attack definitions are created via AttackViewSet.
|
|
116
|
+
|
|
117
|
+
Args:
|
|
118
|
+
id (UUID):
|
|
119
|
+
|
|
120
|
+
Raises:
|
|
121
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
|
122
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
|
123
|
+
|
|
124
|
+
Returns:
|
|
125
|
+
Response[Run]
|
|
126
|
+
"""
|
|
127
|
+
|
|
128
|
+
kwargs = _get_kwargs(
|
|
129
|
+
id=id,
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
response = await client.get_async_httpx_client().request(**kwargs)
|
|
133
|
+
|
|
134
|
+
return _build_response(client=client, response=response)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
async def asyncio(
|
|
138
|
+
id: UUID,
|
|
139
|
+
*,
|
|
140
|
+
client: AuthenticatedClient,
|
|
141
|
+
) -> Optional[Run]:
|
|
142
|
+
"""ViewSet for managing Run instances.
|
|
143
|
+
Primarily for listing/retrieving runs.
|
|
144
|
+
Creation of server-side runs is handled by custom actions.
|
|
145
|
+
Runs initiated from Attack definitions are created via AttackViewSet.
|
|
146
|
+
|
|
147
|
+
Args:
|
|
148
|
+
id (UUID):
|
|
149
|
+
|
|
150
|
+
Raises:
|
|
151
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
|
152
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
|
153
|
+
|
|
154
|
+
Returns:
|
|
155
|
+
Run
|
|
156
|
+
"""
|
|
157
|
+
|
|
158
|
+
return (
|
|
159
|
+
await asyncio_detailed(
|
|
160
|
+
id=id,
|
|
161
|
+
client=client,
|
|
162
|
+
)
|
|
163
|
+
).parsed
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
from http import HTTPStatus
|
|
2
|
+
from typing import Any, Optional, Union
|
|
3
|
+
|
|
4
|
+
import httpx
|
|
5
|
+
|
|
6
|
+
from ... import errors
|
|
7
|
+
from ...client import AuthenticatedClient, Client
|
|
8
|
+
from ...models.run import Run
|
|
9
|
+
from ...models.run_request import RunRequest
|
|
10
|
+
from ...types import Response
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _get_kwargs(
|
|
14
|
+
*,
|
|
15
|
+
body: RunRequest,
|
|
16
|
+
) -> dict[str, Any]:
|
|
17
|
+
headers: dict[str, Any] = {}
|
|
18
|
+
|
|
19
|
+
_kwargs: dict[str, Any] = {
|
|
20
|
+
"method": "post",
|
|
21
|
+
"url": "/api/run/run_tests",
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
_body = body.to_dict()
|
|
25
|
+
|
|
26
|
+
_kwargs["json"] = _body
|
|
27
|
+
headers["Content-Type"] = "application/json"
|
|
28
|
+
|
|
29
|
+
_kwargs["headers"] = headers
|
|
30
|
+
return _kwargs
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _parse_response(
|
|
34
|
+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
|
|
35
|
+
) -> Optional[Run]:
|
|
36
|
+
if response.status_code == 200:
|
|
37
|
+
response_200 = Run.from_dict(response.json())
|
|
38
|
+
|
|
39
|
+
return response_200
|
|
40
|
+
if client.raise_on_unexpected_status:
|
|
41
|
+
raise errors.UnexpectedStatus(response.status_code, response.content)
|
|
42
|
+
else:
|
|
43
|
+
return None
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _build_response(
|
|
47
|
+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
|
|
48
|
+
) -> Response[Run]:
|
|
49
|
+
return Response(
|
|
50
|
+
status_code=HTTPStatus(response.status_code),
|
|
51
|
+
content=response.content,
|
|
52
|
+
headers=response.headers,
|
|
53
|
+
parsed=_parse_response(client=client, response=response),
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def sync_detailed(
|
|
58
|
+
*,
|
|
59
|
+
client: AuthenticatedClient,
|
|
60
|
+
body: RunRequest,
|
|
61
|
+
) -> Response[Run]:
|
|
62
|
+
"""ViewSet for managing Run instances.
|
|
63
|
+
Primarily for listing/retrieving runs.
|
|
64
|
+
Creation of server-side runs is handled by custom actions.
|
|
65
|
+
Runs initiated from Attack definitions are created via AttackViewSet.
|
|
66
|
+
|
|
67
|
+
Args:
|
|
68
|
+
body (RunRequest): Serializer for the Run model, used for both input and output.
|
|
69
|
+
|
|
70
|
+
Raises:
|
|
71
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
|
72
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
|
73
|
+
|
|
74
|
+
Returns:
|
|
75
|
+
Response[Run]
|
|
76
|
+
"""
|
|
77
|
+
|
|
78
|
+
kwargs = _get_kwargs(
|
|
79
|
+
body=body,
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
response = client.get_httpx_client().request(
|
|
83
|
+
**kwargs,
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
return _build_response(client=client, response=response)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def sync(
|
|
90
|
+
*,
|
|
91
|
+
client: AuthenticatedClient,
|
|
92
|
+
body: RunRequest,
|
|
93
|
+
) -> Optional[Run]:
|
|
94
|
+
"""ViewSet for managing Run instances.
|
|
95
|
+
Primarily for listing/retrieving runs.
|
|
96
|
+
Creation of server-side runs is handled by custom actions.
|
|
97
|
+
Runs initiated from Attack definitions are created via AttackViewSet.
|
|
98
|
+
|
|
99
|
+
Args:
|
|
100
|
+
body (RunRequest): Serializer for the Run model, used for both input and output.
|
|
101
|
+
|
|
102
|
+
Raises:
|
|
103
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
|
104
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
|
105
|
+
|
|
106
|
+
Returns:
|
|
107
|
+
Run
|
|
108
|
+
"""
|
|
109
|
+
|
|
110
|
+
return sync_detailed(
|
|
111
|
+
client=client,
|
|
112
|
+
body=body,
|
|
113
|
+
).parsed
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
async def asyncio_detailed(
|
|
117
|
+
*,
|
|
118
|
+
client: AuthenticatedClient,
|
|
119
|
+
body: RunRequest,
|
|
120
|
+
) -> Response[Run]:
|
|
121
|
+
"""ViewSet for managing Run instances.
|
|
122
|
+
Primarily for listing/retrieving runs.
|
|
123
|
+
Creation of server-side runs is handled by custom actions.
|
|
124
|
+
Runs initiated from Attack definitions are created via AttackViewSet.
|
|
125
|
+
|
|
126
|
+
Args:
|
|
127
|
+
body (RunRequest): Serializer for the Run model, used for both input and output.
|
|
128
|
+
|
|
129
|
+
Raises:
|
|
130
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
|
131
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
|
132
|
+
|
|
133
|
+
Returns:
|
|
134
|
+
Response[Run]
|
|
135
|
+
"""
|
|
136
|
+
|
|
137
|
+
kwargs = _get_kwargs(
|
|
138
|
+
body=body,
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
response = await client.get_async_httpx_client().request(**kwargs)
|
|
142
|
+
|
|
143
|
+
return _build_response(client=client, response=response)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
async def asyncio(
|
|
147
|
+
*,
|
|
148
|
+
client: AuthenticatedClient,
|
|
149
|
+
body: RunRequest,
|
|
150
|
+
) -> Optional[Run]:
|
|
151
|
+
"""ViewSet for managing Run instances.
|
|
152
|
+
Primarily for listing/retrieving runs.
|
|
153
|
+
Creation of server-side runs is handled by custom actions.
|
|
154
|
+
Runs initiated from Attack definitions are created via AttackViewSet.
|
|
155
|
+
|
|
156
|
+
Args:
|
|
157
|
+
body (RunRequest): Serializer for the Run model, used for both input and output.
|
|
158
|
+
|
|
159
|
+
Raises:
|
|
160
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
|
161
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
|
162
|
+
|
|
163
|
+
Returns:
|
|
164
|
+
Run
|
|
165
|
+
"""
|
|
166
|
+
|
|
167
|
+
return (
|
|
168
|
+
await asyncio_detailed(
|
|
169
|
+
client=client,
|
|
170
|
+
body=body,
|
|
171
|
+
)
|
|
172
|
+
).parsed
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
from http import HTTPStatus
|
|
2
|
+
from typing import Any, Optional, Union
|
|
3
|
+
from uuid import UUID
|
|
4
|
+
|
|
5
|
+
import httpx
|
|
6
|
+
|
|
7
|
+
from ... import errors
|
|
8
|
+
from ...client import AuthenticatedClient, Client
|
|
9
|
+
from ...models.run import Run
|
|
10
|
+
from ...models.run_request import RunRequest
|
|
11
|
+
from ...types import Response
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _get_kwargs(
|
|
15
|
+
id: UUID,
|
|
16
|
+
*,
|
|
17
|
+
body: RunRequest,
|
|
18
|
+
) -> dict[str, Any]:
|
|
19
|
+
headers: dict[str, Any] = {}
|
|
20
|
+
|
|
21
|
+
_kwargs: dict[str, Any] = {
|
|
22
|
+
"method": "put",
|
|
23
|
+
"url": f"/api/run/{id}",
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
_body = body.to_dict()
|
|
27
|
+
|
|
28
|
+
_kwargs["json"] = _body
|
|
29
|
+
headers["Content-Type"] = "application/json"
|
|
30
|
+
|
|
31
|
+
_kwargs["headers"] = headers
|
|
32
|
+
return _kwargs
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _parse_response(
|
|
36
|
+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
|
|
37
|
+
) -> Optional[Run]:
|
|
38
|
+
if response.status_code == 200:
|
|
39
|
+
response_200 = Run.from_dict(response.json())
|
|
40
|
+
|
|
41
|
+
return response_200
|
|
42
|
+
if client.raise_on_unexpected_status:
|
|
43
|
+
raise errors.UnexpectedStatus(response.status_code, response.content)
|
|
44
|
+
else:
|
|
45
|
+
return None
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _build_response(
|
|
49
|
+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
|
|
50
|
+
) -> Response[Run]:
|
|
51
|
+
return Response(
|
|
52
|
+
status_code=HTTPStatus(response.status_code),
|
|
53
|
+
content=response.content,
|
|
54
|
+
headers=response.headers,
|
|
55
|
+
parsed=_parse_response(client=client, response=response),
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def sync_detailed(
|
|
60
|
+
id: UUID,
|
|
61
|
+
*,
|
|
62
|
+
client: AuthenticatedClient,
|
|
63
|
+
body: RunRequest,
|
|
64
|
+
) -> Response[Run]:
|
|
65
|
+
"""ViewSet for managing Run instances.
|
|
66
|
+
Primarily for listing/retrieving runs.
|
|
67
|
+
Creation of server-side runs is handled by custom actions.
|
|
68
|
+
Runs initiated from Attack definitions are created via AttackViewSet.
|
|
69
|
+
|
|
70
|
+
Args:
|
|
71
|
+
id (UUID):
|
|
72
|
+
body (RunRequest): Serializer for the Run model, used for both input and output.
|
|
73
|
+
|
|
74
|
+
Raises:
|
|
75
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
|
76
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
|
77
|
+
|
|
78
|
+
Returns:
|
|
79
|
+
Response[Run]
|
|
80
|
+
"""
|
|
81
|
+
|
|
82
|
+
kwargs = _get_kwargs(
|
|
83
|
+
id=id,
|
|
84
|
+
body=body,
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
response = client.get_httpx_client().request(
|
|
88
|
+
**kwargs,
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
return _build_response(client=client, response=response)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def sync(
|
|
95
|
+
id: UUID,
|
|
96
|
+
*,
|
|
97
|
+
client: AuthenticatedClient,
|
|
98
|
+
body: RunRequest,
|
|
99
|
+
) -> Optional[Run]:
|
|
100
|
+
"""ViewSet for managing Run instances.
|
|
101
|
+
Primarily for listing/retrieving runs.
|
|
102
|
+
Creation of server-side runs is handled by custom actions.
|
|
103
|
+
Runs initiated from Attack definitions are created via AttackViewSet.
|
|
104
|
+
|
|
105
|
+
Args:
|
|
106
|
+
id (UUID):
|
|
107
|
+
body (RunRequest): Serializer for the Run model, used for both input and output.
|
|
108
|
+
|
|
109
|
+
Raises:
|
|
110
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
|
111
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
|
112
|
+
|
|
113
|
+
Returns:
|
|
114
|
+
Run
|
|
115
|
+
"""
|
|
116
|
+
|
|
117
|
+
return sync_detailed(
|
|
118
|
+
id=id,
|
|
119
|
+
client=client,
|
|
120
|
+
body=body,
|
|
121
|
+
).parsed
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
async def asyncio_detailed(
|
|
125
|
+
id: UUID,
|
|
126
|
+
*,
|
|
127
|
+
client: AuthenticatedClient,
|
|
128
|
+
body: RunRequest,
|
|
129
|
+
) -> Response[Run]:
|
|
130
|
+
"""ViewSet for managing Run instances.
|
|
131
|
+
Primarily for listing/retrieving runs.
|
|
132
|
+
Creation of server-side runs is handled by custom actions.
|
|
133
|
+
Runs initiated from Attack definitions are created via AttackViewSet.
|
|
134
|
+
|
|
135
|
+
Args:
|
|
136
|
+
id (UUID):
|
|
137
|
+
body (RunRequest): Serializer for the Run model, used for both input and output.
|
|
138
|
+
|
|
139
|
+
Raises:
|
|
140
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
|
141
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
|
142
|
+
|
|
143
|
+
Returns:
|
|
144
|
+
Response[Run]
|
|
145
|
+
"""
|
|
146
|
+
|
|
147
|
+
kwargs = _get_kwargs(
|
|
148
|
+
id=id,
|
|
149
|
+
body=body,
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
response = await client.get_async_httpx_client().request(**kwargs)
|
|
153
|
+
|
|
154
|
+
return _build_response(client=client, response=response)
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
async def asyncio(
|
|
158
|
+
id: UUID,
|
|
159
|
+
*,
|
|
160
|
+
client: AuthenticatedClient,
|
|
161
|
+
body: RunRequest,
|
|
162
|
+
) -> Optional[Run]:
|
|
163
|
+
"""ViewSet for managing Run instances.
|
|
164
|
+
Primarily for listing/retrieving runs.
|
|
165
|
+
Creation of server-side runs is handled by custom actions.
|
|
166
|
+
Runs initiated from Attack definitions are created via AttackViewSet.
|
|
167
|
+
|
|
168
|
+
Args:
|
|
169
|
+
id (UUID):
|
|
170
|
+
body (RunRequest): Serializer for the Run model, used for both input and output.
|
|
171
|
+
|
|
172
|
+
Raises:
|
|
173
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
|
174
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
|
175
|
+
|
|
176
|
+
Returns:
|
|
177
|
+
Run
|
|
178
|
+
"""
|
|
179
|
+
|
|
180
|
+
return (
|
|
181
|
+
await asyncio_detailed(
|
|
182
|
+
id=id,
|
|
183
|
+
client=client,
|
|
184
|
+
body=body,
|
|
185
|
+
)
|
|
186
|
+
).parsed
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# AdvPrefix: An Objective for Nuanced LLM Jailbreaks
|
|
2
|
+
|
|
3
|
+
This codebase is our team's implementation reproducing the target prefix generation pipeline from the [nuanced LLM jailbreaks](https://arxiv.org/abs/2412.10321) paper (AdvPrefix).
|
|
4
|
+
For a given user request and victim LLM, the pipeline automatically generates and selects target prefixes.
|
|
5
|
+
Replacing the original "Sure, here is ..." with these prefixes enables more nuanced jailbreak attacks.
|
|
6
|
+
|
|
7
|
+
[**[arXiv of the original paper](https://arxiv.org/abs/2412.10321)**]
|
|
File without changes
|