hackagent 0.3.1__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 (183) hide show
  1. hackagent/__init__.py +12 -0
  2. hackagent/agent.py +214 -0
  3. hackagent/api/__init__.py +1 -0
  4. hackagent/api/agent/__init__.py +1 -0
  5. hackagent/api/agent/agent_create.py +347 -0
  6. hackagent/api/agent/agent_destroy.py +140 -0
  7. hackagent/api/agent/agent_list.py +242 -0
  8. hackagent/api/agent/agent_partial_update.py +361 -0
  9. hackagent/api/agent/agent_retrieve.py +235 -0
  10. hackagent/api/agent/agent_update.py +361 -0
  11. hackagent/api/apilogs/__init__.py +1 -0
  12. hackagent/api/apilogs/apilogs_list.py +170 -0
  13. hackagent/api/apilogs/apilogs_retrieve.py +162 -0
  14. hackagent/api/attack/__init__.py +1 -0
  15. hackagent/api/attack/attack_create.py +275 -0
  16. hackagent/api/attack/attack_destroy.py +146 -0
  17. hackagent/api/attack/attack_list.py +254 -0
  18. hackagent/api/attack/attack_partial_update.py +289 -0
  19. hackagent/api/attack/attack_retrieve.py +247 -0
  20. hackagent/api/attack/attack_update.py +289 -0
  21. hackagent/api/checkout/__init__.py +1 -0
  22. hackagent/api/checkout/checkout_create.py +225 -0
  23. hackagent/api/generate/__init__.py +1 -0
  24. hackagent/api/generate/generate_create.py +253 -0
  25. hackagent/api/judge/__init__.py +1 -0
  26. hackagent/api/judge/judge_create.py +253 -0
  27. hackagent/api/key/__init__.py +1 -0
  28. hackagent/api/key/key_create.py +179 -0
  29. hackagent/api/key/key_destroy.py +103 -0
  30. hackagent/api/key/key_list.py +170 -0
  31. hackagent/api/key/key_retrieve.py +162 -0
  32. hackagent/api/organization/__init__.py +1 -0
  33. hackagent/api/organization/organization_create.py +208 -0
  34. hackagent/api/organization/organization_destroy.py +104 -0
  35. hackagent/api/organization/organization_list.py +170 -0
  36. hackagent/api/organization/organization_me_retrieve.py +126 -0
  37. hackagent/api/organization/organization_partial_update.py +222 -0
  38. hackagent/api/organization/organization_retrieve.py +163 -0
  39. hackagent/api/organization/organization_update.py +222 -0
  40. hackagent/api/prompt/__init__.py +1 -0
  41. hackagent/api/prompt/prompt_create.py +171 -0
  42. hackagent/api/prompt/prompt_destroy.py +104 -0
  43. hackagent/api/prompt/prompt_list.py +185 -0
  44. hackagent/api/prompt/prompt_partial_update.py +185 -0
  45. hackagent/api/prompt/prompt_retrieve.py +163 -0
  46. hackagent/api/prompt/prompt_update.py +185 -0
  47. hackagent/api/result/__init__.py +1 -0
  48. hackagent/api/result/result_create.py +175 -0
  49. hackagent/api/result/result_destroy.py +106 -0
  50. hackagent/api/result/result_list.py +249 -0
  51. hackagent/api/result/result_partial_update.py +193 -0
  52. hackagent/api/result/result_retrieve.py +167 -0
  53. hackagent/api/result/result_trace_create.py +177 -0
  54. hackagent/api/result/result_update.py +189 -0
  55. hackagent/api/run/__init__.py +1 -0
  56. hackagent/api/run/run_create.py +187 -0
  57. hackagent/api/run/run_destroy.py +112 -0
  58. hackagent/api/run/run_list.py +291 -0
  59. hackagent/api/run/run_partial_update.py +201 -0
  60. hackagent/api/run/run_result_create.py +177 -0
  61. hackagent/api/run/run_retrieve.py +179 -0
  62. hackagent/api/run/run_run_tests_create.py +187 -0
  63. hackagent/api/run/run_update.py +201 -0
  64. hackagent/api/user/__init__.py +1 -0
  65. hackagent/api/user/user_create.py +212 -0
  66. hackagent/api/user/user_destroy.py +106 -0
  67. hackagent/api/user/user_list.py +174 -0
  68. hackagent/api/user/user_me_retrieve.py +126 -0
  69. hackagent/api/user/user_me_update.py +196 -0
  70. hackagent/api/user/user_partial_update.py +226 -0
  71. hackagent/api/user/user_retrieve.py +167 -0
  72. hackagent/api/user/user_update.py +226 -0
  73. hackagent/attacks/AdvPrefix/__init__.py +41 -0
  74. hackagent/attacks/AdvPrefix/completions.py +416 -0
  75. hackagent/attacks/AdvPrefix/config.py +259 -0
  76. hackagent/attacks/AdvPrefix/evaluation.py +745 -0
  77. hackagent/attacks/AdvPrefix/evaluators.py +564 -0
  78. hackagent/attacks/AdvPrefix/generate.py +711 -0
  79. hackagent/attacks/AdvPrefix/utils.py +307 -0
  80. hackagent/attacks/__init__.py +35 -0
  81. hackagent/attacks/advprefix.py +507 -0
  82. hackagent/attacks/base.py +106 -0
  83. hackagent/attacks/strategies.py +906 -0
  84. hackagent/cli/__init__.py +19 -0
  85. hackagent/cli/commands/__init__.py +20 -0
  86. hackagent/cli/commands/agent.py +100 -0
  87. hackagent/cli/commands/attack.py +417 -0
  88. hackagent/cli/commands/config.py +301 -0
  89. hackagent/cli/commands/results.py +327 -0
  90. hackagent/cli/config.py +249 -0
  91. hackagent/cli/main.py +515 -0
  92. hackagent/cli/tui/__init__.py +31 -0
  93. hackagent/cli/tui/actions_logger.py +200 -0
  94. hackagent/cli/tui/app.py +288 -0
  95. hackagent/cli/tui/base.py +137 -0
  96. hackagent/cli/tui/logger.py +318 -0
  97. hackagent/cli/tui/views/__init__.py +33 -0
  98. hackagent/cli/tui/views/agents.py +488 -0
  99. hackagent/cli/tui/views/attacks.py +624 -0
  100. hackagent/cli/tui/views/config.py +244 -0
  101. hackagent/cli/tui/views/dashboard.py +307 -0
  102. hackagent/cli/tui/views/results.py +1210 -0
  103. hackagent/cli/tui/widgets/__init__.py +24 -0
  104. hackagent/cli/tui/widgets/actions.py +346 -0
  105. hackagent/cli/tui/widgets/logs.py +435 -0
  106. hackagent/cli/utils.py +276 -0
  107. hackagent/client.py +286 -0
  108. hackagent/errors.py +37 -0
  109. hackagent/logger.py +83 -0
  110. hackagent/models/__init__.py +109 -0
  111. hackagent/models/agent.py +223 -0
  112. hackagent/models/agent_request.py +129 -0
  113. hackagent/models/api_token_log.py +184 -0
  114. hackagent/models/attack.py +154 -0
  115. hackagent/models/attack_request.py +82 -0
  116. hackagent/models/checkout_session_request_request.py +76 -0
  117. hackagent/models/checkout_session_response.py +59 -0
  118. hackagent/models/choice.py +81 -0
  119. hackagent/models/choice_message.py +67 -0
  120. hackagent/models/evaluation_status_enum.py +14 -0
  121. hackagent/models/generate_error_response.py +59 -0
  122. hackagent/models/generate_request_request.py +212 -0
  123. hackagent/models/generate_success_response.py +115 -0
  124. hackagent/models/generic_error_response.py +70 -0
  125. hackagent/models/message_request.py +67 -0
  126. hackagent/models/organization.py +102 -0
  127. hackagent/models/organization_minimal.py +68 -0
  128. hackagent/models/organization_request.py +71 -0
  129. hackagent/models/paginated_agent_list.py +123 -0
  130. hackagent/models/paginated_api_token_log_list.py +123 -0
  131. hackagent/models/paginated_attack_list.py +123 -0
  132. hackagent/models/paginated_organization_list.py +123 -0
  133. hackagent/models/paginated_prompt_list.py +123 -0
  134. hackagent/models/paginated_result_list.py +123 -0
  135. hackagent/models/paginated_run_list.py +123 -0
  136. hackagent/models/paginated_user_api_key_list.py +123 -0
  137. hackagent/models/paginated_user_profile_list.py +123 -0
  138. hackagent/models/patched_agent_request.py +128 -0
  139. hackagent/models/patched_attack_request.py +92 -0
  140. hackagent/models/patched_organization_request.py +71 -0
  141. hackagent/models/patched_prompt_request.py +125 -0
  142. hackagent/models/patched_result_request.py +237 -0
  143. hackagent/models/patched_run_request.py +138 -0
  144. hackagent/models/patched_user_profile_request.py +99 -0
  145. hackagent/models/prompt.py +220 -0
  146. hackagent/models/prompt_request.py +126 -0
  147. hackagent/models/result.py +294 -0
  148. hackagent/models/result_list_evaluation_status.py +14 -0
  149. hackagent/models/result_request.py +232 -0
  150. hackagent/models/run.py +233 -0
  151. hackagent/models/run_list_status.py +12 -0
  152. hackagent/models/run_request.py +133 -0
  153. hackagent/models/status_enum.py +12 -0
  154. hackagent/models/step_type_enum.py +14 -0
  155. hackagent/models/trace.py +121 -0
  156. hackagent/models/trace_request.py +94 -0
  157. hackagent/models/usage.py +75 -0
  158. hackagent/models/user_api_key.py +201 -0
  159. hackagent/models/user_api_key_request.py +73 -0
  160. hackagent/models/user_profile.py +135 -0
  161. hackagent/models/user_profile_minimal.py +76 -0
  162. hackagent/models/user_profile_request.py +99 -0
  163. hackagent/router/__init__.py +25 -0
  164. hackagent/router/adapters/__init__.py +20 -0
  165. hackagent/router/adapters/base.py +63 -0
  166. hackagent/router/adapters/google_adk.py +671 -0
  167. hackagent/router/adapters/litellm_adapter.py +524 -0
  168. hackagent/router/adapters/openai_adapter.py +426 -0
  169. hackagent/router/router.py +969 -0
  170. hackagent/router/types.py +54 -0
  171. hackagent/tracking/__init__.py +42 -0
  172. hackagent/tracking/context.py +163 -0
  173. hackagent/tracking/decorators.py +299 -0
  174. hackagent/tracking/tracker.py +441 -0
  175. hackagent/types.py +54 -0
  176. hackagent/utils.py +194 -0
  177. hackagent/vulnerabilities/__init__.py +13 -0
  178. hackagent/vulnerabilities/prompts.py +81 -0
  179. hackagent-0.3.1.dist-info/METADATA +122 -0
  180. hackagent-0.3.1.dist-info/RECORD +183 -0
  181. hackagent-0.3.1.dist-info/WHEEL +4 -0
  182. hackagent-0.3.1.dist-info/entry_points.txt +2 -0
  183. hackagent-0.3.1.dist-info/licenses/LICENSE +202 -0
@@ -0,0 +1,82 @@
1
+ from collections.abc import Mapping
2
+ from typing import Any, TypeVar
3
+ from uuid import UUID
4
+
5
+ from attrs import define as _attrs_define
6
+ from attrs import field as _attrs_field
7
+
8
+ T = TypeVar("T", bound="AttackRequest")
9
+
10
+
11
+ @_attrs_define
12
+ class AttackRequest:
13
+ """Serializer for the Attack model, which represents an Attack configuration.
14
+
15
+ Handles the conversion of Attack configuration instances to JSON (and vice-versa)
16
+ for API requests and responses. It includes read-only fields for related
17
+ object names (like agent_name, owner_username) for convenience in API outputs.
18
+
19
+ Attributes:
20
+ type_ (str): A string identifier for the type of attack being configured (e.g., 'PREFIX_GENERATION',
21
+ 'PROMPT_INJECTION').
22
+ agent (UUID):
23
+ configuration (Any): JSON containing client-provided configuration for an attack using this definition.
24
+ """
25
+
26
+ type_: str
27
+ agent: UUID
28
+ configuration: Any
29
+ additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
30
+
31
+ def to_dict(self) -> dict[str, Any]:
32
+ type_ = self.type_
33
+
34
+ agent = str(self.agent)
35
+
36
+ configuration = self.configuration
37
+
38
+ field_dict: dict[str, Any] = {}
39
+ field_dict.update(self.additional_properties)
40
+ field_dict.update(
41
+ {
42
+ "type": type_,
43
+ "agent": agent,
44
+ "configuration": configuration,
45
+ }
46
+ )
47
+
48
+ return field_dict
49
+
50
+ @classmethod
51
+ def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
52
+ d = dict(src_dict)
53
+ type_ = d.pop("type")
54
+
55
+ agent = UUID(d.pop("agent"))
56
+
57
+ configuration = d.pop("configuration")
58
+
59
+ attack_request = cls(
60
+ type_=type_,
61
+ agent=agent,
62
+ configuration=configuration,
63
+ )
64
+
65
+ attack_request.additional_properties = d
66
+ return attack_request
67
+
68
+ @property
69
+ def additional_keys(self) -> list[str]:
70
+ return list(self.additional_properties.keys())
71
+
72
+ def __getitem__(self, key: str) -> Any:
73
+ return self.additional_properties[key]
74
+
75
+ def __setitem__(self, key: str, value: Any) -> None:
76
+ self.additional_properties[key] = value
77
+
78
+ def __delitem__(self, key: str) -> None:
79
+ del self.additional_properties[key]
80
+
81
+ def __contains__(self, key: str) -> bool:
82
+ return key in self.additional_properties
@@ -0,0 +1,76 @@
1
+ from collections.abc import Mapping
2
+ from typing import Any, TypeVar
3
+
4
+ from attrs import define as _attrs_define
5
+ from attrs import field as _attrs_field
6
+
7
+ from .. import types
8
+
9
+ T = TypeVar("T", bound="CheckoutSessionRequestRequest")
10
+
11
+
12
+ @_attrs_define
13
+ class CheckoutSessionRequestRequest:
14
+ """
15
+ Attributes:
16
+ credits_to_purchase (int): Number of credits the user wants to purchase.
17
+ """
18
+
19
+ credits_to_purchase: int
20
+ additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
21
+
22
+ def to_dict(self) -> dict[str, Any]:
23
+ credits_to_purchase = self.credits_to_purchase
24
+
25
+ field_dict: dict[str, Any] = {}
26
+ field_dict.update(self.additional_properties)
27
+ field_dict.update(
28
+ {
29
+ "credits_to_purchase": credits_to_purchase,
30
+ }
31
+ )
32
+
33
+ return field_dict
34
+
35
+ def to_multipart(self) -> types.RequestFiles:
36
+ files: types.RequestFiles = []
37
+
38
+ files.append(
39
+ (
40
+ "credits_to_purchase",
41
+ (None, str(self.credits_to_purchase).encode(), "text/plain"),
42
+ )
43
+ )
44
+
45
+ for prop_name, prop in self.additional_properties.items():
46
+ files.append((prop_name, (None, str(prop).encode(), "text/plain")))
47
+
48
+ return files
49
+
50
+ @classmethod
51
+ def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
52
+ d = dict(src_dict)
53
+ credits_to_purchase = d.pop("credits_to_purchase")
54
+
55
+ checkout_session_request_request = cls(
56
+ credits_to_purchase=credits_to_purchase,
57
+ )
58
+
59
+ checkout_session_request_request.additional_properties = d
60
+ return checkout_session_request_request
61
+
62
+ @property
63
+ def additional_keys(self) -> list[str]:
64
+ return list(self.additional_properties.keys())
65
+
66
+ def __getitem__(self, key: str) -> Any:
67
+ return self.additional_properties[key]
68
+
69
+ def __setitem__(self, key: str, value: Any) -> None:
70
+ self.additional_properties[key] = value
71
+
72
+ def __delitem__(self, key: str) -> None:
73
+ del self.additional_properties[key]
74
+
75
+ def __contains__(self, key: str) -> bool:
76
+ return key in self.additional_properties
@@ -0,0 +1,59 @@
1
+ from collections.abc import Mapping
2
+ from typing import Any, TypeVar
3
+
4
+ from attrs import define as _attrs_define
5
+ from attrs import field as _attrs_field
6
+
7
+ T = TypeVar("T", bound="CheckoutSessionResponse")
8
+
9
+
10
+ @_attrs_define
11
+ class CheckoutSessionResponse:
12
+ """
13
+ Attributes:
14
+ checkout_url (str): The URL to redirect the user to for Stripe Checkout.
15
+ """
16
+
17
+ checkout_url: str
18
+ additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
19
+
20
+ def to_dict(self) -> dict[str, Any]:
21
+ checkout_url = self.checkout_url
22
+
23
+ field_dict: dict[str, Any] = {}
24
+ field_dict.update(self.additional_properties)
25
+ field_dict.update(
26
+ {
27
+ "checkout_url": checkout_url,
28
+ }
29
+ )
30
+
31
+ return field_dict
32
+
33
+ @classmethod
34
+ def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
35
+ d = dict(src_dict)
36
+ checkout_url = d.pop("checkout_url")
37
+
38
+ checkout_session_response = cls(
39
+ checkout_url=checkout_url,
40
+ )
41
+
42
+ checkout_session_response.additional_properties = d
43
+ return checkout_session_response
44
+
45
+ @property
46
+ def additional_keys(self) -> list[str]:
47
+ return list(self.additional_properties.keys())
48
+
49
+ def __getitem__(self, key: str) -> Any:
50
+ return self.additional_properties[key]
51
+
52
+ def __setitem__(self, key: str, value: Any) -> None:
53
+ self.additional_properties[key] = value
54
+
55
+ def __delitem__(self, key: str) -> None:
56
+ del self.additional_properties[key]
57
+
58
+ def __contains__(self, key: str) -> bool:
59
+ return key in self.additional_properties
@@ -0,0 +1,81 @@
1
+ from collections.abc import Mapping
2
+ from typing import TYPE_CHECKING, Any, TypeVar
3
+
4
+ from attrs import define as _attrs_define
5
+ from attrs import field as _attrs_field
6
+
7
+ if TYPE_CHECKING:
8
+ from ..models.choice_message import ChoiceMessage
9
+
10
+
11
+ T = TypeVar("T", bound="Choice")
12
+
13
+
14
+ @_attrs_define
15
+ class Choice:
16
+ """
17
+ Attributes:
18
+ index (int): Index of the choice
19
+ message (ChoiceMessage):
20
+ finish_reason (str): Reason for completion (stop, length, etc.)
21
+ """
22
+
23
+ index: int
24
+ message: "ChoiceMessage"
25
+ finish_reason: str
26
+ additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
27
+
28
+ def to_dict(self) -> dict[str, Any]:
29
+ index = self.index
30
+
31
+ message = self.message.to_dict()
32
+
33
+ finish_reason = self.finish_reason
34
+
35
+ field_dict: dict[str, Any] = {}
36
+ field_dict.update(self.additional_properties)
37
+ field_dict.update(
38
+ {
39
+ "index": index,
40
+ "message": message,
41
+ "finish_reason": finish_reason,
42
+ }
43
+ )
44
+
45
+ return field_dict
46
+
47
+ @classmethod
48
+ def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
49
+ from ..models.choice_message import ChoiceMessage
50
+
51
+ d = dict(src_dict)
52
+ index = d.pop("index")
53
+
54
+ message = ChoiceMessage.from_dict(d.pop("message"))
55
+
56
+ finish_reason = d.pop("finish_reason")
57
+
58
+ choice = cls(
59
+ index=index,
60
+ message=message,
61
+ finish_reason=finish_reason,
62
+ )
63
+
64
+ choice.additional_properties = d
65
+ return choice
66
+
67
+ @property
68
+ def additional_keys(self) -> list[str]:
69
+ return list(self.additional_properties.keys())
70
+
71
+ def __getitem__(self, key: str) -> Any:
72
+ return self.additional_properties[key]
73
+
74
+ def __setitem__(self, key: str, value: Any) -> None:
75
+ self.additional_properties[key] = value
76
+
77
+ def __delitem__(self, key: str) -> None:
78
+ del self.additional_properties[key]
79
+
80
+ def __contains__(self, key: str) -> bool:
81
+ return key in self.additional_properties
@@ -0,0 +1,67 @@
1
+ from collections.abc import Mapping
2
+ from typing import Any, TypeVar
3
+
4
+ from attrs import define as _attrs_define
5
+ from attrs import field as _attrs_field
6
+
7
+ T = TypeVar("T", bound="ChoiceMessage")
8
+
9
+
10
+ @_attrs_define
11
+ class ChoiceMessage:
12
+ """
13
+ Attributes:
14
+ role (str): Role of the message sender
15
+ content (str): Generated content
16
+ """
17
+
18
+ role: str
19
+ content: str
20
+ additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
21
+
22
+ def to_dict(self) -> dict[str, Any]:
23
+ role = self.role
24
+
25
+ content = self.content
26
+
27
+ field_dict: dict[str, Any] = {}
28
+ field_dict.update(self.additional_properties)
29
+ field_dict.update(
30
+ {
31
+ "role": role,
32
+ "content": content,
33
+ }
34
+ )
35
+
36
+ return field_dict
37
+
38
+ @classmethod
39
+ def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
40
+ d = dict(src_dict)
41
+ role = d.pop("role")
42
+
43
+ content = d.pop("content")
44
+
45
+ choice_message = cls(
46
+ role=role,
47
+ content=content,
48
+ )
49
+
50
+ choice_message.additional_properties = d
51
+ return choice_message
52
+
53
+ @property
54
+ def additional_keys(self) -> list[str]:
55
+ return list(self.additional_properties.keys())
56
+
57
+ def __getitem__(self, key: str) -> Any:
58
+ return self.additional_properties[key]
59
+
60
+ def __setitem__(self, key: str, value: Any) -> None:
61
+ self.additional_properties[key] = value
62
+
63
+ def __delitem__(self, key: str) -> None:
64
+ del self.additional_properties[key]
65
+
66
+ def __contains__(self, key: str) -> bool:
67
+ return key in self.additional_properties
@@ -0,0 +1,14 @@
1
+ from enum import Enum
2
+
3
+
4
+ class EvaluationStatusEnum(str, Enum):
5
+ ERROR_AGENT_RESPONSE = "ERROR_AGENT_RESPONSE"
6
+ ERROR_TEST_FRAMEWORK = "ERROR_TEST_FRAMEWORK"
7
+ FAILED_CRITERIA = "FAILED_CRITERIA"
8
+ FAILED_JAILBREAK = "FAILED_JAILBREAK"
9
+ NOT_EVALUATED = "NOT_EVALUATED"
10
+ PASSED_CRITERIA = "PASSED_CRITERIA"
11
+ SUCCESSFUL_JAILBREAK = "SUCCESSFUL_JAILBREAK"
12
+
13
+ def __str__(self) -> str:
14
+ return str(self.value)
@@ -0,0 +1,59 @@
1
+ from collections.abc import Mapping
2
+ from typing import Any, TypeVar
3
+
4
+ from attrs import define as _attrs_define
5
+ from attrs import field as _attrs_field
6
+
7
+ T = TypeVar("T", bound="GenerateErrorResponse")
8
+
9
+
10
+ @_attrs_define
11
+ class GenerateErrorResponse:
12
+ """
13
+ Attributes:
14
+ error (str): Description of the error that occurred.
15
+ """
16
+
17
+ error: str
18
+ additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
19
+
20
+ def to_dict(self) -> dict[str, Any]:
21
+ error = self.error
22
+
23
+ field_dict: dict[str, Any] = {}
24
+ field_dict.update(self.additional_properties)
25
+ field_dict.update(
26
+ {
27
+ "error": error,
28
+ }
29
+ )
30
+
31
+ return field_dict
32
+
33
+ @classmethod
34
+ def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
35
+ d = dict(src_dict)
36
+ error = d.pop("error")
37
+
38
+ generate_error_response = cls(
39
+ error=error,
40
+ )
41
+
42
+ generate_error_response.additional_properties = d
43
+ return generate_error_response
44
+
45
+ @property
46
+ def additional_keys(self) -> list[str]:
47
+ return list(self.additional_properties.keys())
48
+
49
+ def __getitem__(self, key: str) -> Any:
50
+ return self.additional_properties[key]
51
+
52
+ def __setitem__(self, key: str, value: Any) -> None:
53
+ self.additional_properties[key] = value
54
+
55
+ def __delitem__(self, key: str) -> None:
56
+ del self.additional_properties[key]
57
+
58
+ def __contains__(self, key: str) -> bool:
59
+ return key in self.additional_properties
@@ -0,0 +1,212 @@
1
+ import json
2
+ from collections.abc import Mapping
3
+ from typing import TYPE_CHECKING, Any, TypeVar, Union, cast
4
+
5
+ from attrs import define as _attrs_define
6
+ from attrs import field as _attrs_field
7
+
8
+ from .. import types
9
+ from ..types import UNSET, Unset
10
+
11
+ if TYPE_CHECKING:
12
+ from ..models.message_request import MessageRequest
13
+
14
+
15
+ T = TypeVar("T", bound="GenerateRequestRequest")
16
+
17
+
18
+ @_attrs_define
19
+ class GenerateRequestRequest:
20
+ """
21
+ Attributes:
22
+ messages (list['MessageRequest']): Array of conversation messages
23
+ model (Union[Unset, str]): Client-specified model (will be overridden by server)
24
+ stream (Union[Unset, bool]): Whether to stream the response Default: False.
25
+ temperature (Union[Unset, float]): Sampling temperature (0-2)
26
+ max_tokens (Union[Unset, int]): Maximum tokens to generate
27
+ top_p (Union[Unset, float]): Nucleus sampling threshold
28
+ frequency_penalty (Union[Unset, float]): Frequency penalty (-2.0 to 2.0)
29
+ presence_penalty (Union[Unset, float]): Presence penalty (-2.0 to 2.0)
30
+ stop (Union[Unset, list[str]]): Sequences where the API will stop generating
31
+ """
32
+
33
+ messages: list["MessageRequest"]
34
+ model: Union[Unset, str] = UNSET
35
+ stream: Union[Unset, bool] = False
36
+ temperature: Union[Unset, float] = UNSET
37
+ max_tokens: Union[Unset, int] = UNSET
38
+ top_p: Union[Unset, float] = UNSET
39
+ frequency_penalty: Union[Unset, float] = UNSET
40
+ presence_penalty: Union[Unset, float] = UNSET
41
+ stop: Union[Unset, list[str]] = UNSET
42
+ additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
43
+
44
+ def to_dict(self) -> dict[str, Any]:
45
+ messages = []
46
+ for messages_item_data in self.messages:
47
+ messages_item = messages_item_data.to_dict()
48
+ messages.append(messages_item)
49
+
50
+ model = self.model
51
+
52
+ stream = self.stream
53
+
54
+ temperature = self.temperature
55
+
56
+ max_tokens = self.max_tokens
57
+
58
+ top_p = self.top_p
59
+
60
+ frequency_penalty = self.frequency_penalty
61
+
62
+ presence_penalty = self.presence_penalty
63
+
64
+ stop: Union[Unset, list[str]] = UNSET
65
+ if not isinstance(self.stop, Unset):
66
+ stop = self.stop
67
+
68
+ field_dict: dict[str, Any] = {}
69
+ field_dict.update(self.additional_properties)
70
+ field_dict.update(
71
+ {
72
+ "messages": messages,
73
+ }
74
+ )
75
+ if model is not UNSET:
76
+ field_dict["model"] = model
77
+ if stream is not UNSET:
78
+ field_dict["stream"] = stream
79
+ if temperature is not UNSET:
80
+ field_dict["temperature"] = temperature
81
+ if max_tokens is not UNSET:
82
+ field_dict["max_tokens"] = max_tokens
83
+ if top_p is not UNSET:
84
+ field_dict["top_p"] = top_p
85
+ if frequency_penalty is not UNSET:
86
+ field_dict["frequency_penalty"] = frequency_penalty
87
+ if presence_penalty is not UNSET:
88
+ field_dict["presence_penalty"] = presence_penalty
89
+ if stop is not UNSET:
90
+ field_dict["stop"] = stop
91
+
92
+ return field_dict
93
+
94
+ def to_multipart(self) -> types.RequestFiles:
95
+ files: types.RequestFiles = []
96
+
97
+ for messages_item_element in self.messages:
98
+ files.append(
99
+ (
100
+ "messages",
101
+ (
102
+ None,
103
+ json.dumps(messages_item_element.to_dict()).encode(),
104
+ "application/json",
105
+ ),
106
+ )
107
+ )
108
+
109
+ if not isinstance(self.model, Unset):
110
+ files.append(("model", (None, str(self.model).encode(), "text/plain")))
111
+
112
+ if not isinstance(self.stream, Unset):
113
+ files.append(("stream", (None, str(self.stream).encode(), "text/plain")))
114
+
115
+ if not isinstance(self.temperature, Unset):
116
+ files.append(
117
+ ("temperature", (None, str(self.temperature).encode(), "text/plain"))
118
+ )
119
+
120
+ if not isinstance(self.max_tokens, Unset):
121
+ files.append(
122
+ ("max_tokens", (None, str(self.max_tokens).encode(), "text/plain"))
123
+ )
124
+
125
+ if not isinstance(self.top_p, Unset):
126
+ files.append(("top_p", (None, str(self.top_p).encode(), "text/plain")))
127
+
128
+ if not isinstance(self.frequency_penalty, Unset):
129
+ files.append(
130
+ (
131
+ "frequency_penalty",
132
+ (None, str(self.frequency_penalty).encode(), "text/plain"),
133
+ )
134
+ )
135
+
136
+ if not isinstance(self.presence_penalty, Unset):
137
+ files.append(
138
+ (
139
+ "presence_penalty",
140
+ (None, str(self.presence_penalty).encode(), "text/plain"),
141
+ )
142
+ )
143
+
144
+ if not isinstance(self.stop, Unset):
145
+ for stop_item_element in self.stop:
146
+ files.append(
147
+ ("stop", (None, str(stop_item_element).encode(), "text/plain"))
148
+ )
149
+
150
+ for prop_name, prop in self.additional_properties.items():
151
+ files.append((prop_name, (None, str(prop).encode(), "text/plain")))
152
+
153
+ return files
154
+
155
+ @classmethod
156
+ def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
157
+ from ..models.message_request import MessageRequest
158
+
159
+ d = dict(src_dict)
160
+ messages = []
161
+ _messages = d.pop("messages")
162
+ for messages_item_data in _messages:
163
+ messages_item = MessageRequest.from_dict(messages_item_data)
164
+
165
+ messages.append(messages_item)
166
+
167
+ model = d.pop("model", UNSET)
168
+
169
+ stream = d.pop("stream", UNSET)
170
+
171
+ temperature = d.pop("temperature", UNSET)
172
+
173
+ max_tokens = d.pop("max_tokens", UNSET)
174
+
175
+ top_p = d.pop("top_p", UNSET)
176
+
177
+ frequency_penalty = d.pop("frequency_penalty", UNSET)
178
+
179
+ presence_penalty = d.pop("presence_penalty", UNSET)
180
+
181
+ stop = cast(list[str], d.pop("stop", UNSET))
182
+
183
+ generate_request_request = cls(
184
+ messages=messages,
185
+ model=model,
186
+ stream=stream,
187
+ temperature=temperature,
188
+ max_tokens=max_tokens,
189
+ top_p=top_p,
190
+ frequency_penalty=frequency_penalty,
191
+ presence_penalty=presence_penalty,
192
+ stop=stop,
193
+ )
194
+
195
+ generate_request_request.additional_properties = d
196
+ return generate_request_request
197
+
198
+ @property
199
+ def additional_keys(self) -> list[str]:
200
+ return list(self.additional_properties.keys())
201
+
202
+ def __getitem__(self, key: str) -> Any:
203
+ return self.additional_properties[key]
204
+
205
+ def __setitem__(self, key: str, value: Any) -> None:
206
+ self.additional_properties[key] = value
207
+
208
+ def __delitem__(self, key: str) -> None:
209
+ del self.additional_properties[key]
210
+
211
+ def __contains__(self, key: str) -> bool:
212
+ return key in self.additional_properties