isaacus 0.9.1__py3-none-any.whl → 0.10.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.
isaacus/_models.py CHANGED
@@ -2,7 +2,21 @@ from __future__ import annotations
2
2
 
3
3
  import os
4
4
  import inspect
5
- from typing import TYPE_CHECKING, Any, Type, Union, Generic, TypeVar, Callable, Optional, cast
5
+ import weakref
6
+ from typing import (
7
+ IO,
8
+ TYPE_CHECKING,
9
+ Any,
10
+ Type,
11
+ Union,
12
+ Generic,
13
+ TypeVar,
14
+ Callable,
15
+ Iterable,
16
+ Optional,
17
+ AsyncIterable,
18
+ cast,
19
+ )
6
20
  from datetime import date, datetime
7
21
  from typing_extensions import (
8
22
  List,
@@ -256,15 +270,16 @@ class BaseModel(pydantic.BaseModel):
256
270
  mode: Literal["json", "python"] | str = "python",
257
271
  include: IncEx | None = None,
258
272
  exclude: IncEx | None = None,
273
+ context: Any | None = None,
259
274
  by_alias: bool | None = None,
260
275
  exclude_unset: bool = False,
261
276
  exclude_defaults: bool = False,
262
277
  exclude_none: bool = False,
278
+ exclude_computed_fields: bool = False,
263
279
  round_trip: bool = False,
264
280
  warnings: bool | Literal["none", "warn", "error"] = True,
265
- context: dict[str, Any] | None = None,
266
- serialize_as_any: bool = False,
267
281
  fallback: Callable[[Any], Any] | None = None,
282
+ serialize_as_any: bool = False,
268
283
  ) -> dict[str, Any]:
269
284
  """Usage docs: https://docs.pydantic.dev/2.4/concepts/serialization/#modelmodel_dump
270
285
 
@@ -272,16 +287,24 @@ class BaseModel(pydantic.BaseModel):
272
287
 
273
288
  Args:
274
289
  mode: The mode in which `to_python` should run.
275
- If mode is 'json', the dictionary will only contain JSON serializable types.
276
- If mode is 'python', the dictionary may contain any Python objects.
277
- include: A list of fields to include in the output.
278
- exclude: A list of fields to exclude from the output.
290
+ If mode is 'json', the output will only contain JSON serializable types.
291
+ If mode is 'python', the output may contain non-JSON-serializable Python objects.
292
+ include: A set of fields to include in the output.
293
+ exclude: A set of fields to exclude from the output.
294
+ context: Additional context to pass to the serializer.
279
295
  by_alias: Whether to use the field's alias in the dictionary key if defined.
280
- exclude_unset: Whether to exclude fields that are unset or None from the output.
281
- exclude_defaults: Whether to exclude fields that are set to their default value from the output.
282
- exclude_none: Whether to exclude fields that have a value of `None` from the output.
283
- round_trip: Whether to enable serialization and deserialization round-trip support.
284
- warnings: Whether to log warnings when invalid fields are encountered.
296
+ exclude_unset: Whether to exclude fields that have not been explicitly set.
297
+ exclude_defaults: Whether to exclude fields that are set to their default value.
298
+ exclude_none: Whether to exclude fields that have a value of `None`.
299
+ exclude_computed_fields: Whether to exclude computed fields.
300
+ While this can be useful for round-tripping, it is usually recommended to use the dedicated
301
+ `round_trip` parameter instead.
302
+ round_trip: If True, dumped values should be valid as input for non-idempotent types such as Json[T].
303
+ warnings: How to handle serialization errors. False/"none" ignores them, True/"warn" logs errors,
304
+ "error" raises a [`PydanticSerializationError`][pydantic_core.PydanticSerializationError].
305
+ fallback: A function to call when an unknown value is encountered. If not provided,
306
+ a [`PydanticSerializationError`][pydantic_core.PydanticSerializationError] error is raised.
307
+ serialize_as_any: Whether to serialize fields with duck-typing serialization behavior.
285
308
 
286
309
  Returns:
287
310
  A dictionary representation of the model.
@@ -298,6 +321,8 @@ class BaseModel(pydantic.BaseModel):
298
321
  raise ValueError("serialize_as_any is only supported in Pydantic v2")
299
322
  if fallback is not None:
300
323
  raise ValueError("fallback is only supported in Pydantic v2")
324
+ if exclude_computed_fields != False:
325
+ raise ValueError("exclude_computed_fields is only supported in Pydantic v2")
301
326
  dumped = super().dict( # pyright: ignore[reportDeprecated]
302
327
  include=include,
303
328
  exclude=exclude,
@@ -314,15 +339,17 @@ class BaseModel(pydantic.BaseModel):
314
339
  self,
315
340
  *,
316
341
  indent: int | None = None,
342
+ ensure_ascii: bool = False,
317
343
  include: IncEx | None = None,
318
344
  exclude: IncEx | None = None,
345
+ context: Any | None = None,
319
346
  by_alias: bool | None = None,
320
347
  exclude_unset: bool = False,
321
348
  exclude_defaults: bool = False,
322
349
  exclude_none: bool = False,
350
+ exclude_computed_fields: bool = False,
323
351
  round_trip: bool = False,
324
352
  warnings: bool | Literal["none", "warn", "error"] = True,
325
- context: dict[str, Any] | None = None,
326
353
  fallback: Callable[[Any], Any] | None = None,
327
354
  serialize_as_any: bool = False,
328
355
  ) -> str:
@@ -354,6 +381,10 @@ class BaseModel(pydantic.BaseModel):
354
381
  raise ValueError("serialize_as_any is only supported in Pydantic v2")
355
382
  if fallback is not None:
356
383
  raise ValueError("fallback is only supported in Pydantic v2")
384
+ if ensure_ascii != False:
385
+ raise ValueError("ensure_ascii is only supported in Pydantic v2")
386
+ if exclude_computed_fields != False:
387
+ raise ValueError("exclude_computed_fields is only supported in Pydantic v2")
357
388
  return super().json( # type: ignore[reportDeprecated]
358
389
  indent=indent,
359
390
  include=include,
@@ -573,6 +604,9 @@ class CachedDiscriminatorType(Protocol):
573
604
  __discriminator__: DiscriminatorDetails
574
605
 
575
606
 
607
+ DISCRIMINATOR_CACHE: weakref.WeakKeyDictionary[type, DiscriminatorDetails] = weakref.WeakKeyDictionary()
608
+
609
+
576
610
  class DiscriminatorDetails:
577
611
  field_name: str
578
612
  """The name of the discriminator field in the variant class, e.g.
@@ -615,8 +649,9 @@ class DiscriminatorDetails:
615
649
 
616
650
 
617
651
  def _build_discriminated_union_meta(*, union: type, meta_annotations: tuple[Any, ...]) -> DiscriminatorDetails | None:
618
- if isinstance(union, CachedDiscriminatorType):
619
- return union.__discriminator__
652
+ cached = DISCRIMINATOR_CACHE.get(union)
653
+ if cached is not None:
654
+ return cached
620
655
 
621
656
  discriminator_field_name: str | None = None
622
657
 
@@ -669,7 +704,7 @@ def _build_discriminated_union_meta(*, union: type, meta_annotations: tuple[Any,
669
704
  discriminator_field=discriminator_field_name,
670
705
  discriminator_alias=discriminator_alias,
671
706
  )
672
- cast(CachedDiscriminatorType, union).__discriminator__ = details
707
+ DISCRIMINATOR_CACHE.setdefault(union, details)
673
708
  return details
674
709
 
675
710
 
@@ -765,6 +800,7 @@ class FinalRequestOptionsInput(TypedDict, total=False):
765
800
  timeout: float | Timeout | None
766
801
  files: HttpxRequestFiles | None
767
802
  idempotency_key: str
803
+ content: Union[bytes, bytearray, IO[bytes], Iterable[bytes], AsyncIterable[bytes], None]
768
804
  json_data: Body
769
805
  extra_json: AnyMapping
770
806
  follow_redirects: bool
@@ -783,6 +819,7 @@ class FinalRequestOptions(pydantic.BaseModel):
783
819
  post_parser: Union[Callable[[Any], Any], NotGiven] = NotGiven()
784
820
  follow_redirects: Union[bool, None] = None
785
821
 
822
+ content: Union[bytes, bytearray, IO[bytes], Iterable[bytes], AsyncIterable[bytes], None] = None
786
823
  # It should be noted that we cannot use `json` here as that would override
787
824
  # a BaseModel method in an incompatible fashion.
788
825
  json_data: Union[Body, None] = None
isaacus/_streaming.py CHANGED
@@ -54,12 +54,12 @@ class Stream(Generic[_T]):
54
54
  process_data = self._client._process_response_data
55
55
  iterator = self._iter_events()
56
56
 
57
- for sse in iterator:
58
- yield process_data(data=sse.json(), cast_to=cast_to, response=response)
59
-
60
- # Ensure the entire stream is consumed
61
- for _sse in iterator:
62
- ...
57
+ try:
58
+ for sse in iterator:
59
+ yield process_data(data=sse.json(), cast_to=cast_to, response=response)
60
+ finally:
61
+ # Ensure the response is closed even if the consumer doesn't read all data
62
+ response.close()
63
63
 
64
64
  def __enter__(self) -> Self:
65
65
  return self
@@ -118,12 +118,12 @@ class AsyncStream(Generic[_T]):
118
118
  process_data = self._client._process_response_data
119
119
  iterator = self._iter_events()
120
120
 
121
- async for sse in iterator:
122
- yield process_data(data=sse.json(), cast_to=cast_to, response=response)
123
-
124
- # Ensure the entire stream is consumed
125
- async for _sse in iterator:
126
- ...
121
+ try:
122
+ async for sse in iterator:
123
+ yield process_data(data=sse.json(), cast_to=cast_to, response=response)
124
+ finally:
125
+ # Ensure the response is closed even if the consumer doesn't read all data
126
+ await response.aclose()
127
127
 
128
128
  async def __aenter__(self) -> Self:
129
129
  return self
isaacus/_types.py CHANGED
@@ -13,9 +13,11 @@ from typing import (
13
13
  Mapping,
14
14
  TypeVar,
15
15
  Callable,
16
+ Iterable,
16
17
  Iterator,
17
18
  Optional,
18
19
  Sequence,
20
+ AsyncIterable,
19
21
  )
20
22
  from typing_extensions import (
21
23
  Set,
@@ -56,6 +58,13 @@ if TYPE_CHECKING:
56
58
  else:
57
59
  Base64FileInput = Union[IO[bytes], PathLike]
58
60
  FileContent = Union[IO[bytes], bytes, PathLike] # PathLike is not subscriptable in Python 3.8.
61
+
62
+
63
+ # Used for sending raw binary data / streaming data in request bodies
64
+ # e.g. for file uploads without multipart encoding
65
+ BinaryTypes = Union[bytes, bytearray, IO[bytes], Iterable[bytes]]
66
+ AsyncBinaryTypes = Union[bytes, bytearray, IO[bytes], AsyncIterable[bytes]]
67
+
59
68
  FileTypes = Union[
60
69
  # file (or bytes)
61
70
  FileContent,
@@ -243,6 +252,9 @@ _T_co = TypeVar("_T_co", covariant=True)
243
252
  if TYPE_CHECKING:
244
253
  # This works because str.__contains__ does not accept object (either in typeshed or at runtime)
245
254
  # https://github.com/hauntsaninja/useful_types/blob/5e9710f3875107d068e7679fd7fec9cfab0eff3b/useful_types/__init__.py#L285
255
+ #
256
+ # Note: index() and count() methods are intentionally omitted to allow pyright to properly
257
+ # infer TypedDict types when dict literals are used in lists assigned to SequenceNotStr.
246
258
  class SequenceNotStr(Protocol[_T_co]):
247
259
  @overload
248
260
  def __getitem__(self, index: SupportsIndex, /) -> _T_co: ...
@@ -251,8 +263,6 @@ if TYPE_CHECKING:
251
263
  def __contains__(self, value: object, /) -> bool: ...
252
264
  def __len__(self) -> int: ...
253
265
  def __iter__(self) -> Iterator[_T_co]: ...
254
- def index(self, value: Any, start: int = 0, stop: int = ..., /) -> int: ...
255
- def count(self, value: Any, /) -> int: ...
256
266
  def __reversed__(self) -> Iterator[_T_co]: ...
257
267
  else:
258
268
  # just point this to a normal `Sequence` at runtime to avoid having to special case
@@ -0,0 +1,35 @@
1
+ import json
2
+ from typing import Any
3
+ from datetime import datetime
4
+ from typing_extensions import override
5
+
6
+ import pydantic
7
+
8
+ from .._compat import model_dump
9
+
10
+
11
+ def openapi_dumps(obj: Any) -> bytes:
12
+ """
13
+ Serialize an object to UTF-8 encoded JSON bytes.
14
+
15
+ Extends the standard json.dumps with support for additional types
16
+ commonly used in the SDK, such as `datetime`, `pydantic.BaseModel`, etc.
17
+ """
18
+ return json.dumps(
19
+ obj,
20
+ cls=_CustomEncoder,
21
+ # Uses the same defaults as httpx's JSON serialization
22
+ ensure_ascii=False,
23
+ separators=(",", ":"),
24
+ allow_nan=False,
25
+ ).encode()
26
+
27
+
28
+ class _CustomEncoder(json.JSONEncoder):
29
+ @override
30
+ def default(self, o: Any) -> Any:
31
+ if isinstance(o, datetime):
32
+ return o.isoformat()
33
+ if isinstance(o, pydantic.BaseModel):
34
+ return model_dump(o, exclude_unset=True, mode="json", by_alias=True)
35
+ return super().default(o)
isaacus/_utils/_sync.py CHANGED
@@ -1,10 +1,8 @@
1
1
  from __future__ import annotations
2
2
 
3
- import sys
4
3
  import asyncio
5
4
  import functools
6
- import contextvars
7
- from typing import Any, TypeVar, Callable, Awaitable
5
+ from typing import TypeVar, Callable, Awaitable
8
6
  from typing_extensions import ParamSpec
9
7
 
10
8
  import anyio
@@ -15,34 +13,11 @@ T_Retval = TypeVar("T_Retval")
15
13
  T_ParamSpec = ParamSpec("T_ParamSpec")
16
14
 
17
15
 
18
- if sys.version_info >= (3, 9):
19
- _asyncio_to_thread = asyncio.to_thread
20
- else:
21
- # backport of https://docs.python.org/3/library/asyncio-task.html#asyncio.to_thread
22
- # for Python 3.8 support
23
- async def _asyncio_to_thread(
24
- func: Callable[T_ParamSpec, T_Retval], /, *args: T_ParamSpec.args, **kwargs: T_ParamSpec.kwargs
25
- ) -> Any:
26
- """Asynchronously run function *func* in a separate thread.
27
-
28
- Any *args and **kwargs supplied for this function are directly passed
29
- to *func*. Also, the current :class:`contextvars.Context` is propagated,
30
- allowing context variables from the main thread to be accessed in the
31
- separate thread.
32
-
33
- Returns a coroutine that can be awaited to get the eventual result of *func*.
34
- """
35
- loop = asyncio.events.get_running_loop()
36
- ctx = contextvars.copy_context()
37
- func_call = functools.partial(ctx.run, func, *args, **kwargs)
38
- return await loop.run_in_executor(None, func_call)
39
-
40
-
41
16
  async def to_thread(
42
17
  func: Callable[T_ParamSpec, T_Retval], /, *args: T_ParamSpec.args, **kwargs: T_ParamSpec.kwargs
43
18
  ) -> T_Retval:
44
19
  if sniffio.current_async_library() == "asyncio":
45
- return await _asyncio_to_thread(func, *args, **kwargs)
20
+ return await asyncio.to_thread(func, *args, **kwargs)
46
21
 
47
22
  return await anyio.to_thread.run_sync(
48
23
  functools.partial(func, *args, **kwargs),
@@ -53,10 +28,7 @@ async def to_thread(
53
28
  def asyncify(function: Callable[T_ParamSpec, T_Retval]) -> Callable[T_ParamSpec, Awaitable[T_Retval]]:
54
29
  """
55
30
  Take a blocking function and create an async one that receives the same
56
- positional and keyword arguments. For python version 3.9 and above, it uses
57
- asyncio.to_thread to run the function in a separate thread. For python version
58
- 3.8, it uses locally defined copy of the asyncio.to_thread function which was
59
- introduced in python 3.9.
31
+ positional and keyword arguments.
60
32
 
61
33
  Usage:
62
34
 
isaacus/_utils/_utils.py CHANGED
@@ -133,7 +133,7 @@ def is_given(obj: _T | NotGiven | Omit) -> TypeGuard[_T]:
133
133
  # Type safe methods for narrowing types with TypeVars.
134
134
  # The default narrowing for isinstance(obj, dict) is dict[unknown, unknown],
135
135
  # however this cause Pyright to rightfully report errors. As we know we don't
136
- # care about the contained types we can safely use `object` in it's place.
136
+ # care about the contained types we can safely use `object` in its place.
137
137
  #
138
138
  # There are two separate functions defined, `is_*` and `is_*_t` for different use cases.
139
139
  # `is_*` is for when you're dealing with an unknown input
isaacus/_version.py CHANGED
@@ -1,4 +1,4 @@
1
1
  # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
 
3
3
  __title__ = "isaacus"
4
- __version__ = "0.9.1" # x-release-please-version
4
+ __version__ = "0.10.1" # x-release-please-version
@@ -16,6 +16,14 @@ from .rerankings import (
16
16
  RerankingsResourceWithStreamingResponse,
17
17
  AsyncRerankingsResourceWithStreamingResponse,
18
18
  )
19
+ from .enrichments import (
20
+ EnrichmentsResource,
21
+ AsyncEnrichmentsResource,
22
+ EnrichmentsResourceWithRawResponse,
23
+ AsyncEnrichmentsResourceWithRawResponse,
24
+ EnrichmentsResourceWithStreamingResponse,
25
+ AsyncEnrichmentsResourceWithStreamingResponse,
26
+ )
19
27
  from .extractions import (
20
28
  ExtractionsResource,
21
29
  AsyncExtractionsResource,
@@ -58,4 +66,10 @@ __all__ = [
58
66
  "AsyncExtractionsResourceWithRawResponse",
59
67
  "ExtractionsResourceWithStreamingResponse",
60
68
  "AsyncExtractionsResourceWithStreamingResponse",
69
+ "EnrichmentsResource",
70
+ "AsyncEnrichmentsResource",
71
+ "EnrichmentsResourceWithRawResponse",
72
+ "AsyncEnrichmentsResourceWithRawResponse",
73
+ "EnrichmentsResourceWithStreamingResponse",
74
+ "AsyncEnrichmentsResourceWithStreamingResponse",
61
75
  ]
@@ -0,0 +1,224 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Union, Optional
6
+ from typing_extensions import Literal
7
+
8
+ import httpx
9
+
10
+ from ..types import enrichment_create_params
11
+ from .._types import Body, Omit, Query, Headers, NotGiven, SequenceNotStr, omit, not_given
12
+ from .._utils import maybe_transform, async_maybe_transform
13
+ from .._compat import cached_property
14
+ from .._resource import SyncAPIResource, AsyncAPIResource
15
+ from .._response import (
16
+ to_raw_response_wrapper,
17
+ to_streamed_response_wrapper,
18
+ async_to_raw_response_wrapper,
19
+ async_to_streamed_response_wrapper,
20
+ )
21
+ from .._base_client import make_request_options
22
+ from ..types.enrichment_response import EnrichmentResponse
23
+
24
+ __all__ = ["EnrichmentsResource", "AsyncEnrichmentsResource"]
25
+
26
+
27
+ class EnrichmentsResource(SyncAPIResource):
28
+ @cached_property
29
+ def with_raw_response(self) -> EnrichmentsResourceWithRawResponse:
30
+ """
31
+ This property can be used as a prefix for any HTTP method call to return
32
+ the raw response object instead of the parsed content.
33
+
34
+ For more information, see https://www.github.com/isaacus-dev/isaacus-python#accessing-raw-response-data-eg-headers
35
+ """
36
+ return EnrichmentsResourceWithRawResponse(self)
37
+
38
+ @cached_property
39
+ def with_streaming_response(self) -> EnrichmentsResourceWithStreamingResponse:
40
+ """
41
+ An alternative to `.with_raw_response` that doesn't eagerly read the response body.
42
+
43
+ For more information, see https://www.github.com/isaacus-dev/isaacus-python#with_streaming_response
44
+ """
45
+ return EnrichmentsResourceWithStreamingResponse(self)
46
+
47
+ def create(
48
+ self,
49
+ *,
50
+ model: Literal["kanon-2-enricher-preview"],
51
+ texts: Union[SequenceNotStr[str], str],
52
+ overflow_strategy: Optional[Literal["auto", "drop_end"]] | Omit = omit,
53
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
54
+ # The extra values given here take precedence over values defined on the client or passed to this method.
55
+ extra_headers: Headers | None = None,
56
+ extra_query: Query | None = None,
57
+ extra_body: Body | None = None,
58
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
59
+ ) -> EnrichmentResponse:
60
+ """
61
+ Enrich documents with an Isaacus enricher model.
62
+
63
+ Args:
64
+ model: The ID of the [model](https://docs.isaacus.com/models#enrichment) to use for
65
+ enrichment.
66
+
67
+ texts: A text or array of texts to be enriched, each containing at least one
68
+ non-whitespace character.
69
+
70
+ No more than 8 texts can be enriched in a single request.
71
+
72
+ overflow_strategy: The strategy for handling content exceeding the model's maximum input length.
73
+
74
+ `auto` currently behaves the same as `drop_end`, dropping excess tokens from the
75
+ end of input. In the future, `auto` may implement more sophisticated strategies
76
+ such as chunking and context-aware stitching.
77
+
78
+ `drop_end` drops tokens from the end of input exceeding the model's maximum
79
+ input length.
80
+
81
+ `null`, which is the default setting, raises an error if the input exceeds the
82
+ model's maximum input length.
83
+
84
+ extra_headers: Send extra headers
85
+
86
+ extra_query: Add additional query parameters to the request
87
+
88
+ extra_body: Add additional JSON properties to the request
89
+
90
+ timeout: Override the client-level default timeout for this request, in seconds
91
+ """
92
+ return self._post(
93
+ "/enrichments",
94
+ body=maybe_transform(
95
+ {
96
+ "model": model,
97
+ "texts": texts,
98
+ "overflow_strategy": overflow_strategy,
99
+ },
100
+ enrichment_create_params.EnrichmentCreateParams,
101
+ ),
102
+ options=make_request_options(
103
+ extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
104
+ ),
105
+ cast_to=EnrichmentResponse,
106
+ )
107
+
108
+
109
+ class AsyncEnrichmentsResource(AsyncAPIResource):
110
+ @cached_property
111
+ def with_raw_response(self) -> AsyncEnrichmentsResourceWithRawResponse:
112
+ """
113
+ This property can be used as a prefix for any HTTP method call to return
114
+ the raw response object instead of the parsed content.
115
+
116
+ For more information, see https://www.github.com/isaacus-dev/isaacus-python#accessing-raw-response-data-eg-headers
117
+ """
118
+ return AsyncEnrichmentsResourceWithRawResponse(self)
119
+
120
+ @cached_property
121
+ def with_streaming_response(self) -> AsyncEnrichmentsResourceWithStreamingResponse:
122
+ """
123
+ An alternative to `.with_raw_response` that doesn't eagerly read the response body.
124
+
125
+ For more information, see https://www.github.com/isaacus-dev/isaacus-python#with_streaming_response
126
+ """
127
+ return AsyncEnrichmentsResourceWithStreamingResponse(self)
128
+
129
+ async def create(
130
+ self,
131
+ *,
132
+ model: Literal["kanon-2-enricher-preview"],
133
+ texts: Union[SequenceNotStr[str], str],
134
+ overflow_strategy: Optional[Literal["auto", "drop_end"]] | Omit = omit,
135
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
136
+ # The extra values given here take precedence over values defined on the client or passed to this method.
137
+ extra_headers: Headers | None = None,
138
+ extra_query: Query | None = None,
139
+ extra_body: Body | None = None,
140
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
141
+ ) -> EnrichmentResponse:
142
+ """
143
+ Enrich documents with an Isaacus enricher model.
144
+
145
+ Args:
146
+ model: The ID of the [model](https://docs.isaacus.com/models#enrichment) to use for
147
+ enrichment.
148
+
149
+ texts: A text or array of texts to be enriched, each containing at least one
150
+ non-whitespace character.
151
+
152
+ No more than 8 texts can be enriched in a single request.
153
+
154
+ overflow_strategy: The strategy for handling content exceeding the model's maximum input length.
155
+
156
+ `auto` currently behaves the same as `drop_end`, dropping excess tokens from the
157
+ end of input. In the future, `auto` may implement more sophisticated strategies
158
+ such as chunking and context-aware stitching.
159
+
160
+ `drop_end` drops tokens from the end of input exceeding the model's maximum
161
+ input length.
162
+
163
+ `null`, which is the default setting, raises an error if the input exceeds the
164
+ model's maximum input length.
165
+
166
+ extra_headers: Send extra headers
167
+
168
+ extra_query: Add additional query parameters to the request
169
+
170
+ extra_body: Add additional JSON properties to the request
171
+
172
+ timeout: Override the client-level default timeout for this request, in seconds
173
+ """
174
+ return await self._post(
175
+ "/enrichments",
176
+ body=await async_maybe_transform(
177
+ {
178
+ "model": model,
179
+ "texts": texts,
180
+ "overflow_strategy": overflow_strategy,
181
+ },
182
+ enrichment_create_params.EnrichmentCreateParams,
183
+ ),
184
+ options=make_request_options(
185
+ extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
186
+ ),
187
+ cast_to=EnrichmentResponse,
188
+ )
189
+
190
+
191
+ class EnrichmentsResourceWithRawResponse:
192
+ def __init__(self, enrichments: EnrichmentsResource) -> None:
193
+ self._enrichments = enrichments
194
+
195
+ self.create = to_raw_response_wrapper(
196
+ enrichments.create,
197
+ )
198
+
199
+
200
+ class AsyncEnrichmentsResourceWithRawResponse:
201
+ def __init__(self, enrichments: AsyncEnrichmentsResource) -> None:
202
+ self._enrichments = enrichments
203
+
204
+ self.create = async_to_raw_response_wrapper(
205
+ enrichments.create,
206
+ )
207
+
208
+
209
+ class EnrichmentsResourceWithStreamingResponse:
210
+ def __init__(self, enrichments: EnrichmentsResource) -> None:
211
+ self._enrichments = enrichments
212
+
213
+ self.create = to_streamed_response_wrapper(
214
+ enrichments.create,
215
+ )
216
+
217
+
218
+ class AsyncEnrichmentsResourceWithStreamingResponse:
219
+ def __init__(self, enrichments: AsyncEnrichmentsResource) -> None:
220
+ self._enrichments = enrichments
221
+
222
+ self.create = async_to_streamed_response_wrapper(
223
+ enrichments.create,
224
+ )
@@ -62,7 +62,7 @@ class RerankingsResource(SyncAPIResource):
62
62
  timeout: float | httpx.Timeout | None | NotGiven = not_given,
63
63
  ) -> RerankingResponse:
64
64
  """
65
- Rerank legal documents by their relevance to a query with an Isaacus legal AI
65
+ Rank legal documents by their relevance to a query with an Isaacus legal AI
66
66
  reranker.
67
67
 
68
68
  Args:
@@ -173,7 +173,7 @@ class AsyncRerankingsResource(AsyncAPIResource):
173
173
  timeout: float | httpx.Timeout | None | NotGiven = not_given,
174
174
  ) -> RerankingResponse:
175
175
  """
176
- Rerank legal documents by their relevance to a query with an Isaacus legal AI
176
+ Rank legal documents by their relevance to a query with an Isaacus legal AI
177
177
  reranker.
178
178
 
179
179
  Args:
isaacus/types/__init__.py CHANGED
@@ -4,5 +4,7 @@ from __future__ import annotations
4
4
 
5
5
  from .embedding_response import EmbeddingResponse as EmbeddingResponse
6
6
  from .reranking_response import RerankingResponse as RerankingResponse
7
+ from .enrichment_response import EnrichmentResponse as EnrichmentResponse
7
8
  from .embedding_create_params import EmbeddingCreateParams as EmbeddingCreateParams
8
9
  from .reranking_create_params import RerankingCreateParams as RerankingCreateParams
10
+ from .enrichment_create_params import EnrichmentCreateParams as EnrichmentCreateParams
@@ -68,6 +68,8 @@ class Classification(BaseModel):
68
68
 
69
69
 
70
70
  class Usage(BaseModel):
71
+ """Statistics about the usage of resources in the process of classifying the text."""
72
+
71
73
  input_tokens: int
72
74
  """The number of tokens inputted to the model."""
73
75
 
@@ -59,11 +59,13 @@ class UniversalCreateParams(TypedDict, total=False):
59
59
 
60
60
 
61
61
  class ChunkingOptions(TypedDict, total=False):
62
+ """Options for how to split text into smaller chunks."""
63
+
62
64
  overlap_ratio: Optional[float]
63
65
  """A number greater than or equal to 0 and less than 1."""
64
66
 
65
67
  overlap_tokens: Optional[int]
66
- """A whole number greater than -1."""
68
+ """A whole number greater than or equal to 0."""
67
69
 
68
70
  size: Optional[int]
69
71
  """A whole number greater than or equal to 1."""
@@ -19,6 +19,8 @@ class Embedding(BaseModel):
19
19
 
20
20
 
21
21
  class Usage(BaseModel):
22
+ """Statistics about the usage of resources in the process of embedding the inputs."""
23
+
22
24
  input_tokens: int
23
25
  """The number of tokens inputted to the model."""
24
26