calibrate-python-sdk 0.0.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 (56) hide show
  1. artpark/__init__.py +109 -0
  2. artpark/_default_clients.py +32 -0
  3. artpark/agent_tests/__init__.py +4 -0
  4. artpark/agent_tests/client.py +356 -0
  5. artpark/agent_tests/raw_client.py +455 -0
  6. artpark/agents/__init__.py +4 -0
  7. artpark/agents/client.py +210 -0
  8. artpark/agents/raw_client.py +273 -0
  9. artpark/client.py +268 -0
  10. artpark/core/__init__.py +127 -0
  11. artpark/core/api_error.py +23 -0
  12. artpark/core/client_wrapper.py +163 -0
  13. artpark/core/datetime_utils.py +70 -0
  14. artpark/core/file.py +67 -0
  15. artpark/core/force_multipart.py +18 -0
  16. artpark/core/http_client.py +843 -0
  17. artpark/core/http_response.py +59 -0
  18. artpark/core/http_sse/__init__.py +42 -0
  19. artpark/core/http_sse/_api.py +180 -0
  20. artpark/core/http_sse/_decoders.py +61 -0
  21. artpark/core/http_sse/_exceptions.py +7 -0
  22. artpark/core/http_sse/_models.py +17 -0
  23. artpark/core/jsonable_encoder.py +120 -0
  24. artpark/core/logging.py +107 -0
  25. artpark/core/parse_error.py +36 -0
  26. artpark/core/pydantic_utilities.py +508 -0
  27. artpark/core/query_encoder.py +58 -0
  28. artpark/core/remove_none_from_dict.py +11 -0
  29. artpark/core/request_options.py +37 -0
  30. artpark/core/serialization.py +347 -0
  31. artpark/environment.py +7 -0
  32. artpark/errors/__init__.py +34 -0
  33. artpark/errors/unprocessable_entity_error.py +11 -0
  34. artpark/py.typed +0 -0
  35. artpark/types/__init__.py +83 -0
  36. artpark/types/batch_run_request.py +19 -0
  37. artpark/types/batch_test_run.py +22 -0
  38. artpark/types/batch_test_run_response.py +22 -0
  39. artpark/types/batch_test_skip.py +21 -0
  40. artpark/types/http_validation_error.py +20 -0
  41. artpark/types/judge_result.py +51 -0
  42. artpark/types/resolve_agent_names_response.py +20 -0
  43. artpark/types/routers_agent_tests_agent_response.py +27 -0
  44. artpark/types/routers_agent_tests_agent_response_type.py +5 -0
  45. artpark/types/task_create_response.py +22 -0
  46. artpark/types/test_case_result.py +33 -0
  47. artpark/types/test_output.py +21 -0
  48. artpark/types/test_run_status_response.py +37 -0
  49. artpark/types/tool_call_output.py +21 -0
  50. artpark/types/validation_error.py +22 -0
  51. artpark/types/validation_error_loc_item.py +5 -0
  52. artpark/version.py +3 -0
  53. calibrate_python_sdk-0.0.1.dist-info/LICENSE +21 -0
  54. calibrate_python_sdk-0.0.1.dist-info/METADATA +55 -0
  55. calibrate_python_sdk-0.0.1.dist-info/RECORD +56 -0
  56. calibrate_python_sdk-0.0.1.dist-info/WHEEL +4 -0
@@ -0,0 +1,163 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import typing
4
+
5
+ import httpx
6
+ from .http_client import AsyncHttpClient, HttpClient
7
+ from .logging import LogConfig, Logger
8
+
9
+
10
+ class BaseClientWrapper:
11
+ def __init__(
12
+ self,
13
+ *,
14
+ api_key: typing.Optional[str] = None,
15
+ org_uuid: typing.Optional[str] = None,
16
+ token: typing.Union[str, typing.Callable[[], str]],
17
+ headers: typing.Optional[typing.Dict[str, str]] = None,
18
+ base_url: str,
19
+ timeout: typing.Optional[float] = None,
20
+ max_retries: int = 2,
21
+ stream_reconnection_enabled: typing.Optional[bool] = None,
22
+ max_stream_reconnection_attempts: typing.Optional[int] = None,
23
+ logging: typing.Optional[typing.Union[LogConfig, Logger]] = None,
24
+ ):
25
+ self._api_key = api_key
26
+ self._org_uuid = org_uuid
27
+ self._token = token
28
+ self._headers = headers
29
+ self._base_url = base_url
30
+ self._timeout = timeout
31
+ self._max_retries = max_retries
32
+ self._stream_reconnection_enabled = stream_reconnection_enabled
33
+ self._max_stream_reconnection_attempts = max_stream_reconnection_attempts
34
+ self._logging = logging
35
+
36
+ def get_headers(self) -> typing.Dict[str, str]:
37
+ import platform
38
+
39
+ headers: typing.Dict[str, str] = {
40
+ "User-Agent": "calibrate-python-sdk/0.0.1",
41
+ "X-Fern-Language": "Python",
42
+ "X-Fern-Runtime": f"python/{platform.python_version()}",
43
+ "X-Fern-Platform": f"{platform.system().lower()}/{platform.release()}",
44
+ "X-Fern-SDK-Name": "calibrate-python-sdk",
45
+ "X-Fern-SDK-Version": "0.0.1",
46
+ **(self.get_custom_headers() or {}),
47
+ }
48
+ if self._api_key is not None:
49
+ headers["X-API-Key"] = self._api_key
50
+ if self._org_uuid is not None:
51
+ headers["X-Org-UUID"] = self._org_uuid
52
+ headers["Authorization"] = f"Bearer {self._get_token()}"
53
+ return headers
54
+
55
+ def _get_token(self) -> str:
56
+ if isinstance(self._token, str):
57
+ return self._token
58
+ else:
59
+ return self._token()
60
+
61
+ def get_custom_headers(self) -> typing.Optional[typing.Dict[str, str]]:
62
+ return self._headers
63
+
64
+ def get_base_url(self) -> str:
65
+ return self._base_url
66
+
67
+ def get_timeout(self) -> typing.Optional[float]:
68
+ return self._timeout
69
+
70
+ def get_max_retries(self) -> int:
71
+ return self._max_retries
72
+
73
+ def get_stream_reconnection_enabled(self) -> bool:
74
+ return self._stream_reconnection_enabled if self._stream_reconnection_enabled is not None else True
75
+
76
+ def get_max_stream_reconnection_attempts(self) -> typing.Optional[int]:
77
+ return self._max_stream_reconnection_attempts
78
+
79
+
80
+ class SyncClientWrapper(BaseClientWrapper):
81
+ def __init__(
82
+ self,
83
+ *,
84
+ api_key: typing.Optional[str] = None,
85
+ org_uuid: typing.Optional[str] = None,
86
+ token: typing.Union[str, typing.Callable[[], str]],
87
+ headers: typing.Optional[typing.Dict[str, str]] = None,
88
+ base_url: str,
89
+ timeout: typing.Optional[float] = None,
90
+ max_retries: int = 2,
91
+ stream_reconnection_enabled: typing.Optional[bool] = None,
92
+ max_stream_reconnection_attempts: typing.Optional[int] = None,
93
+ logging: typing.Optional[typing.Union[LogConfig, Logger]] = None,
94
+ httpx_client: httpx.Client,
95
+ ):
96
+ super().__init__(
97
+ api_key=api_key,
98
+ org_uuid=org_uuid,
99
+ token=token,
100
+ headers=headers,
101
+ base_url=base_url,
102
+ timeout=timeout,
103
+ max_retries=max_retries,
104
+ stream_reconnection_enabled=stream_reconnection_enabled,
105
+ max_stream_reconnection_attempts=max_stream_reconnection_attempts,
106
+ logging=logging,
107
+ )
108
+ self.httpx_client = HttpClient(
109
+ httpx_client=httpx_client,
110
+ base_headers=self.get_headers,
111
+ base_timeout=self.get_timeout,
112
+ base_url=self.get_base_url,
113
+ base_max_retries=self.get_max_retries(),
114
+ logging_config=self._logging,
115
+ )
116
+
117
+
118
+ class AsyncClientWrapper(BaseClientWrapper):
119
+ def __init__(
120
+ self,
121
+ *,
122
+ api_key: typing.Optional[str] = None,
123
+ org_uuid: typing.Optional[str] = None,
124
+ token: typing.Union[str, typing.Callable[[], str]],
125
+ headers: typing.Optional[typing.Dict[str, str]] = None,
126
+ base_url: str,
127
+ timeout: typing.Optional[float] = None,
128
+ max_retries: int = 2,
129
+ stream_reconnection_enabled: typing.Optional[bool] = None,
130
+ max_stream_reconnection_attempts: typing.Optional[int] = None,
131
+ logging: typing.Optional[typing.Union[LogConfig, Logger]] = None,
132
+ async_token: typing.Optional[typing.Callable[[], typing.Awaitable[str]]] = None,
133
+ httpx_client: httpx.AsyncClient,
134
+ ):
135
+ super().__init__(
136
+ api_key=api_key,
137
+ org_uuid=org_uuid,
138
+ token=token,
139
+ headers=headers,
140
+ base_url=base_url,
141
+ timeout=timeout,
142
+ max_retries=max_retries,
143
+ stream_reconnection_enabled=stream_reconnection_enabled,
144
+ max_stream_reconnection_attempts=max_stream_reconnection_attempts,
145
+ logging=logging,
146
+ )
147
+ self._async_token = async_token
148
+ self.httpx_client = AsyncHttpClient(
149
+ httpx_client=httpx_client,
150
+ base_headers=self.get_headers,
151
+ base_timeout=self.get_timeout,
152
+ base_url=self.get_base_url,
153
+ base_max_retries=self.get_max_retries(),
154
+ async_base_headers=self.async_get_headers,
155
+ logging_config=self._logging,
156
+ )
157
+
158
+ async def async_get_headers(self) -> typing.Dict[str, str]:
159
+ headers = self.get_headers()
160
+ if self._async_token is not None:
161
+ token = await self._async_token()
162
+ headers["Authorization"] = f"Bearer {token}"
163
+ return headers
@@ -0,0 +1,70 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import datetime as dt
4
+ from email.utils import parsedate_to_datetime
5
+ from typing import Any
6
+
7
+ import pydantic
8
+
9
+ IS_PYDANTIC_V2 = pydantic.VERSION.startswith("2.")
10
+
11
+
12
+ def parse_rfc2822_datetime(v: Any) -> dt.datetime:
13
+ """
14
+ Parse an RFC 2822 datetime string (e.g., "Wed, 02 Oct 2002 13:00:00 GMT")
15
+ into a datetime object. If the value is already a datetime, return it as-is.
16
+ Falls back to ISO 8601 parsing if RFC 2822 parsing fails.
17
+ """
18
+ if isinstance(v, dt.datetime):
19
+ return v
20
+ if isinstance(v, str):
21
+ try:
22
+ return parsedate_to_datetime(v)
23
+ except Exception:
24
+ pass
25
+ # Fallback to ISO 8601 parsing
26
+ return dt.datetime.fromisoformat(v.replace("Z", "+00:00"))
27
+ raise ValueError(f"Expected str or datetime, got {type(v)}")
28
+
29
+
30
+ class Rfc2822DateTime(dt.datetime):
31
+ """A datetime subclass that parses RFC 2822 date strings.
32
+
33
+ On Pydantic V1, uses __get_validators__ for pre-validation.
34
+ On Pydantic V2, uses __get_pydantic_core_schema__ for BeforeValidator-style parsing.
35
+ """
36
+
37
+ @classmethod
38
+ def __get_validators__(cls): # type: ignore[no-untyped-def]
39
+ yield parse_rfc2822_datetime
40
+
41
+ @classmethod
42
+ def __get_pydantic_core_schema__(cls, _source_type: Any, _handler: Any) -> Any: # type: ignore[override]
43
+ from pydantic_core import core_schema
44
+
45
+ return core_schema.no_info_before_validator_function(parse_rfc2822_datetime, core_schema.datetime_schema())
46
+
47
+
48
+ def serialize_datetime(v: dt.datetime) -> str:
49
+ """
50
+ Serialize a datetime including timezone info.
51
+
52
+ Uses the timezone info provided if present, otherwise uses the current runtime's timezone info.
53
+
54
+ UTC datetimes end in "Z" while all other timezones are represented as offset from UTC, e.g. +05:00.
55
+ """
56
+
57
+ def _serialize_zoned_datetime(v: dt.datetime) -> str:
58
+ if v.tzinfo is not None and v.tzinfo.tzname(None) == dt.timezone.utc.tzname(None):
59
+ # UTC is a special case where we use "Z" at the end instead of "+00:00"
60
+ return v.isoformat().replace("+00:00", "Z")
61
+ else:
62
+ # Delegate to the typical +/- offset format
63
+ return v.isoformat()
64
+
65
+ if v.tzinfo is not None:
66
+ return _serialize_zoned_datetime(v)
67
+ else:
68
+ local_tz = dt.datetime.now().astimezone().tzinfo
69
+ localized_dt = v.replace(tzinfo=local_tz)
70
+ return _serialize_zoned_datetime(localized_dt)
artpark/core/file.py ADDED
@@ -0,0 +1,67 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ from typing import IO, Dict, List, Mapping, Optional, Tuple, Union, cast
4
+
5
+ # File typing inspired by the flexibility of types within the httpx library
6
+ # https://github.com/encode/httpx/blob/master/httpx/_types.py
7
+ FileContent = Union[IO[bytes], bytes, str]
8
+ File = Union[
9
+ # file (or bytes)
10
+ FileContent,
11
+ # (filename, file (or bytes))
12
+ Tuple[Optional[str], FileContent],
13
+ # (filename, file (or bytes), content_type)
14
+ Tuple[Optional[str], FileContent, Optional[str]],
15
+ # (filename, file (or bytes), content_type, headers)
16
+ Tuple[
17
+ Optional[str],
18
+ FileContent,
19
+ Optional[str],
20
+ Mapping[str, str],
21
+ ],
22
+ ]
23
+
24
+
25
+ def convert_file_dict_to_httpx_tuples(
26
+ d: Dict[str, Union[File, List[File]]],
27
+ ) -> List[Tuple[str, File]]:
28
+ """
29
+ The format we use is a list of tuples, where the first element is the
30
+ name of the file and the second is the file object. Typically HTTPX wants
31
+ a dict, but to be able to send lists of files, you have to use the list
32
+ approach (which also works for non-lists)
33
+ https://github.com/encode/httpx/pull/1032
34
+ """
35
+
36
+ httpx_tuples = []
37
+ for key, file_like in d.items():
38
+ if isinstance(file_like, list):
39
+ for file_like_item in file_like:
40
+ httpx_tuples.append((key, file_like_item))
41
+ else:
42
+ httpx_tuples.append((key, file_like))
43
+ return httpx_tuples
44
+
45
+
46
+ def with_content_type(*, file: File, default_content_type: str) -> File:
47
+ """
48
+ This function resolves to the file's content type, if provided, and defaults
49
+ to the default_content_type value if not.
50
+ """
51
+ if isinstance(file, tuple):
52
+ if len(file) == 2:
53
+ filename, content = cast(Tuple[Optional[str], FileContent], file) # type: ignore
54
+ return (filename, content, default_content_type)
55
+ elif len(file) == 3:
56
+ filename, content, file_content_type = cast(Tuple[Optional[str], FileContent, Optional[str]], file) # type: ignore
57
+ out_content_type = file_content_type or default_content_type
58
+ return (filename, content, out_content_type)
59
+ elif len(file) == 4:
60
+ filename, content, file_content_type, headers = cast( # type: ignore
61
+ Tuple[Optional[str], FileContent, Optional[str], Mapping[str, str]], file
62
+ )
63
+ out_content_type = file_content_type or default_content_type
64
+ return (filename, content, out_content_type, headers)
65
+ else:
66
+ raise ValueError(f"Unexpected tuple length: {len(file)}")
67
+ return (None, file, default_content_type)
@@ -0,0 +1,18 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ from typing import Any, Dict
4
+
5
+
6
+ class ForceMultipartDict(Dict[str, Any]):
7
+ """
8
+ A dictionary subclass that always evaluates to True in boolean contexts.
9
+
10
+ This is used to force multipart/form-data encoding in HTTP requests even when
11
+ the dictionary is empty, which would normally evaluate to False.
12
+ """
13
+
14
+ def __bool__(self) -> bool:
15
+ return True
16
+
17
+
18
+ FORCE_MULTIPART = ForceMultipartDict()