11import asyncio
22import json
3+ from collections .abc import Iterable
34from functools import wraps
45
56import httpx
@@ -46,6 +47,7 @@ async def submit_task(
4647 model_name : str = None ,
4748 task : str = None ,
4849 data = None ,
50+ json = None ,
4951 files = None ,
5052 params = None ,
5153 headers = None ,
@@ -57,7 +59,9 @@ async def submit_task(
5759 if not model_name :
5860 raise ValueError ("Please provide a model name or set a default model for the client." )
5961 url = f"{ self .base_url } /models/{ model_name } /tasks/{ task } "
60- resp = await self ._client .post (url , data = data , files = files , params = params , headers = headers )
62+ resp = await self ._client .post (
63+ url , data = data , json = json , files = files , params = params , headers = headers
64+ )
6165 resp .raise_for_status ()
6266 task_info = resp .json ()
6367 if wait_for_completion :
@@ -84,18 +88,51 @@ async def process(
8488 return_result = return_result ,
8589 )
8690
91+ async def process_bulk (
92+ self ,
93+ texts : list [str ],
94+ model_name : str = None ,
95+ wait_for_completion : bool = True ,
96+ return_result : bool = True ,
97+ ):
98+ """Generate annotations for a list of texts."""
99+ return await self .submit_task (
100+ model_name = model_name ,
101+ task = "process_bulk" ,
102+ json = texts ,
103+ headers = {"Content-Type" : "application/json" },
104+ wait_for_completion = wait_for_completion ,
105+ return_result = return_result ,
106+ )
107+
87108 async def redact (
88109 self ,
89110 text : str ,
111+ concepts_to_keep : Iterable [str ] = None ,
112+ warn_on_no_redaction : bool = None ,
113+ mask : str = None ,
114+ hash : bool = None ,
90115 model_name : str = None ,
91116 wait_for_completion : bool = True ,
92117 return_result : bool = True ,
93118 ):
94119 """Redact sensitive information from the provided text."""
120+ params = {
121+ k : v
122+ for k , v in {
123+ "concepts_to_keep" : concepts_to_keep ,
124+ "warn_on_no_redaction" : warn_on_no_redaction ,
125+ "mask" : mask ,
126+ "hash" : hash ,
127+ }.items ()
128+ if v is not None
129+ } or None
130+
95131 return await self .submit_task (
96132 model_name = model_name ,
97133 task = "redact" ,
98134 data = text ,
135+ params = params ,
99136 headers = {"Content-Type" : "text/plain" },
100137 wait_for_completion = wait_for_completion ,
101138 return_result = return_result ,
@@ -225,6 +262,9 @@ def submit_task(self, *args, **kwargs):
225262 def process (self , * args , ** kwargs ):
226263 return self ._loop .run_until_complete (self ._client .process (* args , ** kwargs ))
227264
265+ def process_bulk (self , * args , ** kwargs ):
266+ return self ._loop .run_until_complete (self ._client .process_bulk (* args , ** kwargs ))
267+
228268 def redact (self , * args , ** kwargs ):
229269 return self ._loop .run_until_complete (self ._client .redact (* args , ** kwargs ))
230270
0 commit comments