Repository navigation
Expand file tree
/
Copy pathcapabilities.py
More file actions
469 lines (380 loc) · 16.6 KB
/
Copy pathcapabilities.py
File metadata and controls
469 lines (380 loc) · 16.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
# File generated from our OpenAPI spec by Stainless.
from __future__ import annotations
from typing import Dict
from typing_extensions import Literal
import httpx
from .media import (
Media,
AsyncMedia,
MediaWithRawResponse,
AsyncMediaWithRawResponse,
MediaWithStreamingResponse,
AsyncMediaWithStreamingResponse,
)
from ...types import capability_compare_params, capability_extract_params, capability_summarize_params
from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven
from ..._utils import (
maybe_transform,
async_maybe_transform,
)
from ..._compat import cached_property
from ..._resource import SyncAPIResource, AsyncAPIResource
from ..._response import (
to_raw_response_wrapper,
to_streamed_response_wrapper,
async_to_raw_response_wrapper,
async_to_streamed_response_wrapper,
)
from ..._base_client import (
make_request_options,
)
from ...types.shared import TextSummary, TextExtractor, TextComparator
__all__ = ["Capabilities", "AsyncCapabilities"]
class Capabilities(SyncAPIResource):
@cached_property
def media(self) -> Media:
return Media(self._client)
@cached_property
def with_raw_response(self) -> CapabilitiesWithRawResponse:
return CapabilitiesWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> CapabilitiesWithStreamingResponse:
return CapabilitiesWithStreamingResponse(self)
def compare(
self,
*,
text1: str,
text2: str,
variables: Dict[str, capability_compare_params.Variables],
lang: Literal["en", "es", "pt", "fr", "de", "it", "nl", "sv", "pl", "ro"] | NotGiven = NOT_GIVEN,
prompt: str | NotGiven = NOT_GIVEN,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> TextComparator:
"""
Compare extracts of text based on a specific data.
Args:
text1: The text to be compared.
text2: The text to be compared with.
variables: The variables to be compared.
lang: The language of the output. If not provided, the language used will be the same
as the language of the text provided.
prompt: The prompt to be used as criteria to compare the texts.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._post(
"/v1/capabilities/compare",
body=maybe_transform(
{
"text1": text1,
"text2": text2,
"variables": variables,
"lang": lang,
"prompt": prompt,
},
capability_compare_params.CapabilityCompareParams,
),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=TextComparator,
)
def extract(
self,
*,
text: str,
variables: Dict[str, capability_extract_params.Variables],
lang: Literal["en", "es", "pt", "fr", "de", "it", "nl", "sv", "pl", "ro"] | NotGiven = NOT_GIVEN,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> TextExtractor:
"""Extracts structured data from text.
The text is analyzed and the variables are
extracted.
Args:
text: The text to be extracted from.
variables: The variables to be extracted from the text.
lang: The language of the output. If not provided, the language used will be the same
as the language of the text provided.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._post(
"/v1/capabilities/extract",
body=maybe_transform(
{
"text": text,
"variables": variables,
"lang": lang,
},
capability_extract_params.CapabilityExtractParams,
),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=TextExtractor,
)
def summarize(
self,
*,
text: str,
format: Literal["paragraph", "bullet"] | NotGiven = NOT_GIVEN,
lang: Literal["en", "es", "pt", "fr", "de", "it", "nl", "sv", "pl", "ro"] | NotGiven = NOT_GIVEN,
length: Literal["short", "medium", "long"] | NotGiven = NOT_GIVEN,
summary_hint: str | NotGiven = NOT_GIVEN,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> TextSummary:
"""Summarizes a text.
The summary is returned in the format and length specified.
Args:
text: The text to be summarized.
format: Text Summary Request Format.
lang: The language of the output. If not provided, the language used will be the same
as the language of the text provided.
length: Text Summary Request Length.
summary_hint: A hint to the summarization. This can be used to provide a specific summary if
the user has a specific summary in mind.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._post(
"/v1/capabilities/summarize",
body=maybe_transform(
{
"text": text,
"format": format,
"lang": lang,
"length": length,
"summary_hint": summary_hint,
},
capability_summarize_params.CapabilitySummarizeParams,
),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=TextSummary,
)
class AsyncCapabilities(AsyncAPIResource):
@cached_property
def media(self) -> AsyncMedia:
return AsyncMedia(self._client)
@cached_property
def with_raw_response(self) -> AsyncCapabilitiesWithRawResponse:
return AsyncCapabilitiesWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> AsyncCapabilitiesWithStreamingResponse:
return AsyncCapabilitiesWithStreamingResponse(self)
async def compare(
self,
*,
text1: str,
text2: str,
variables: Dict[str, capability_compare_params.Variables],
lang: Literal["en", "es", "pt", "fr", "de", "it", "nl", "sv", "pl", "ro"] | NotGiven = NOT_GIVEN,
prompt: str | NotGiven = NOT_GIVEN,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> TextComparator:
"""
Compare extracts of text based on a specific data.
Args:
text1: The text to be compared.
text2: The text to be compared with.
variables: The variables to be compared.
lang: The language of the output. If not provided, the language used will be the same
as the language of the text provided.
prompt: The prompt to be used as criteria to compare the texts.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return await self._post(
"/v1/capabilities/compare",
body=await async_maybe_transform(
{
"text1": text1,
"text2": text2,
"variables": variables,
"lang": lang,
"prompt": prompt,
},
capability_compare_params.CapabilityCompareParams,
),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=TextComparator,
)
async def extract(
self,
*,
text: str,
variables: Dict[str, capability_extract_params.Variables],
lang: Literal["en", "es", "pt", "fr", "de", "it", "nl", "sv", "pl", "ro"] | NotGiven = NOT_GIVEN,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> TextExtractor:
"""Extracts structured data from text.
The text is analyzed and the variables are
extracted.
Args:
text: The text to be extracted from.
variables: The variables to be extracted from the text.
lang: The language of the output. If not provided, the language used will be the same
as the language of the text provided.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return await self._post(
"/v1/capabilities/extract",
body=await async_maybe_transform(
{
"text": text,
"variables": variables,
"lang": lang,
},
capability_extract_params.CapabilityExtractParams,
),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=TextExtractor,
)
async def summarize(
self,
*,
text: str,
format: Literal["paragraph", "bullet"] | NotGiven = NOT_GIVEN,
lang: Literal["en", "es", "pt", "fr", "de", "it", "nl", "sv", "pl", "ro"] | NotGiven = NOT_GIVEN,
length: Literal["short", "medium", "long"] | NotGiven = NOT_GIVEN,
summary_hint: str | NotGiven = NOT_GIVEN,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> TextSummary:
"""Summarizes a text.
The summary is returned in the format and length specified.
Args:
text: The text to be summarized.
format: Text Summary Request Format.
lang: The language of the output. If not provided, the language used will be the same
as the language of the text provided.
length: Text Summary Request Length.
summary_hint: A hint to the summarization. This can be used to provide a specific summary if
the user has a specific summary in mind.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return await self._post(
"/v1/capabilities/summarize",
body=await async_maybe_transform(
{
"text": text,
"format": format,
"lang": lang,
"length": length,
"summary_hint": summary_hint,
},
capability_summarize_params.CapabilitySummarizeParams,
),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=TextSummary,
)
class CapabilitiesWithRawResponse:
def __init__(self, capabilities: Capabilities) -> None:
self._capabilities = capabilities
self.compare = to_raw_response_wrapper(
capabilities.compare,
)
self.extract = to_raw_response_wrapper(
capabilities.extract,
)
self.summarize = to_raw_response_wrapper(
capabilities.summarize,
)
@cached_property
def media(self) -> MediaWithRawResponse:
return MediaWithRawResponse(self._capabilities.media)
class AsyncCapabilitiesWithRawResponse:
def __init__(self, capabilities: AsyncCapabilities) -> None:
self._capabilities = capabilities
self.compare = async_to_raw_response_wrapper(
capabilities.compare,
)
self.extract = async_to_raw_response_wrapper(
capabilities.extract,
)
self.summarize = async_to_raw_response_wrapper(
capabilities.summarize,
)
@cached_property
def media(self) -> AsyncMediaWithRawResponse:
return AsyncMediaWithRawResponse(self._capabilities.media)
class CapabilitiesWithStreamingResponse:
def __init__(self, capabilities: Capabilities) -> None:
self._capabilities = capabilities
self.compare = to_streamed_response_wrapper(
capabilities.compare,
)
self.extract = to_streamed_response_wrapper(
capabilities.extract,
)
self.summarize = to_streamed_response_wrapper(
capabilities.summarize,
)
@cached_property
def media(self) -> MediaWithStreamingResponse:
return MediaWithStreamingResponse(self._capabilities.media)
class AsyncCapabilitiesWithStreamingResponse:
def __init__(self, capabilities: AsyncCapabilities) -> None:
self._capabilities = capabilities
self.compare = async_to_streamed_response_wrapper(
capabilities.compare,
)
self.extract = async_to_streamed_response_wrapper(
capabilities.extract,
)
self.summarize = async_to_streamed_response_wrapper(
capabilities.summarize,
)
@cached_property
def media(self) -> AsyncMediaWithStreamingResponse:
return AsyncMediaWithStreamingResponse(self._capabilities.media)