99)
1010from ai21 .http_client .async_http_client import AsyncAI21HTTPClient
1111from ai21 .http_client .http_client import AI21HTTPClient
12- from ai21 .models import FileResponse
12+ from ai21 .models import FileResponse , BatchStatusResponse
13+ from ai21 .models .upload_mode import UploadMode
1314from ai21 .types import NOT_GIVEN , NotGiven
1415from ai21 .utils .typing import remove_not_given
1516
@@ -24,6 +25,7 @@ def __init__(self, client: AI21HTTPClient):
2425
2526class LibraryFiles (StudioResource ):
2627 _module_name = "library/files"
28+ _sub_module_name = "library"
2729
2830 def create (
2931 self ,
@@ -32,10 +34,22 @@ def create(
3234 path : Optional [str ] | NotGiven = NOT_GIVEN ,
3335 labels : Optional [List [str ]] | NotGiven = NOT_GIVEN ,
3436 public_url : Optional [str ] | NotGiven = NOT_GIVEN ,
37+ batch_id : Optional [str ] | NotGiven = NOT_GIVEN ,
3538 ** kwargs ,
3639 ) -> str :
3740 files = {"file" : open (file_path , "rb" )}
38- body = remove_not_given ({"path" : path , "labels" : labels , "publicUrl" : public_url , ** kwargs })
41+ body = remove_not_given (
42+ {
43+ "path" : path ,
44+ "labels" : labels ,
45+ "publicUrl" : public_url ,
46+ "batch_id" : batch_id ,
47+ ** kwargs ,
48+ }
49+ )
50+
51+ if body .get ("batch_id" ):
52+ body ["upload_mode" ] = UploadMode .BATCH
3953
4054 raw_response = self ._post (path = f"/{ self ._module_name } " , files = files , body = body , response_cls = dict )
4155
@@ -44,6 +58,9 @@ def create(
4458 def get (self , file_id : str ) -> FileResponse :
4559 return self ._get (path = f"/{ self ._module_name } /{ file_id } " , response_cls = FileResponse )
4660
61+ def get_batch_status (self , batch_id : str ) -> BatchStatusResponse :
62+ return self ._get (path = f"/{ self ._sub_module_name } /batches/{ batch_id } /status" , response_cls = BatchStatusResponse )
63+
4764 def list (
4865 self ,
4966 * ,
@@ -86,6 +103,7 @@ def __init__(self, client: AsyncAI21HTTPClient):
86103
87104class AsyncLibraryFiles (AsyncStudioResource ):
88105 _module_name = "library/files"
106+ _sub_module_name = "library"
89107
90108 async def create (
91109 self ,
@@ -94,10 +112,22 @@ async def create(
94112 path : Optional [str ] | NotGiven = NOT_GIVEN ,
95113 labels : Optional [List [str ]] | NotGiven = NOT_GIVEN ,
96114 public_url : Optional [str ] | NotGiven = NOT_GIVEN ,
115+ batch_id : Optional [str ] | NotGiven = NOT_GIVEN ,
97116 ** kwargs ,
98117 ) -> str :
99118 files = {"file" : open (file_path , "rb" )}
100- body = remove_not_given ({"path" : path , "labels" : labels , "publicUrl" : public_url , ** kwargs })
119+ body = remove_not_given (
120+ {
121+ "path" : path ,
122+ "labels" : labels ,
123+ "publicUrl" : public_url ,
124+ "batch_id" : batch_id ,
125+ ** kwargs ,
126+ }
127+ )
128+
129+ if body .get ("batch_id" ):
130+ body ["upload_mode" ] = UploadMode .BATCH
101131
102132 raw_response = await self ._post (path = f"/{ self ._module_name } " , files = files , body = body , response_cls = dict )
103133
@@ -106,6 +136,11 @@ async def create(
106136 async def get (self , file_id : str ) -> FileResponse :
107137 return await self ._get (path = f"/{ self ._module_name } /{ file_id } " , response_cls = FileResponse )
108138
139+ async def get_batch_status (self , batch_id : str ) -> BatchStatusResponse :
140+ return await self ._get (
141+ path = f"/{ self ._sub_module_name } /batches/{ batch_id } /status" , response_cls = BatchStatusResponse
142+ )
143+
109144 async def list (
110145 self ,
111146 * ,
0 commit comments