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.
Files changed (117) hide show
  1. hackagent/__init__.py +23 -0
  2. hackagent/agent.py +193 -0
  3. hackagent/api/__init__.py +1 -0
  4. hackagent/api/agent/__init__.py +1 -0
  5. hackagent/api/agent/agent_create.py +340 -0
  6. hackagent/api/agent/agent_destroy.py +136 -0
  7. hackagent/api/agent/agent_list.py +234 -0
  8. hackagent/api/agent/agent_partial_update.py +354 -0
  9. hackagent/api/agent/agent_retrieve.py +227 -0
  10. hackagent/api/agent/agent_update.py +354 -0
  11. hackagent/api/attack/__init__.py +1 -0
  12. hackagent/api/attack/attack_create.py +264 -0
  13. hackagent/api/attack/attack_destroy.py +140 -0
  14. hackagent/api/attack/attack_list.py +242 -0
  15. hackagent/api/attack/attack_partial_update.py +278 -0
  16. hackagent/api/attack/attack_retrieve.py +235 -0
  17. hackagent/api/attack/attack_update.py +278 -0
  18. hackagent/api/key/__init__.py +1 -0
  19. hackagent/api/key/key_create.py +168 -0
  20. hackagent/api/key/key_destroy.py +97 -0
  21. hackagent/api/key/key_list.py +158 -0
  22. hackagent/api/key/key_retrieve.py +150 -0
  23. hackagent/api/prompt/__init__.py +1 -0
  24. hackagent/api/prompt/prompt_create.py +160 -0
  25. hackagent/api/prompt/prompt_destroy.py +98 -0
  26. hackagent/api/prompt/prompt_list.py +173 -0
  27. hackagent/api/prompt/prompt_partial_update.py +174 -0
  28. hackagent/api/prompt/prompt_retrieve.py +151 -0
  29. hackagent/api/prompt/prompt_update.py +174 -0
  30. hackagent/api/result/__init__.py +1 -0
  31. hackagent/api/result/result_create.py +160 -0
  32. hackagent/api/result/result_destroy.py +98 -0
  33. hackagent/api/result/result_list.py +233 -0
  34. hackagent/api/result/result_partial_update.py +178 -0
  35. hackagent/api/result/result_retrieve.py +151 -0
  36. hackagent/api/result/result_trace_create.py +178 -0
  37. hackagent/api/result/result_update.py +174 -0
  38. hackagent/api/run/__init__.py +1 -0
  39. hackagent/api/run/run_create.py +172 -0
  40. hackagent/api/run/run_destroy.py +104 -0
  41. hackagent/api/run/run_list.py +260 -0
  42. hackagent/api/run/run_partial_update.py +186 -0
  43. hackagent/api/run/run_result_create.py +178 -0
  44. hackagent/api/run/run_retrieve.py +163 -0
  45. hackagent/api/run/run_run_tests_create.py +172 -0
  46. hackagent/api/run/run_update.py +186 -0
  47. hackagent/attacks/AdvPrefix/README.md +7 -0
  48. hackagent/attacks/AdvPrefix/__init__.py +0 -0
  49. hackagent/attacks/AdvPrefix/completer.py +438 -0
  50. hackagent/attacks/AdvPrefix/config.py +59 -0
  51. hackagent/attacks/AdvPrefix/preprocessing.py +521 -0
  52. hackagent/attacks/AdvPrefix/scorer.py +259 -0
  53. hackagent/attacks/AdvPrefix/scorer_parser.py +498 -0
  54. hackagent/attacks/AdvPrefix/selector.py +246 -0
  55. hackagent/attacks/AdvPrefix/step1_generate.py +324 -0
  56. hackagent/attacks/AdvPrefix/step4_compute_ce.py +293 -0
  57. hackagent/attacks/AdvPrefix/step6_get_completions.py +387 -0
  58. hackagent/attacks/AdvPrefix/step7_evaluate_responses.py +289 -0
  59. hackagent/attacks/AdvPrefix/step8_aggregate_evaluations.py +177 -0
  60. hackagent/attacks/AdvPrefix/step9_select_prefixes.py +59 -0
  61. hackagent/attacks/AdvPrefix/utils.py +192 -0
  62. hackagent/attacks/__init__.py +6 -0
  63. hackagent/attacks/advprefix.py +1136 -0
  64. hackagent/attacks/base.py +50 -0
  65. hackagent/attacks/strategies.py +539 -0
  66. hackagent/branding.py +143 -0
  67. hackagent/client.py +328 -0
  68. hackagent/errors.py +31 -0
  69. hackagent/logger.py +67 -0
  70. hackagent/models/__init__.py +71 -0
  71. hackagent/models/agent.py +240 -0
  72. hackagent/models/agent_request.py +169 -0
  73. hackagent/models/agent_type_enum.py +12 -0
  74. hackagent/models/attack.py +154 -0
  75. hackagent/models/attack_request.py +82 -0
  76. hackagent/models/evaluation_status_enum.py +14 -0
  77. hackagent/models/organization_minimal.py +68 -0
  78. hackagent/models/paginated_agent_list.py +123 -0
  79. hackagent/models/paginated_attack_list.py +123 -0
  80. hackagent/models/paginated_prompt_list.py +123 -0
  81. hackagent/models/paginated_result_list.py +123 -0
  82. hackagent/models/paginated_run_list.py +123 -0
  83. hackagent/models/paginated_user_api_key_list.py +123 -0
  84. hackagent/models/patched_agent_request.py +176 -0
  85. hackagent/models/patched_attack_request.py +92 -0
  86. hackagent/models/patched_prompt_request.py +162 -0
  87. hackagent/models/patched_result_request.py +237 -0
  88. hackagent/models/patched_run_request.py +138 -0
  89. hackagent/models/prompt.py +226 -0
  90. hackagent/models/prompt_request.py +155 -0
  91. hackagent/models/result.py +294 -0
  92. hackagent/models/result_list_evaluation_status.py +14 -0
  93. hackagent/models/result_request.py +232 -0
  94. hackagent/models/run.py +233 -0
  95. hackagent/models/run_list_status.py +12 -0
  96. hackagent/models/run_request.py +133 -0
  97. hackagent/models/status_enum.py +12 -0
  98. hackagent/models/step_type_enum.py +14 -0
  99. hackagent/models/trace.py +121 -0
  100. hackagent/models/trace_request.py +94 -0
  101. hackagent/models/user_api_key.py +201 -0
  102. hackagent/models/user_api_key_request.py +73 -0
  103. hackagent/models/user_profile_minimal.py +76 -0
  104. hackagent/py.typed +1 -0
  105. hackagent/router/__init__.py +11 -0
  106. hackagent/router/adapters/__init__.py +5 -0
  107. hackagent/router/adapters/google_adk.py +658 -0
  108. hackagent/router/adapters/litellm_adapter.py +290 -0
  109. hackagent/router/base.py +48 -0
  110. hackagent/router/router.py +753 -0
  111. hackagent/types.py +46 -0
  112. hackagent/utils.py +61 -0
  113. hackagent/vulnerabilities/__init__.py +0 -0
  114. hackagent-0.1.0.dist-info/LICENSE +202 -0
  115. hackagent-0.1.0.dist-info/METADATA +173 -0
  116. hackagent-0.1.0.dist-info/RECORD +117 -0
  117. hackagent-0.1.0.dist-info/WHEEL +4 -0
@@ -0,0 +1,160 @@
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.result import Result
9
+ from ...models.result_request import ResultRequest
10
+ from ...types import Response
11
+
12
+
13
+ def _get_kwargs(
14
+ *,
15
+ body: ResultRequest,
16
+ ) -> dict[str, Any]:
17
+ headers: dict[str, Any] = {}
18
+
19
+ _kwargs: dict[str, Any] = {
20
+ "method": "post",
21
+ "url": "/api/result",
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[Result]:
36
+ if response.status_code == 201:
37
+ response_201 = Result.from_dict(response.json())
38
+
39
+ return response_201
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[Result]:
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: ResultRequest,
61
+ ) -> Response[Result]:
62
+ """ViewSet for managing Result instances. Allows creation of Traces via an action.
63
+
64
+ Args:
65
+ body (ResultRequest): Serializer for the Result model, often nested in RunSerializer.
66
+
67
+ Raises:
68
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
69
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
70
+
71
+ Returns:
72
+ Response[Result]
73
+ """
74
+
75
+ kwargs = _get_kwargs(
76
+ body=body,
77
+ )
78
+
79
+ response = client.get_httpx_client().request(
80
+ **kwargs,
81
+ )
82
+
83
+ return _build_response(client=client, response=response)
84
+
85
+
86
+ def sync(
87
+ *,
88
+ client: AuthenticatedClient,
89
+ body: ResultRequest,
90
+ ) -> Optional[Result]:
91
+ """ViewSet for managing Result instances. Allows creation of Traces via an action.
92
+
93
+ Args:
94
+ body (ResultRequest): Serializer for the Result model, often nested in RunSerializer.
95
+
96
+ Raises:
97
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
98
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
99
+
100
+ Returns:
101
+ Result
102
+ """
103
+
104
+ return sync_detailed(
105
+ client=client,
106
+ body=body,
107
+ ).parsed
108
+
109
+
110
+ async def asyncio_detailed(
111
+ *,
112
+ client: AuthenticatedClient,
113
+ body: ResultRequest,
114
+ ) -> Response[Result]:
115
+ """ViewSet for managing Result instances. Allows creation of Traces via an action.
116
+
117
+ Args:
118
+ body (ResultRequest): Serializer for the Result model, often nested in RunSerializer.
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[Result]
126
+ """
127
+
128
+ kwargs = _get_kwargs(
129
+ body=body,
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
+ *,
139
+ client: AuthenticatedClient,
140
+ body: ResultRequest,
141
+ ) -> Optional[Result]:
142
+ """ViewSet for managing Result instances. Allows creation of Traces via an action.
143
+
144
+ Args:
145
+ body (ResultRequest): Serializer for the Result model, often nested in RunSerializer.
146
+
147
+ Raises:
148
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
149
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
150
+
151
+ Returns:
152
+ Result
153
+ """
154
+
155
+ return (
156
+ await asyncio_detailed(
157
+ client=client,
158
+ body=body,
159
+ )
160
+ ).parsed
@@ -0,0 +1,98 @@
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 ...types import Response
10
+
11
+
12
+ def _get_kwargs(
13
+ id: UUID,
14
+ ) -> dict[str, Any]:
15
+ _kwargs: dict[str, Any] = {
16
+ "method": "delete",
17
+ "url": f"/api/result/{id}",
18
+ }
19
+
20
+ return _kwargs
21
+
22
+
23
+ def _parse_response(
24
+ *, client: Union[AuthenticatedClient, Client], response: httpx.Response
25
+ ) -> Optional[Any]:
26
+ if response.status_code == 204:
27
+ return None
28
+ if client.raise_on_unexpected_status:
29
+ raise errors.UnexpectedStatus(response.status_code, response.content)
30
+ else:
31
+ return None
32
+
33
+
34
+ def _build_response(
35
+ *, client: Union[AuthenticatedClient, Client], response: httpx.Response
36
+ ) -> Response[Any]:
37
+ return Response(
38
+ status_code=HTTPStatus(response.status_code),
39
+ content=response.content,
40
+ headers=response.headers,
41
+ parsed=_parse_response(client=client, response=response),
42
+ )
43
+
44
+
45
+ def sync_detailed(
46
+ id: UUID,
47
+ *,
48
+ client: AuthenticatedClient,
49
+ ) -> Response[Any]:
50
+ """ViewSet for managing Result instances. Allows creation of Traces via an action.
51
+
52
+ Args:
53
+ id (UUID):
54
+
55
+ Raises:
56
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
57
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
58
+
59
+ Returns:
60
+ Response[Any]
61
+ """
62
+
63
+ kwargs = _get_kwargs(
64
+ id=id,
65
+ )
66
+
67
+ response = client.get_httpx_client().request(
68
+ **kwargs,
69
+ )
70
+
71
+ return _build_response(client=client, response=response)
72
+
73
+
74
+ async def asyncio_detailed(
75
+ id: UUID,
76
+ *,
77
+ client: AuthenticatedClient,
78
+ ) -> Response[Any]:
79
+ """ViewSet for managing Result instances. Allows creation of Traces via an action.
80
+
81
+ Args:
82
+ id (UUID):
83
+
84
+ Raises:
85
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
86
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
87
+
88
+ Returns:
89
+ Response[Any]
90
+ """
91
+
92
+ kwargs = _get_kwargs(
93
+ id=id,
94
+ )
95
+
96
+ response = await client.get_async_httpx_client().request(**kwargs)
97
+
98
+ return _build_response(client=client, response=response)
@@ -0,0 +1,233 @@
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.paginated_result_list import PaginatedResultList
10
+ from ...models.result_list_evaluation_status import ResultListEvaluationStatus
11
+ from ...types import UNSET, Response, Unset
12
+
13
+
14
+ def _get_kwargs(
15
+ *,
16
+ evaluation_status: Union[Unset, ResultListEvaluationStatus] = UNSET,
17
+ page: Union[Unset, int] = UNSET,
18
+ prompt: Union[Unset, UUID] = UNSET,
19
+ run: Union[Unset, UUID] = UNSET,
20
+ run_organization: Union[Unset, UUID] = UNSET,
21
+ ) -> dict[str, Any]:
22
+ params: dict[str, Any] = {}
23
+
24
+ json_evaluation_status: Union[Unset, str] = UNSET
25
+ if not isinstance(evaluation_status, Unset):
26
+ json_evaluation_status = evaluation_status.value
27
+
28
+ params["evaluation_status"] = json_evaluation_status
29
+
30
+ params["page"] = page
31
+
32
+ json_prompt: Union[Unset, str] = UNSET
33
+ if not isinstance(prompt, Unset):
34
+ json_prompt = str(prompt)
35
+ params["prompt"] = json_prompt
36
+
37
+ json_run: Union[Unset, str] = UNSET
38
+ if not isinstance(run, Unset):
39
+ json_run = str(run)
40
+ params["run"] = json_run
41
+
42
+ json_run_organization: Union[Unset, str] = UNSET
43
+ if not isinstance(run_organization, Unset):
44
+ json_run_organization = str(run_organization)
45
+ params["run__organization"] = json_run_organization
46
+
47
+ params = {k: v for k, v in params.items() if v is not UNSET and v is not None}
48
+
49
+ _kwargs: dict[str, Any] = {
50
+ "method": "get",
51
+ "url": "/api/result",
52
+ "params": params,
53
+ }
54
+
55
+ return _kwargs
56
+
57
+
58
+ def _parse_response(
59
+ *, client: Union[AuthenticatedClient, Client], response: httpx.Response
60
+ ) -> Optional[PaginatedResultList]:
61
+ if response.status_code == 200:
62
+ response_200 = PaginatedResultList.from_dict(response.json())
63
+
64
+ return response_200
65
+ if client.raise_on_unexpected_status:
66
+ raise errors.UnexpectedStatus(response.status_code, response.content)
67
+ else:
68
+ return None
69
+
70
+
71
+ def _build_response(
72
+ *, client: Union[AuthenticatedClient, Client], response: httpx.Response
73
+ ) -> Response[PaginatedResultList]:
74
+ return Response(
75
+ status_code=HTTPStatus(response.status_code),
76
+ content=response.content,
77
+ headers=response.headers,
78
+ parsed=_parse_response(client=client, response=response),
79
+ )
80
+
81
+
82
+ def sync_detailed(
83
+ *,
84
+ client: AuthenticatedClient,
85
+ evaluation_status: Union[Unset, ResultListEvaluationStatus] = UNSET,
86
+ page: Union[Unset, int] = UNSET,
87
+ prompt: Union[Unset, UUID] = UNSET,
88
+ run: Union[Unset, UUID] = UNSET,
89
+ run_organization: Union[Unset, UUID] = UNSET,
90
+ ) -> Response[PaginatedResultList]:
91
+ """ViewSet for managing Result instances. Allows creation of Traces via an action.
92
+
93
+ Args:
94
+ evaluation_status (Union[Unset, ResultListEvaluationStatus]):
95
+ page (Union[Unset, int]):
96
+ prompt (Union[Unset, UUID]):
97
+ run (Union[Unset, UUID]):
98
+ run_organization (Union[Unset, UUID]):
99
+
100
+ Raises:
101
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
102
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
103
+
104
+ Returns:
105
+ Response[PaginatedResultList]
106
+ """
107
+
108
+ kwargs = _get_kwargs(
109
+ evaluation_status=evaluation_status,
110
+ page=page,
111
+ prompt=prompt,
112
+ run=run,
113
+ run_organization=run_organization,
114
+ )
115
+
116
+ response = client.get_httpx_client().request(
117
+ **kwargs,
118
+ )
119
+
120
+ return _build_response(client=client, response=response)
121
+
122
+
123
+ def sync(
124
+ *,
125
+ client: AuthenticatedClient,
126
+ evaluation_status: Union[Unset, ResultListEvaluationStatus] = UNSET,
127
+ page: Union[Unset, int] = UNSET,
128
+ prompt: Union[Unset, UUID] = UNSET,
129
+ run: Union[Unset, UUID] = UNSET,
130
+ run_organization: Union[Unset, UUID] = UNSET,
131
+ ) -> Optional[PaginatedResultList]:
132
+ """ViewSet for managing Result instances. Allows creation of Traces via an action.
133
+
134
+ Args:
135
+ evaluation_status (Union[Unset, ResultListEvaluationStatus]):
136
+ page (Union[Unset, int]):
137
+ prompt (Union[Unset, UUID]):
138
+ run (Union[Unset, UUID]):
139
+ run_organization (Union[Unset, UUID]):
140
+
141
+ Raises:
142
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
143
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
144
+
145
+ Returns:
146
+ PaginatedResultList
147
+ """
148
+
149
+ return sync_detailed(
150
+ client=client,
151
+ evaluation_status=evaluation_status,
152
+ page=page,
153
+ prompt=prompt,
154
+ run=run,
155
+ run_organization=run_organization,
156
+ ).parsed
157
+
158
+
159
+ async def asyncio_detailed(
160
+ *,
161
+ client: AuthenticatedClient,
162
+ evaluation_status: Union[Unset, ResultListEvaluationStatus] = UNSET,
163
+ page: Union[Unset, int] = UNSET,
164
+ prompt: Union[Unset, UUID] = UNSET,
165
+ run: Union[Unset, UUID] = UNSET,
166
+ run_organization: Union[Unset, UUID] = UNSET,
167
+ ) -> Response[PaginatedResultList]:
168
+ """ViewSet for managing Result instances. Allows creation of Traces via an action.
169
+
170
+ Args:
171
+ evaluation_status (Union[Unset, ResultListEvaluationStatus]):
172
+ page (Union[Unset, int]):
173
+ prompt (Union[Unset, UUID]):
174
+ run (Union[Unset, UUID]):
175
+ run_organization (Union[Unset, UUID]):
176
+
177
+ Raises:
178
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
179
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
180
+
181
+ Returns:
182
+ Response[PaginatedResultList]
183
+ """
184
+
185
+ kwargs = _get_kwargs(
186
+ evaluation_status=evaluation_status,
187
+ page=page,
188
+ prompt=prompt,
189
+ run=run,
190
+ run_organization=run_organization,
191
+ )
192
+
193
+ response = await client.get_async_httpx_client().request(**kwargs)
194
+
195
+ return _build_response(client=client, response=response)
196
+
197
+
198
+ async def asyncio(
199
+ *,
200
+ client: AuthenticatedClient,
201
+ evaluation_status: Union[Unset, ResultListEvaluationStatus] = UNSET,
202
+ page: Union[Unset, int] = UNSET,
203
+ prompt: Union[Unset, UUID] = UNSET,
204
+ run: Union[Unset, UUID] = UNSET,
205
+ run_organization: Union[Unset, UUID] = UNSET,
206
+ ) -> Optional[PaginatedResultList]:
207
+ """ViewSet for managing Result instances. Allows creation of Traces via an action.
208
+
209
+ Args:
210
+ evaluation_status (Union[Unset, ResultListEvaluationStatus]):
211
+ page (Union[Unset, int]):
212
+ prompt (Union[Unset, UUID]):
213
+ run (Union[Unset, UUID]):
214
+ run_organization (Union[Unset, UUID]):
215
+
216
+ Raises:
217
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
218
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
219
+
220
+ Returns:
221
+ PaginatedResultList
222
+ """
223
+
224
+ return (
225
+ await asyncio_detailed(
226
+ client=client,
227
+ evaluation_status=evaluation_status,
228
+ page=page,
229
+ prompt=prompt,
230
+ run=run,
231
+ run_organization=run_organization,
232
+ )
233
+ ).parsed
@@ -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.patched_result_request import PatchedResultRequest
10
+ from ...models.result import Result
11
+ from ...types import Response
12
+
13
+
14
+ def _get_kwargs(
15
+ id: UUID,
16
+ *,
17
+ body: PatchedResultRequest,
18
+ ) -> dict[str, Any]:
19
+ headers: dict[str, Any] = {}
20
+
21
+ _kwargs: dict[str, Any] = {
22
+ "method": "patch",
23
+ "url": f"/api/result/{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[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: PatchedResultRequest,
64
+ ) -> Response[Result]:
65
+ """ViewSet for managing Result instances. Allows creation of Traces via an action.
66
+
67
+ Args:
68
+ id (UUID):
69
+ body (PatchedResultRequest): Serializer for the Result model, often nested in
70
+ 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: PatchedResultRequest,
97
+ ) -> Optional[Result]:
98
+ """ViewSet for managing Result instances. Allows creation of Traces via an action.
99
+
100
+ Args:
101
+ id (UUID):
102
+ body (PatchedResultRequest): Serializer for the Result model, often nested in
103
+ 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: PatchedResultRequest,
125
+ ) -> Response[Result]:
126
+ """ViewSet for managing Result instances. Allows creation of Traces via an action.
127
+
128
+ Args:
129
+ id (UUID):
130
+ body (PatchedResultRequest): Serializer for the Result model, often nested in
131
+ 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: PatchedResultRequest,
156
+ ) -> Optional[Result]:
157
+ """ViewSet for managing Result instances. Allows creation of Traces via an action.
158
+
159
+ Args:
160
+ id (UUID):
161
+ body (PatchedResultRequest): Serializer for the Result model, often nested in
162
+ 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