33from .request import Request , RequestConfig
44from .async_request import AsyncRequest , AsyncRequestConfig
55from ._config import ClientConfig
6+ from ._types import BaseResponse
67
78
8- class DatasetItemText (TypedDict ):
9- type : Literal ["text" ]
9+ class DatasetItem (TypedDict ):
10+ type : Literal ["text" , "image" ]
1011 """
1112 Type of the dataset item: text
1213 """
13-
14- value : str
15- """
16- Value of the dataset item
17- """
18-
1914
20- class DatasetItemImage (TypedDict ):
21- type : Literal ["image" ]
22- """
23- Type of the dataset item: image
24- """
25-
2615 value : str
2716 """
2817 Value of the dataset item
2918 """
3019
3120
32- class LabelItemText (TypedDict ):
21+ class LabelItem (TypedDict ):
3322 key : NotRequired [str ]
3423 """
3524 Optional key for the label
3625 """
37-
38- type : Literal ["text" ]
26+
27+ type : Literal ["text" , "image" ]
3928 """
4029 Type of the label: text
4130 """
42-
43- value : str
44- """
45- Value of the label
46- """
4731
48-
49- class LabelItemImage (TypedDict ):
50- key : NotRequired [str ]
51- """
52- Optional key for the label
53- """
54-
55- type : Literal ["image" , "text" ]
56- """
57- Type of the label: image or text
58- """
59-
6032 value : str
6133 """
6234 Value of the label
6335 """
6436
6537
66- class ClassificationTextParams (TypedDict ):
67- dataset : List [DatasetItemText ]
38+ class ClassificationParams (TypedDict ):
39+ dataset : List [DatasetItem ]
6840 """
6941 List of text dataset items to classify
7042 """
71-
72- labels : List [LabelItemText ]
43+
44+ labels : List [LabelItem ]
7345 """
7446 List of text labels for classification
7547 """
76-
77- multiple_labels : NotRequired [bool ]
78- """
79- Whether to allow multiple labels per item
80- """
8148
82-
83- class ClassificationImageParams (TypedDict ):
84- dataset : List [DatasetItemImage ]
85- """
86- List of image dataset items to classify
87- """
88-
89- labels : List [LabelItemImage ]
90- """
91- List of labels for classification
92- """
93-
9449 multiple_labels : NotRequired [bool ]
9550 """
9651 Whether to allow multiple labels per item
9752 """
9853
9954
100- class ClassificationResponse (TypedDict ):
55+ class ClassificationResponse (BaseResponse ):
10156 predictions : List [Union [str , List [str ]]]
10257 """
10358 Classification predictions - single labels or multiple labels per item
10459 """
10560
10661
107-
10862class Classification (ClientConfig ):
109-
11063 config : RequestConfig
11164
11265 def __init__ (
@@ -122,16 +75,7 @@ def __init__(
12275 disable_request_logging = disable_request_logging ,
12376 )
12477
125- def text (self , params : ClassificationTextParams ) -> ClassificationResponse :
126- path = "/classification"
127- resp = Request (
128- config = self .config ,
129- path = path ,
130- params = cast (Dict [Any , Any ], params ),
131- verb = "post" ,
132- ).perform_with_content ()
133- return resp
134- def image (self , params : ClassificationImageParams ) -> ClassificationResponse :
78+ def classify (self , params : ClassificationParams ) -> ClassificationResponse :
13579 path = "/classification"
13680 resp = Request (
13781 config = self .config ,
@@ -142,7 +86,6 @@ def image(self, params: ClassificationImageParams) -> ClassificationResponse:
14286 return resp
14387
14488
145-
14689class AsyncClassification (ClientConfig ):
14790 config : AsyncRequestConfig
14891
@@ -159,7 +102,7 @@ def __init__(
159102 disable_request_logging = disable_request_logging ,
160103 )
161104
162- async def text (self , params : ClassificationTextParams ) -> ClassificationResponse :
105+ async def classify (self , params : ClassificationParams ) -> ClassificationResponse :
163106 path = "/classification"
164107 resp = await AsyncRequest (
165108 config = self .config ,
@@ -168,13 +111,3 @@ async def text(self, params: ClassificationTextParams) -> ClassificationResponse
168111 verb = "post" ,
169112 ).perform_with_content ()
170113 return resp
171-
172- async def image (self , params : ClassificationImageParams ) -> ClassificationResponse :
173- path = "/classification"
174- resp = await AsyncRequest (
175- config = self .config ,
176- path = path ,
177- params = cast (Dict [Any , Any ], params ),
178- verb = "post" ,
179- ).perform_with_content ()
180- return resp
0 commit comments