|
| 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 | + ) |
0 commit comments