scorable 1.6.4__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.

Potentially problematic release.


This version of scorable might be problematic. Click here for more details.

Files changed (228) hide show
  1. root/__about__.py +4 -0
  2. root/__init__.py +17 -0
  3. root/client.py +207 -0
  4. root/datasets.py +231 -0
  5. root/execution_logs.py +162 -0
  6. root/generated/__init__.py +0 -0
  7. root/generated/openapi_aclient/__init__.py +1 -0
  8. root/generated/openapi_aclient/api/__init__.py +1 -0
  9. root/generated/openapi_aclient/api/datasets_api.py +1274 -0
  10. root/generated/openapi_aclient/api/evaluators_api.py +3641 -0
  11. root/generated/openapi_aclient/api/execution_logs_api.py +751 -0
  12. root/generated/openapi_aclient/api/judges_api.py +3794 -0
  13. root/generated/openapi_aclient/api/models_api.py +1473 -0
  14. root/generated/openapi_aclient/api/objectives_api.py +1767 -0
  15. root/generated/openapi_aclient/api_client.py +662 -0
  16. root/generated/openapi_aclient/api_response.py +22 -0
  17. root/generated/openapi_aclient/configuration.py +470 -0
  18. root/generated/openapi_aclient/exceptions.py +197 -0
  19. root/generated/openapi_aclient/models/__init__.py +122 -0
  20. root/generated/openapi_aclient/models/data_set_create.py +118 -0
  21. root/generated/openapi_aclient/models/data_set_create_request.py +105 -0
  22. root/generated/openapi_aclient/models/data_set_list.py +129 -0
  23. root/generated/openapi_aclient/models/data_set_type.py +36 -0
  24. root/generated/openapi_aclient/models/dataset_range_request.py +93 -0
  25. root/generated/openapi_aclient/models/evaluator.py +273 -0
  26. root/generated/openapi_aclient/models/evaluator_calibration_output.py +101 -0
  27. root/generated/openapi_aclient/models/evaluator_calibration_result.py +134 -0
  28. root/generated/openapi_aclient/models/evaluator_demonstrations.py +107 -0
  29. root/generated/openapi_aclient/models/evaluator_demonstrations_request.py +107 -0
  30. root/generated/openapi_aclient/models/evaluator_execution_function_parameter_property_request.py +86 -0
  31. root/generated/openapi_aclient/models/evaluator_execution_function_parameter_request.py +109 -0
  32. root/generated/openapi_aclient/models/evaluator_execution_function_parameter_type_enum.py +35 -0
  33. root/generated/openapi_aclient/models/evaluator_execution_function_request.py +99 -0
  34. root/generated/openapi_aclient/models/evaluator_execution_functions_request.py +98 -0
  35. root/generated/openapi_aclient/models/evaluator_execution_functions_type_enum.py +35 -0
  36. root/generated/openapi_aclient/models/evaluator_execution_request.py +134 -0
  37. root/generated/openapi_aclient/models/evaluator_execution_result.py +114 -0
  38. root/generated/openapi_aclient/models/evaluator_inputs_value.py +100 -0
  39. root/generated/openapi_aclient/models/evaluator_inputs_value_items.py +89 -0
  40. root/generated/openapi_aclient/models/evaluator_list_output.py +198 -0
  41. root/generated/openapi_aclient/models/evaluator_reference.py +90 -0
  42. root/generated/openapi_aclient/models/evaluator_reference_request.py +90 -0
  43. root/generated/openapi_aclient/models/evaluator_request.py +194 -0
  44. root/generated/openapi_aclient/models/evaluator_result.py +110 -0
  45. root/generated/openapi_aclient/models/execution_log_details.py +291 -0
  46. root/generated/openapi_aclient/models/execution_log_details_evaluation_context.py +83 -0
  47. root/generated/openapi_aclient/models/execution_log_details_evaluator_latencies_inner.py +83 -0
  48. root/generated/openapi_aclient/models/execution_log_list.py +217 -0
  49. root/generated/openapi_aclient/models/execution_log_list_evaluation_context.py +83 -0
  50. root/generated/openapi_aclient/models/generation_model_params_request.py +93 -0
  51. root/generated/openapi_aclient/models/id.py +87 -0
  52. root/generated/openapi_aclient/models/input_variable.py +121 -0
  53. root/generated/openapi_aclient/models/input_variable_request.py +82 -0
  54. root/generated/openapi_aclient/models/judge.py +178 -0
  55. root/generated/openapi_aclient/models/judge_execution_request.py +114 -0
  56. root/generated/openapi_aclient/models/judge_execution_response.py +97 -0
  57. root/generated/openapi_aclient/models/judge_files_inner.py +84 -0
  58. root/generated/openapi_aclient/models/judge_generator_request.py +142 -0
  59. root/generated/openapi_aclient/models/judge_generator_response.py +88 -0
  60. root/generated/openapi_aclient/models/judge_invite_request.py +87 -0
  61. root/generated/openapi_aclient/models/judge_list.py +156 -0
  62. root/generated/openapi_aclient/models/judge_rectifier_request_request.py +114 -0
  63. root/generated/openapi_aclient/models/judge_rectifier_response.py +121 -0
  64. root/generated/openapi_aclient/models/judge_request.py +108 -0
  65. root/generated/openapi_aclient/models/model.py +126 -0
  66. root/generated/openapi_aclient/models/model_list.py +115 -0
  67. root/generated/openapi_aclient/models/model_params.py +89 -0
  68. root/generated/openapi_aclient/models/model_params_request.py +89 -0
  69. root/generated/openapi_aclient/models/model_request.py +118 -0
  70. root/generated/openapi_aclient/models/nested_evaluator.py +110 -0
  71. root/generated/openapi_aclient/models/nested_evaluator_objective.py +87 -0
  72. root/generated/openapi_aclient/models/nested_evaluator_request.py +92 -0
  73. root/generated/openapi_aclient/models/nested_objective_evaluator.py +105 -0
  74. root/generated/openapi_aclient/models/nested_objective_evaluator_request.py +92 -0
  75. root/generated/openapi_aclient/models/nested_objective_list.py +111 -0
  76. root/generated/openapi_aclient/models/nested_user_details.py +88 -0
  77. root/generated/openapi_aclient/models/nested_user_details_request.py +82 -0
  78. root/generated/openapi_aclient/models/nested_vector_objective.py +88 -0
  79. root/generated/openapi_aclient/models/nested_vector_objective_request.py +82 -0
  80. root/generated/openapi_aclient/models/objective.py +157 -0
  81. root/generated/openapi_aclient/models/objective_list.py +128 -0
  82. root/generated/openapi_aclient/models/objective_request.py +113 -0
  83. root/generated/openapi_aclient/models/objective_validator.py +100 -0
  84. root/generated/openapi_aclient/models/objective_validator_request.py +90 -0
  85. root/generated/openapi_aclient/models/paginated_data_set_list_list.py +111 -0
  86. root/generated/openapi_aclient/models/paginated_evaluator_list.py +111 -0
  87. root/generated/openapi_aclient/models/paginated_evaluator_list_output_list.py +111 -0
  88. root/generated/openapi_aclient/models/paginated_execution_log_list_list.py +111 -0
  89. root/generated/openapi_aclient/models/paginated_judge_list_list.py +111 -0
  90. root/generated/openapi_aclient/models/paginated_model_list_list.py +111 -0
  91. root/generated/openapi_aclient/models/paginated_objective_list.py +111 -0
  92. root/generated/openapi_aclient/models/paginated_objective_list_list.py +111 -0
  93. root/generated/openapi_aclient/models/patched_evaluator_request.py +194 -0
  94. root/generated/openapi_aclient/models/patched_judge_request.py +110 -0
  95. root/generated/openapi_aclient/models/patched_model_request.py +118 -0
  96. root/generated/openapi_aclient/models/patched_objective_request.py +113 -0
  97. root/generated/openapi_aclient/models/provider.py +99 -0
  98. root/generated/openapi_aclient/models/reference_variable.py +123 -0
  99. root/generated/openapi_aclient/models/reference_variable_request.py +83 -0
  100. root/generated/openapi_aclient/models/skill_execution_validator_result.py +130 -0
  101. root/generated/openapi_aclient/models/skill_test_data_request.py +107 -0
  102. root/generated/openapi_aclient/models/skill_test_data_request_dataset_range.py +93 -0
  103. root/generated/openapi_aclient/models/skill_test_input_request.py +171 -0
  104. root/generated/openapi_aclient/models/skill_type_enum.py +36 -0
  105. root/generated/openapi_aclient/models/status_change.py +84 -0
  106. root/generated/openapi_aclient/models/status_change_request.py +84 -0
  107. root/generated/openapi_aclient/models/status_change_status_enum.py +36 -0
  108. root/generated/openapi_aclient/models/status_enum.py +38 -0
  109. root/generated/openapi_aclient/models/validation_result_status.py +36 -0
  110. root/generated/openapi_aclient/models/visibility_enum.py +38 -0
  111. root/generated/openapi_aclient/rest.py +166 -0
  112. root/generated/openapi_aclient_README.md +239 -0
  113. root/generated/openapi_client/__init__.py +1 -0
  114. root/generated/openapi_client/api/__init__.py +1 -0
  115. root/generated/openapi_client/api/datasets_api.py +1274 -0
  116. root/generated/openapi_client/api/evaluators_api.py +3641 -0
  117. root/generated/openapi_client/api/execution_logs_api.py +751 -0
  118. root/generated/openapi_client/api/judges_api.py +3794 -0
  119. root/generated/openapi_client/api/models_api.py +1473 -0
  120. root/generated/openapi_client/api/objectives_api.py +1767 -0
  121. root/generated/openapi_client/api_client.py +659 -0
  122. root/generated/openapi_client/api_response.py +22 -0
  123. root/generated/openapi_client/configuration.py +474 -0
  124. root/generated/openapi_client/exceptions.py +197 -0
  125. root/generated/openapi_client/models/__init__.py +120 -0
  126. root/generated/openapi_client/models/data_set_create.py +118 -0
  127. root/generated/openapi_client/models/data_set_create_request.py +105 -0
  128. root/generated/openapi_client/models/data_set_list.py +129 -0
  129. root/generated/openapi_client/models/data_set_type.py +36 -0
  130. root/generated/openapi_client/models/dataset_range_request.py +93 -0
  131. root/generated/openapi_client/models/evaluator.py +273 -0
  132. root/generated/openapi_client/models/evaluator_calibration_output.py +101 -0
  133. root/generated/openapi_client/models/evaluator_calibration_result.py +134 -0
  134. root/generated/openapi_client/models/evaluator_demonstrations.py +107 -0
  135. root/generated/openapi_client/models/evaluator_demonstrations_request.py +107 -0
  136. root/generated/openapi_client/models/evaluator_execution_function_parameter_property_request.py +86 -0
  137. root/generated/openapi_client/models/evaluator_execution_function_parameter_request.py +109 -0
  138. root/generated/openapi_client/models/evaluator_execution_function_parameter_type_enum.py +35 -0
  139. root/generated/openapi_client/models/evaluator_execution_function_request.py +99 -0
  140. root/generated/openapi_client/models/evaluator_execution_functions_request.py +98 -0
  141. root/generated/openapi_client/models/evaluator_execution_functions_type_enum.py +35 -0
  142. root/generated/openapi_client/models/evaluator_execution_request.py +134 -0
  143. root/generated/openapi_client/models/evaluator_execution_result.py +114 -0
  144. root/generated/openapi_client/models/evaluator_inputs_value.py +100 -0
  145. root/generated/openapi_client/models/evaluator_inputs_value_items.py +89 -0
  146. root/generated/openapi_client/models/evaluator_list_output.py +198 -0
  147. root/generated/openapi_client/models/evaluator_reference.py +90 -0
  148. root/generated/openapi_client/models/evaluator_reference_request.py +90 -0
  149. root/generated/openapi_client/models/evaluator_request.py +194 -0
  150. root/generated/openapi_client/models/evaluator_result.py +110 -0
  151. root/generated/openapi_client/models/execution_log_details.py +291 -0
  152. root/generated/openapi_client/models/execution_log_details_evaluation_context.py +83 -0
  153. root/generated/openapi_client/models/execution_log_details_evaluator_latencies_inner.py +83 -0
  154. root/generated/openapi_client/models/execution_log_list.py +215 -0
  155. root/generated/openapi_client/models/execution_log_list_evaluation_context.py +83 -0
  156. root/generated/openapi_client/models/generation_model_params_request.py +93 -0
  157. root/generated/openapi_client/models/id.py +87 -0
  158. root/generated/openapi_client/models/input_variable.py +121 -0
  159. root/generated/openapi_client/models/input_variable_request.py +82 -0
  160. root/generated/openapi_client/models/judge.py +178 -0
  161. root/generated/openapi_client/models/judge_execution_request.py +114 -0
  162. root/generated/openapi_client/models/judge_execution_response.py +97 -0
  163. root/generated/openapi_client/models/judge_files_inner.py +84 -0
  164. root/generated/openapi_client/models/judge_generator_request.py +142 -0
  165. root/generated/openapi_client/models/judge_generator_response.py +88 -0
  166. root/generated/openapi_client/models/judge_invite_request.py +87 -0
  167. root/generated/openapi_client/models/judge_list.py +156 -0
  168. root/generated/openapi_client/models/judge_rectifier_request_request.py +114 -0
  169. root/generated/openapi_client/models/judge_rectifier_response.py +121 -0
  170. root/generated/openapi_client/models/judge_request.py +108 -0
  171. root/generated/openapi_client/models/model.py +126 -0
  172. root/generated/openapi_client/models/model_list.py +115 -0
  173. root/generated/openapi_client/models/model_params.py +89 -0
  174. root/generated/openapi_client/models/model_params_request.py +89 -0
  175. root/generated/openapi_client/models/model_request.py +118 -0
  176. root/generated/openapi_client/models/nested_evaluator.py +110 -0
  177. root/generated/openapi_client/models/nested_evaluator_objective.py +87 -0
  178. root/generated/openapi_client/models/nested_evaluator_request.py +92 -0
  179. root/generated/openapi_client/models/nested_objective_evaluator.py +105 -0
  180. root/generated/openapi_client/models/nested_objective_evaluator_request.py +92 -0
  181. root/generated/openapi_client/models/nested_objective_list.py +111 -0
  182. root/generated/openapi_client/models/nested_user_details.py +88 -0
  183. root/generated/openapi_client/models/nested_user_details_request.py +82 -0
  184. root/generated/openapi_client/models/nested_vector_objective.py +88 -0
  185. root/generated/openapi_client/models/nested_vector_objective_request.py +82 -0
  186. root/generated/openapi_client/models/objective.py +157 -0
  187. root/generated/openapi_client/models/objective_list.py +128 -0
  188. root/generated/openapi_client/models/objective_request.py +113 -0
  189. root/generated/openapi_client/models/objective_validator.py +100 -0
  190. root/generated/openapi_client/models/objective_validator_request.py +90 -0
  191. root/generated/openapi_client/models/paginated_data_set_list_list.py +111 -0
  192. root/generated/openapi_client/models/paginated_evaluator_list.py +111 -0
  193. root/generated/openapi_client/models/paginated_evaluator_list_output_list.py +111 -0
  194. root/generated/openapi_client/models/paginated_execution_log_list_list.py +111 -0
  195. root/generated/openapi_client/models/paginated_judge_list_list.py +111 -0
  196. root/generated/openapi_client/models/paginated_model_list_list.py +111 -0
  197. root/generated/openapi_client/models/paginated_objective_list.py +111 -0
  198. root/generated/openapi_client/models/paginated_objective_list_list.py +111 -0
  199. root/generated/openapi_client/models/patched_evaluator_request.py +194 -0
  200. root/generated/openapi_client/models/patched_judge_request.py +110 -0
  201. root/generated/openapi_client/models/patched_model_request.py +118 -0
  202. root/generated/openapi_client/models/patched_objective_request.py +113 -0
  203. root/generated/openapi_client/models/provider.py +99 -0
  204. root/generated/openapi_client/models/reference_variable.py +123 -0
  205. root/generated/openapi_client/models/reference_variable_request.py +83 -0
  206. root/generated/openapi_client/models/skill_execution_validator_result.py +130 -0
  207. root/generated/openapi_client/models/skill_test_data_request.py +107 -0
  208. root/generated/openapi_client/models/skill_test_data_request_dataset_range.py +93 -0
  209. root/generated/openapi_client/models/skill_test_input_request.py +171 -0
  210. root/generated/openapi_client/models/skill_type_enum.py +36 -0
  211. root/generated/openapi_client/models/status_change.py +84 -0
  212. root/generated/openapi_client/models/status_change_request.py +84 -0
  213. root/generated/openapi_client/models/status_change_status_enum.py +36 -0
  214. root/generated/openapi_client/models/status_enum.py +38 -0
  215. root/generated/openapi_client/models/validation_result_status.py +36 -0
  216. root/generated/openapi_client/models/visibility_enum.py +38 -0
  217. root/generated/openapi_client/rest.py +203 -0
  218. root/generated/openapi_client_README.md +238 -0
  219. root/judges.py +681 -0
  220. root/models.py +197 -0
  221. root/objectives.py +343 -0
  222. root/py.typed +0 -0
  223. root/skills.py +1707 -0
  224. root/utils.py +90 -0
  225. scorable-1.6.4.dist-info/METADATA +395 -0
  226. scorable-1.6.4.dist-info/RECORD +228 -0
  227. scorable-1.6.4.dist-info/WHEEL +4 -0
  228. scorable-1.6.4.dist-info/licenses/LICENSE +202 -0
root/__about__.py ADDED
@@ -0,0 +1,4 @@
1
+ # SPDX-FileCopyrightText: 2024-present juho.ylikyla <juho.ylikyla@rootsignals.ai>
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+ __version__ = "1.6.4"
root/__init__.py ADDED
@@ -0,0 +1,17 @@
1
+ """Root Signals SDK.
2
+
3
+ The use should start by creating a :class:`root.client.RootSignals` instance.
4
+
5
+ Example::
6
+
7
+ from root import RootSignals
8
+ client = RootSignals()
9
+
10
+ """
11
+
12
+ from .__about__ import __version__
13
+ from .client import RootSignals
14
+
15
+ # Note: PEP-396 was rejected but we provide __version__ anyway
16
+ # ( https://peps.python.org/pep-0396/ )
17
+ __all__ = ["__version__", "RootSignals"]
root/client.py ADDED
@@ -0,0 +1,207 @@
1
+ from __future__ import annotations
2
+
3
+ import os
4
+ import re
5
+ import textwrap
6
+ from contextlib import asynccontextmanager, contextmanager
7
+ from functools import cached_property
8
+ from typing import (
9
+ TYPE_CHECKING,
10
+ AsyncContextManager,
11
+ AsyncGenerator,
12
+ Callable,
13
+ ContextManager,
14
+ Generator,
15
+ Optional,
16
+ Type,
17
+ Union,
18
+ )
19
+
20
+ from .__about__ import __version__
21
+ from .generated import openapi_aclient, openapi_client
22
+ from .generated.openapi_aclient.configuration import Configuration as _AConfiguration
23
+ from .generated.openapi_client.configuration import Configuration as _Configuration
24
+
25
+ if TYPE_CHECKING:
26
+ from .datasets import DataSets
27
+ from .execution_logs import ExecutionLogs
28
+ from .judges import Judges
29
+ from .models import Models
30
+ from .objectives import Objectives
31
+ from .skills import Evaluators
32
+
33
+
34
+ def _get_api_key(*, dot_env: str = ".env") -> str:
35
+ var = "ROOTSIGNALS_API_KEY"
36
+ api_key = os.environ.get(var)
37
+ if api_key is not None:
38
+ return api_key
39
+ if os.path.exists(dot_env):
40
+ for line in open(dot_env):
41
+ m = re.fullmatch(line, rf"^\s*{var}\s*=\s*(\S+)\s*$")
42
+ if m is not None:
43
+ return m.group(1)
44
+ raise ValueError(
45
+ textwrap.dedent("""
46
+ Root Signals API key cannot be found.
47
+ It can be provided in client invocation, using ROOTSIGNALS_API_KEY environment variable or .env file line
48
+ """)
49
+ )
50
+
51
+
52
+ class Beta:
53
+ """Beta API features namespace"""
54
+
55
+ def __init__(
56
+ self,
57
+ get_client_context: Union[
58
+ Callable[[], AsyncContextManager[openapi_aclient.ApiClient]],
59
+ Callable[[], ContextManager[openapi_client.ApiClient]],
60
+ ],
61
+ ) -> None:
62
+ self._get_client_context = get_client_context
63
+
64
+ @cached_property
65
+ def judges(self) -> Judges:
66
+ """Get Judges API (Beta)"""
67
+ from .judges import Judges
68
+
69
+ return Judges(self._get_client_context)
70
+
71
+
72
+ class Scorable:
73
+ """Root Signals API Python client.
74
+
75
+ The API key must be provided via one of the following methods - the code uses the first one that is found:
76
+
77
+ 1. as an argument to RootSignals constructor,
78
+ 2. environment variable `ROOTSIGNALS_API_KEY`, or
79
+ 3. .env file containing `ROOTSIGNALS_API_KEY=`
80
+
81
+ Args:
82
+ api_key: Root Signals API Key (if not provided from environment)
83
+ run_async: Whether to run the API client asynchronously
84
+ """
85
+
86
+ def __init__(
87
+ self,
88
+ api_key: Optional[str] = None,
89
+ *,
90
+ run_async: bool = False,
91
+ _api_client: Union[Optional[openapi_aclient.ApiClient], Optional[openapi_client.ApiClient]] = None,
92
+ base_url: Optional[str] = None,
93
+ ):
94
+ self.run_async = run_async
95
+ if api_key is None:
96
+ api_key = _get_api_key()
97
+ if base_url is None:
98
+ base_url = os.environ.get("ROOTSIGNALS_API_URL", "https://api.app.rootsignals.ai")
99
+ self.base_url = base_url
100
+ self.api_key = api_key
101
+ self._api_client_arg = _api_client
102
+
103
+ @cached_property
104
+ def get_client_context(
105
+ self,
106
+ ) -> Union[
107
+ Callable[[], AsyncContextManager[openapi_aclient.ApiClient]],
108
+ Callable[[], ContextManager[openapi_client.ApiClient]],
109
+ ]:
110
+ if self._api_client_arg is not None:
111
+ if isinstance(self._api_client_arg, openapi_aclient.ApiClient):
112
+
113
+ @asynccontextmanager
114
+ async def async_client_context() -> AsyncGenerator[openapi_aclient.ApiClient, None]:
115
+ assert isinstance(self._api_client_arg, openapi_aclient.ApiClient)
116
+ yield self._api_client_arg
117
+
118
+ return async_client_context
119
+ else:
120
+
121
+ @contextmanager
122
+ def sync_client_context() -> Generator[openapi_client.ApiClient, None, None]:
123
+ assert isinstance(self._api_client_arg, openapi_client.ApiClient)
124
+ yield self._api_client_arg
125
+
126
+ return sync_client_context
127
+
128
+ if self.run_async:
129
+ return self._configure_client_context(openapi_aclient.ApiClient, _AConfiguration)
130
+ return self._configure_client_context(openapi_client.ApiClient, _Configuration)
131
+
132
+ def _configure_client_context(
133
+ self,
134
+ client_cls: Union[Type[openapi_client.ApiClient], Type[openapi_aclient.ApiClient]],
135
+ config_cls: Union[Type[_Configuration], Type[_AConfiguration]],
136
+ ) -> Union[
137
+ Callable[[], ContextManager[openapi_client.ApiClient]],
138
+ Callable[[], AsyncContextManager[openapi_aclient.ApiClient]],
139
+ ]:
140
+ config = config_cls(host=self.base_url)
141
+ config.api_key["publicApiKey"] = f"Api-Key {self.api_key}"
142
+
143
+ if issubclass(client_cls, openapi_aclient.ApiClient):
144
+
145
+ @asynccontextmanager
146
+ async def async_client_context() -> AsyncGenerator[openapi_aclient.ApiClient, None]:
147
+ async with client_cls(config) as client:
148
+ client.user_agent = f"rs-python-sdk/{__version__}"
149
+ yield client
150
+
151
+ return async_client_context
152
+ else:
153
+
154
+ @contextmanager
155
+ def sync_client_context() -> Generator[openapi_client.ApiClient, None, None]:
156
+ with client_cls(config) as client:
157
+ client.user_agent = f"rs-python-sdk/{__version__}"
158
+ yield client
159
+
160
+ return sync_client_context
161
+
162
+ @cached_property
163
+ def datasets(self) -> DataSets:
164
+ """Get DataSets API"""
165
+ from .datasets import DataSets
166
+
167
+ return DataSets(self.get_client_context, self.base_url, self.api_key)
168
+
169
+ @cached_property
170
+ def evaluators(self) -> Evaluators:
171
+ """Get Evaluators API"""
172
+ from .skills import Evaluators
173
+
174
+ return Evaluators(self.get_client_context)
175
+
176
+ @cached_property
177
+ def execution_logs(self) -> ExecutionLogs:
178
+ """Get Execution Logs API"""
179
+ from .execution_logs import ExecutionLogs
180
+
181
+ return ExecutionLogs(self.get_client_context)
182
+
183
+ @cached_property
184
+ def models(self) -> Models:
185
+ """Get Models API"""
186
+ from .models import Models
187
+
188
+ return Models(self.get_client_context)
189
+
190
+ @cached_property
191
+ def objectives(self) -> Objectives:
192
+ """Get Objectives API"""
193
+ from .objectives import Objectives
194
+
195
+ return Objectives(self.get_client_context)
196
+
197
+ @cached_property
198
+ def judges(self) -> Judges:
199
+ """Get Judges API"""
200
+ from .judges import Judges
201
+
202
+ return Judges(self.get_client_context)
203
+
204
+ @cached_property
205
+ def beta(self) -> Beta:
206
+ """Get Beta API features"""
207
+ return Beta(self.get_client_context)
root/datasets.py ADDED
@@ -0,0 +1,231 @@
1
+ from contextlib import AbstractAsyncContextManager
2
+ from functools import partial
3
+ from typing import Any, AsyncIterator, Dict, Iterator, Optional
4
+
5
+ import aiohttp
6
+ import requests
7
+ from pydantic import StrictStr
8
+
9
+ from root.generated.openapi_client.api_client import ApiClient
10
+
11
+ from .generated.openapi_aclient import ApiClient as AApiClient
12
+ from .generated.openapi_aclient.api.datasets_api import DatasetsApi as ADatasetsApi
13
+ from .generated.openapi_aclient.models.data_set_create import DataSetCreate as ADataSetCreate
14
+ from .generated.openapi_aclient.models.data_set_list import DataSetList as ADataSetList
15
+ from .generated.openapi_aclient.models.paginated_data_set_list_list import (
16
+ PaginatedDataSetListList as APaginatedDataSetListList,
17
+ )
18
+ from .generated.openapi_client.api.datasets_api import DatasetsApi as DatasetsApi
19
+ from .generated.openapi_client.models.data_set_create import DataSetCreate
20
+ from .generated.openapi_client.models.data_set_list import DataSetList
21
+ from .utils import ClientContextCallable, iterate_cursor_list, with_async_client, with_sync_client
22
+
23
+
24
+ class DataSets:
25
+ """
26
+ DataSets (sub) API
27
+
28
+ Note:
29
+
30
+ The construction of the API instance should be handled by
31
+ accesing an attribute of a :class:`root.client.RootSignals` instance.
32
+ """
33
+
34
+ def __init__(self, client_context: ClientContextCallable, base_url: str, api_key: str):
35
+ self.client_context = client_context
36
+ self.base_url = base_url
37
+ self.api_key = api_key
38
+
39
+ def create(
40
+ self,
41
+ *,
42
+ name: Optional[str] = None,
43
+ path: Optional[str] = None,
44
+ type: str = "reference",
45
+ _request_timeout: Optional[int] = None,
46
+ ) -> Optional[DataSetCreate]:
47
+ """
48
+ Create a dataset object with the given parameters to the registry.
49
+ If the dataset has a path, it will be uploaded to the registry.
50
+ """
51
+
52
+ payload: Dict[str, Any] = {"name": name, "type": type, "tags": []}
53
+ file = None
54
+ try:
55
+ if path:
56
+ file = open(path, "rb")
57
+ files = {"file": file}
58
+ else:
59
+ files = None
60
+
61
+ response = requests.post(
62
+ f"{self.base_url}/datasets/",
63
+ headers={"Authorization": f"Api-Key {self.api_key}"},
64
+ data=payload,
65
+ files=files,
66
+ timeout=_request_timeout or 120,
67
+ )
68
+ if not response.ok:
69
+ raise Exception(f"create failed with status code {response.status_code} and message\n{response.text}")
70
+
71
+ return DataSetCreate.from_dict(response.json())
72
+ finally:
73
+ if file and not file.closed:
74
+ file.close()
75
+
76
+ async def acreate(
77
+ self,
78
+ *,
79
+ name: Optional[str] = None,
80
+ path: Optional[str] = None,
81
+ type: str = "reference",
82
+ _request_timeout: Optional[int] = None,
83
+ ) -> Optional[ADataSetCreate]:
84
+ """
85
+ Asynchronously create a dataset object with the given parameters to the registry.
86
+ If the dataset has a path, it will be uploaded to the registry.
87
+
88
+ """
89
+
90
+ payload = aiohttp.FormData()
91
+ payload.add_field("name", name)
92
+ payload.add_field("type", type)
93
+
94
+ file = None
95
+ try:
96
+ if path:
97
+ file = open(path, "rb")
98
+ payload.add_field("file", file)
99
+
100
+ async with aiohttp.ClientSession() as session:
101
+ async with session.post(
102
+ f"{self.base_url}/datasets/",
103
+ data=payload,
104
+ headers={"Authorization": f"Api-Key {self.api_key}"},
105
+ timeout=aiohttp.ClientTimeout(_request_timeout) or aiohttp.ClientTimeout(120),
106
+ ) as response:
107
+ if not response.ok:
108
+ raise Exception(
109
+ f"create failed with status code {response.status} and message\n{response.text}"
110
+ )
111
+ return ADataSetCreate.from_dict(await response.json())
112
+ finally:
113
+ if file and not file.closed:
114
+ file.close()
115
+
116
+ @with_sync_client
117
+ def get(
118
+ self,
119
+ dataset_id: str,
120
+ *,
121
+ _request_timeout: Optional[int] = None,
122
+ _client: ApiClient,
123
+ ) -> DataSetList:
124
+ """
125
+ Get a dataset object from the registry.
126
+ """
127
+
128
+ api_instance = DatasetsApi(_client)
129
+ return api_instance.datasets_retrieve(dataset_id, _request_timeout=_request_timeout)
130
+
131
+ @with_async_client
132
+ async def aget(
133
+ self,
134
+ dataset_id: str,
135
+ *,
136
+ _request_timeout: Optional[int] = None,
137
+ _client: AApiClient,
138
+ ) -> ADataSetList:
139
+ """
140
+ Asynchronously get a dataset object from the registry.
141
+ """
142
+
143
+ api_instance = ADatasetsApi(_client)
144
+ return await api_instance.datasets_retrieve(dataset_id, _request_timeout=_request_timeout)
145
+
146
+ @with_sync_client
147
+ def list(
148
+ self,
149
+ search_term: Optional[str] = None,
150
+ *,
151
+ limit: int = 100,
152
+ _request_timeout: Optional[int] = None,
153
+ _client: ApiClient,
154
+ ) -> Iterator[DataSetList]:
155
+ """
156
+ Iterate through the datasets.
157
+
158
+ Args:
159
+ limit: Number of entries to iterate through at most.
160
+ search_term: Can be used to limit returned datasets.
161
+ """
162
+
163
+ api_instance = DatasetsApi(_client)
164
+ yield from iterate_cursor_list(
165
+ partial(api_instance.datasets_list, search=search_term, _request_timeout=_request_timeout), limit=limit
166
+ )
167
+
168
+ async def alist(
169
+ self,
170
+ search_term: Optional[str] = None,
171
+ *,
172
+ limit: int = 100,
173
+ _request_timeout: Optional[int] = None,
174
+ ) -> AsyncIterator[ADataSetList]:
175
+ """
176
+ Asynchronously iterate through the datasets.
177
+
178
+ Args:
179
+ limit: Number of entries to iterate through at most.
180
+ search_term: Can be used to limit returned datasets.
181
+ """
182
+
183
+ context = self.client_context()
184
+ assert isinstance(context, AbstractAsyncContextManager), "This method is not available in synchronous mode"
185
+ async with context as client:
186
+ api_instance = ADatasetsApi(client)
187
+ partial_list = partial(api_instance.datasets_list, search=search_term, _request_timeout=_request_timeout)
188
+ cursor: Optional[StrictStr] = None
189
+ while limit > 0:
190
+ result: APaginatedDataSetListList = await partial_list(page_size=limit, cursor=cursor)
191
+ if not result.results:
192
+ return
193
+
194
+ used_results = result.results[:limit]
195
+ limit -= len(used_results)
196
+
197
+ for used_result in used_results:
198
+ yield used_result
199
+
200
+ if not (cursor := result.next):
201
+ return
202
+
203
+ @with_sync_client
204
+ def delete(
205
+ self,
206
+ dataset_id: str,
207
+ *,
208
+ _request_timeout: Optional[int] = None,
209
+ _client: ApiClient,
210
+ ) -> None:
211
+ """
212
+ Delete a dataset object from the registry.
213
+ """
214
+
215
+ api_instance = DatasetsApi(_client)
216
+ return api_instance.datasets_destroy(dataset_id, _request_timeout=_request_timeout)
217
+
218
+ @with_async_client
219
+ async def adelete(
220
+ self,
221
+ dataset_id: str,
222
+ *,
223
+ _request_timeout: Optional[int] = None,
224
+ _client: AApiClient,
225
+ ) -> None:
226
+ """
227
+ Asynchronously delete a dataset object from the registry.
228
+ """
229
+
230
+ api_instance = ADatasetsApi(_client)
231
+ return await api_instance.datasets_destroy(dataset_id, _request_timeout=_request_timeout)
root/execution_logs.py ADDED
@@ -0,0 +1,162 @@
1
+ from __future__ import annotations
2
+
3
+ from contextlib import AbstractAsyncContextManager
4
+ from functools import partial
5
+ from typing import TYPE_CHECKING, AsyncIterator, Iterator, List, Optional, Protocol
6
+
7
+ from pydantic import StrictStr
8
+
9
+ from .generated.openapi_aclient import ApiClient as AApiClient
10
+ from .generated.openapi_aclient.api.execution_logs_api import ExecutionLogsApi as AExecutionLogsApi
11
+ from .generated.openapi_aclient.models.execution_log_details import ExecutionLogDetails as AExecutionLogDetails
12
+ from .generated.openapi_aclient.models.execution_log_list import ExecutionLogList as AExecutionLogList
13
+ from .generated.openapi_aclient.models.paginated_execution_log_list_list import (
14
+ PaginatedExecutionLogListList as APaginatedExecutionLogListList,
15
+ )
16
+ from .generated.openapi_client import ApiClient
17
+ from .generated.openapi_client.api.execution_logs_api import ExecutionLogsApi as ExecutionLogsApi
18
+ from .generated.openapi_client.models.execution_log_details import ExecutionLogDetails
19
+ from .generated.openapi_client.models.execution_log_list import ExecutionLogList
20
+ from .utils import ClientContextCallable, iterate_cursor_list, with_async_client, with_sync_client
21
+
22
+ if TYPE_CHECKING:
23
+
24
+ class ExecutionResult(Protocol):
25
+ execution_log_id: str
26
+
27
+
28
+ class ExecutionLogs:
29
+ """Execution logs API"""
30
+
31
+ def __init__(self, client_context: ClientContextCallable):
32
+ self.client_context = client_context
33
+
34
+ @with_sync_client
35
+ def list(
36
+ self,
37
+ *,
38
+ limit: int = 100,
39
+ search_term: Optional[str] = None,
40
+ tags: Optional[List[str]] = None,
41
+ include: Optional[List[str]] = None,
42
+ _request_timeout: Optional[int] = None,
43
+ _client: ApiClient,
44
+ ) -> Iterator[ExecutionLogList]:
45
+ """
46
+ List execution logs
47
+
48
+ Args:
49
+ limit: Number of entries to iterate through at most.
50
+ search_term: Can be used to limit returned logs. For example, a evaluator id or name.
51
+ tags: Optional tags to filter the logs by.
52
+ include: Optional fields to include in the response.
53
+ """
54
+ api_instance = ExecutionLogsApi(_client)
55
+ yield from iterate_cursor_list(
56
+ partial(
57
+ api_instance.execution_logs_list,
58
+ search=search_term,
59
+ tags=",".join(tags) if tags else None,
60
+ include=",".join(include) if include else None,
61
+ _request_timeout=_request_timeout,
62
+ ),
63
+ limit=limit,
64
+ )
65
+
66
+ async def alist(
67
+ self,
68
+ *,
69
+ limit: int = 100,
70
+ search_term: Optional[str] = None,
71
+ tags: Optional[List[str]] = None,
72
+ include: Optional[List[str]] = None,
73
+ _request_timeout: Optional[int] = None,
74
+ ) -> AsyncIterator[AExecutionLogList]:
75
+ """
76
+ Asynchronously list execution logs
77
+
78
+ Args:
79
+ limit: Number of entries to iterate through at most.
80
+ search_term: Can be used to limit returned logs. For example, a evaluator id or name.
81
+ tags: Optional tags to filter the logs by.
82
+ include: Optional fields to include in the response.
83
+ """
84
+
85
+ context = self.client_context()
86
+ assert isinstance(context, AbstractAsyncContextManager), "This method is not available in synchronous mode"
87
+ async with context as client:
88
+ api_instance = AExecutionLogsApi(client)
89
+ partial_list = partial(
90
+ api_instance.execution_logs_list,
91
+ search=search_term,
92
+ tags=",".join(tags) if tags else None,
93
+ include=",".join(include) if include else None,
94
+ _request_timeout=_request_timeout,
95
+ )
96
+
97
+ cursor: Optional[StrictStr] = None
98
+ while limit > 0:
99
+ result: APaginatedExecutionLogListList = await partial_list(page_size=limit, cursor=cursor)
100
+ if not result.results:
101
+ return
102
+
103
+ used_results = result.results[:limit]
104
+ limit -= len(used_results)
105
+
106
+ for used_result in used_results:
107
+ yield used_result
108
+
109
+ if not (cursor := result.next):
110
+ return
111
+
112
+ @with_sync_client
113
+ def get(
114
+ self,
115
+ *,
116
+ log_id: Optional[str] = None,
117
+ execution_result: Optional[ExecutionResult] = None,
118
+ _request_timeout: Optional[int] = None,
119
+ _client: ApiClient,
120
+ ) -> ExecutionLogDetails:
121
+ """
122
+ Get a specific execution log details
123
+
124
+ Args:
125
+ log_id: The log to be fetched
126
+ execution_result: The execution result containing the log ID.
127
+
128
+ Raises:
129
+ ValueError: If both log_id and execution_result are None.
130
+ """
131
+
132
+ api_instance = ExecutionLogsApi(_client)
133
+ _log_id = execution_result.execution_log_id if execution_result else log_id
134
+ if _log_id is None:
135
+ raise ValueError("Either log_id or execution_result must be provided")
136
+ return api_instance.execution_logs_retrieve(_log_id, _request_timeout=_request_timeout)
137
+
138
+ @with_async_client
139
+ async def aget(
140
+ self,
141
+ *,
142
+ log_id: Optional[str] = None,
143
+ execution_result: Optional[ExecutionResult] = None,
144
+ _request_timeout: Optional[int] = None,
145
+ _client: AApiClient,
146
+ ) -> AExecutionLogDetails:
147
+ """
148
+ Asynchronously get a specific execution log details
149
+
150
+ Args:
151
+ log_id: The log to be fetched
152
+ execution_result: The execution result containing the log ID.
153
+
154
+ Raises:
155
+ ValueError: If both log_id and execution_result are None.
156
+ """
157
+
158
+ api_instance = AExecutionLogsApi(_client)
159
+ _log_id = execution_result.execution_log_id if execution_result else log_id
160
+ if _log_id is None:
161
+ raise ValueError("Either log_id or execution_result must be provided")
162
+ return await api_instance.execution_logs_retrieve(_log_id, _request_timeout=_request_timeout)
File without changes
@@ -0,0 +1 @@
1
+ from .api_client import ApiClient