Skip to content

Commit 4fb2535

Browse files
feat(api)!: made universal classification endpoint multi-input only
1 parent bb3df78 commit 4fb2535

File tree

7 files changed

+100
-76
lines changed

7 files changed

+100
-76
lines changed

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 2
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/isaacus%2Fisaacus-c224b4437a8a19d29aa29506fdb44ffc5316d5ba3600feee90678acdb2557e23.yml
3-
openapi_spec_hash: 6b74504e14f7e1aa631e6bd76d596f48
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/isaacus%2Fisaacus-213d554b23f35e746460af23dd32bdde471230549ad223518c86d42ea917a180.yml
3+
openapi_spec_hash: 3672281fe031a42fc59e3a2af758a8f8
44
config_hash: 1d603d50b7183a492ad6df5f728a1863

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ client = Isaacus(
3434
universal_classification = client.classifications.universal.create(
3535
model="kanon-universal-classifier",
3636
query="This is a confidentiality clause.",
37-
text="I agree not to tell anyone about the document.",
37+
texts=["I agree not to tell anyone about the document."],
3838
)
39-
print(universal_classification.chunks)
39+
print(universal_classification.classifications)
4040
```
4141

4242
While you can provide an `api_key` keyword argument,
@@ -62,9 +62,9 @@ async def main() -> None:
6262
universal_classification = await client.classifications.universal.create(
6363
model="kanon-universal-classifier",
6464
query="This is a confidentiality clause.",
65-
text="I agree not to tell anyone about the document.",
65+
texts=["I agree not to tell anyone about the document."],
6666
)
67-
print(universal_classification.chunks)
67+
print(universal_classification.classifications)
6868

6969

7070
asyncio.run(main())
@@ -93,7 +93,7 @@ client = Isaacus()
9393
universal_classification = client.classifications.universal.create(
9494
model="kanon-universal-classifier",
9595
query="This is a confidentiality clause.",
96-
text="I agree not to tell anyone about the document.",
96+
texts=["I agree not to tell anyone about the document."],
9797
chunking_options={
9898
"overlap_ratio": 0.1,
9999
"overlap_tokens": None,
@@ -122,7 +122,7 @@ try:
122122
client.classifications.universal.create(
123123
model="kanon-universal-classifier",
124124
query="This is a confidentiality clause.",
125-
text="I agree not to tell anyone about the document.",
125+
texts=["I agree not to tell anyone about the document."],
126126
)
127127
except isaacus.APIConnectionError as e:
128128
print("The server could not be reached")
@@ -169,7 +169,7 @@ client = Isaacus(
169169
client.with_options(max_retries=5).classifications.universal.create(
170170
model="kanon-universal-classifier",
171171
query="This is a confidentiality clause.",
172-
text="I agree not to tell anyone about the document.",
172+
texts=["I agree not to tell anyone about the document."],
173173
)
174174
```
175175

@@ -196,7 +196,7 @@ client = Isaacus(
196196
client.with_options(timeout=5.0).classifications.universal.create(
197197
model="kanon-universal-classifier",
198198
query="This is a confidentiality clause.",
199-
text="I agree not to tell anyone about the document.",
199+
texts=["I agree not to tell anyone about the document."],
200200
)
201201
```
202202

@@ -241,12 +241,12 @@ client = Isaacus()
241241
response = client.classifications.universal.with_raw_response.create(
242242
model="kanon-universal-classifier",
243243
query="This is a confidentiality clause.",
244-
text="I agree not to tell anyone about the document.",
244+
texts=["I agree not to tell anyone about the document."],
245245
)
246246
print(response.headers.get('X-My-Header'))
247247

248248
universal = response.parse() # get the object that `classifications.universal.create()` would have returned
249-
print(universal.chunks)
249+
print(universal.classifications)
250250
```
251251

252252
These methods return an [`APIResponse`](https://github.com/isaacus-dev/isaacus-python/tree/main/src/isaacus/_response.py) object.
@@ -263,7 +263,7 @@ To stream the response body, use `.with_streaming_response` instead, which requi
263263
with client.classifications.universal.with_streaming_response.create(
264264
model="kanon-universal-classifier",
265265
query="This is a confidentiality clause.",
266-
text="I agree not to tell anyone about the document.",
266+
texts=["I agree not to tell anyone about the document."],
267267
) as response:
268268
print(response.headers.get("X-My-Header"))
269269

src/isaacus/resources/classifications/universal.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
from typing import Optional
5+
from typing import List, Optional
66
from typing_extensions import Literal
77

88
import httpx
@@ -52,7 +52,7 @@ def create(
5252
*,
5353
model: Literal["kanon-universal-classifier", "kanon-universal-classifier-mini"],
5454
query: str,
55-
text: str,
55+
texts: List[str],
5656
chunking_options: Optional[universal_create_params.ChunkingOptions] | NotGiven = NOT_GIVEN,
5757
is_iql: bool | NotGiven = NOT_GIVEN,
5858
scoring_method: Literal["auto", "chunk_max", "chunk_avg", "chunk_min"] | NotGiven = NOT_GIVEN,
@@ -64,24 +64,24 @@ def create(
6464
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
6565
) -> UniversalClassification:
6666
"""
67-
Classify the relevance of a legal document to a query with an Isaacus universal
67+
Classify the relevance of legal documents to a query with an Isaacus universal
6868
legal AI classifier.
6969
7070
Args:
7171
model: The ID of the [model](https://docs.isaacus.com/models#universal-classification)
7272
to use for universal classification.
7373
7474
query: The [Isaacus Query Language (IQL)](https://docs.isaacus.com/iql) query or, if
75-
IQL is disabled, the statement, to evaluate the text against.
75+
IQL is disabled, the statement, to evaluate the texts against.
7676
7777
The query must contain at least one non-whitespace character.
7878
79-
Unlike the text being classified, the query cannot be so long that it exceeds
79+
Unlike the texts being classified, the query cannot be so long that it exceeds
8080
the maximum input length of the universal classifier.
8181
82-
text: The text to classify.
82+
texts: The texts to classify.
8383
84-
The text must contain at least one non-whitespace character.
84+
The texts must contain at least one non-whitespace character.
8585
8686
chunking_options: Options for how to split text into smaller chunks.
8787
@@ -92,13 +92,13 @@ def create(
9292
9393
`auto` is the default scoring method and is recommended for most use cases.
9494
Currently, it is equivalent to `chunk_max`. In the future, it will automatically
95-
select the best method based on the model and input.
95+
select the best method based on the model and inputs.
9696
97-
`chunk_max` uses the highest confidence score of all of the text's chunks.
97+
`chunk_max` uses the highest confidence score of all of the texts' chunks.
9898
99-
`chunk_avg` averages the confidence scores of all of the text's chunks.
99+
`chunk_avg` averages the confidence scores of all of the texts' chunks.
100100
101-
`chunk_min` uses the lowest confidence score of all of the text's chunks.
101+
`chunk_min` uses the lowest confidence score of all of the texts' chunks.
102102
103103
extra_headers: Send extra headers
104104
@@ -114,7 +114,7 @@ def create(
114114
{
115115
"model": model,
116116
"query": query,
117-
"text": text,
117+
"texts": texts,
118118
"chunking_options": chunking_options,
119119
"is_iql": is_iql,
120120
"scoring_method": scoring_method,
@@ -153,7 +153,7 @@ async def create(
153153
*,
154154
model: Literal["kanon-universal-classifier", "kanon-universal-classifier-mini"],
155155
query: str,
156-
text: str,
156+
texts: List[str],
157157
chunking_options: Optional[universal_create_params.ChunkingOptions] | NotGiven = NOT_GIVEN,
158158
is_iql: bool | NotGiven = NOT_GIVEN,
159159
scoring_method: Literal["auto", "chunk_max", "chunk_avg", "chunk_min"] | NotGiven = NOT_GIVEN,
@@ -165,24 +165,24 @@ async def create(
165165
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
166166
) -> UniversalClassification:
167167
"""
168-
Classify the relevance of a legal document to a query with an Isaacus universal
168+
Classify the relevance of legal documents to a query with an Isaacus universal
169169
legal AI classifier.
170170
171171
Args:
172172
model: The ID of the [model](https://docs.isaacus.com/models#universal-classification)
173173
to use for universal classification.
174174
175175
query: The [Isaacus Query Language (IQL)](https://docs.isaacus.com/iql) query or, if
176-
IQL is disabled, the statement, to evaluate the text against.
176+
IQL is disabled, the statement, to evaluate the texts against.
177177
178178
The query must contain at least one non-whitespace character.
179179
180-
Unlike the text being classified, the query cannot be so long that it exceeds
180+
Unlike the texts being classified, the query cannot be so long that it exceeds
181181
the maximum input length of the universal classifier.
182182
183-
text: The text to classify.
183+
texts: The texts to classify.
184184
185-
The text must contain at least one non-whitespace character.
185+
The texts must contain at least one non-whitespace character.
186186
187187
chunking_options: Options for how to split text into smaller chunks.
188188
@@ -193,13 +193,13 @@ async def create(
193193
194194
`auto` is the default scoring method and is recommended for most use cases.
195195
Currently, it is equivalent to `chunk_max`. In the future, it will automatically
196-
select the best method based on the model and input.
196+
select the best method based on the model and inputs.
197197
198-
`chunk_max` uses the highest confidence score of all of the text's chunks.
198+
`chunk_max` uses the highest confidence score of all of the texts' chunks.
199199
200-
`chunk_avg` averages the confidence scores of all of the text's chunks.
200+
`chunk_avg` averages the confidence scores of all of the texts' chunks.
201201
202-
`chunk_min` uses the lowest confidence score of all of the text's chunks.
202+
`chunk_min` uses the lowest confidence score of all of the texts' chunks.
203203
204204
extra_headers: Send extra headers
205205
@@ -215,7 +215,7 @@ async def create(
215215
{
216216
"model": model,
217217
"query": query,
218-
"text": text,
218+
"texts": texts,
219219
"chunking_options": chunking_options,
220220
"is_iql": is_iql,
221221
"scoring_method": scoring_method,

src/isaacus/types/classifications/universal_classification.py

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,22 @@
44

55
from ..._models import BaseModel
66

7-
__all__ = ["UniversalClassification", "Chunk", "Usage"]
7+
__all__ = ["UniversalClassification", "Classification", "ClassificationChunk", "Usage"]
88

99

10-
class Chunk(BaseModel):
10+
class ClassificationChunk(BaseModel):
1111
end: int
12-
"""The end index of the chunk in the original text."""
12+
"""
13+
The index of the character in the original text where the chunk ends, beginning
14+
from `0` (such that, in Python, the chunk is equivalent to `text[start:end+1]`).
15+
"""
1316

1417
index: int
15-
"""The index of the chunk in the list of chunks."""
18+
"""
19+
The original position of the chunk in the outputted list of chunks before
20+
sorting, starting from `0` (and, therefore, ending at the number of chunks minus
21+
`1`).
22+
"""
1623

1724
score: float
1825
"""
@@ -24,19 +31,17 @@ class Chunk(BaseModel):
2431
"""
2532

2633
start: int
27-
"""The start index of the chunk in the original text."""
34+
"""
35+
The index of the character in the original text where the chunk starts,
36+
beginning from `0`.
37+
"""
2838

2939
text: str
3040
"""The text of the chunk."""
3141

3242

33-
class Usage(BaseModel):
34-
input_tokens: int
35-
"""The number of tokens inputted to the model."""
36-
37-
38-
class UniversalClassification(BaseModel):
39-
chunks: Optional[List[Chunk]] = None
43+
class Classification(BaseModel):
44+
chunks: Optional[List[ClassificationChunk]] = None
4045
"""
4146
The text as broken into chunks by
4247
[semchunk](https://github.com/isaacus-dev/semchunk), each chunk with its own
@@ -45,6 +50,12 @@ class UniversalClassification(BaseModel):
4550
If no chunking occurred, this will be `null`.
4651
"""
4752

53+
index: int
54+
"""
55+
The index of the text in the input array of texts, starting from `0` (and,
56+
therefore, ending at the number of texts minus `1`).
57+
"""
58+
4859
score: float
4960
"""
5061
A score of the likelihood that the query expressed about the text is supported
@@ -54,5 +65,18 @@ class UniversalClassification(BaseModel):
5465
score less than `0.5` indicates that the text does not support the query.
5566
"""
5667

68+
69+
class Usage(BaseModel):
70+
input_tokens: int
71+
"""The number of tokens inputted to the model."""
72+
73+
74+
class UniversalClassification(BaseModel):
75+
classifications: List[Classification]
76+
"""
77+
The classifications of the texts, by relevance to the query, in order from
78+
highest to lowest relevance score.
79+
"""
80+
5781
usage: Usage
5882
"""Statistics about the usage of resources in the process of classifying the text."""

src/isaacus/types/classifications/universal_create_params.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
from typing import Optional
5+
from typing import List, Optional
66
from typing_extensions import Literal, Required, TypedDict
77

88
__all__ = ["UniversalCreateParams", "ChunkingOptions"]
@@ -18,18 +18,18 @@ class UniversalCreateParams(TypedDict, total=False):
1818
query: Required[str]
1919
"""
2020
The [Isaacus Query Language (IQL)](https://docs.isaacus.com/iql) query or, if
21-
IQL is disabled, the statement, to evaluate the text against.
21+
IQL is disabled, the statement, to evaluate the texts against.
2222
2323
The query must contain at least one non-whitespace character.
2424
25-
Unlike the text being classified, the query cannot be so long that it exceeds
25+
Unlike the texts being classified, the query cannot be so long that it exceeds
2626
the maximum input length of the universal classifier.
2727
"""
2828

29-
text: Required[str]
30-
"""The text to classify.
29+
texts: Required[List[str]]
30+
"""The texts to classify.
3131
32-
The text must contain at least one non-whitespace character.
32+
The texts must contain at least one non-whitespace character.
3333
"""
3434

3535
chunking_options: Optional[ChunkingOptions]
@@ -46,13 +46,13 @@ class UniversalCreateParams(TypedDict, total=False):
4646
4747
`auto` is the default scoring method and is recommended for most use cases.
4848
Currently, it is equivalent to `chunk_max`. In the future, it will automatically
49-
select the best method based on the model and input.
49+
select the best method based on the model and inputs.
5050
51-
`chunk_max` uses the highest confidence score of all of the text's chunks.
51+
`chunk_max` uses the highest confidence score of all of the texts' chunks.
5252
53-
`chunk_avg` averages the confidence scores of all of the text's chunks.
53+
`chunk_avg` averages the confidence scores of all of the texts' chunks.
5454
55-
`chunk_min` uses the lowest confidence score of all of the text's chunks.
55+
`chunk_min` uses the lowest confidence score of all of the texts' chunks.
5656
"""
5757

5858

0 commit comments

Comments
 (0)