99from mindee .input .sources import LocalInputSource , UrlInputSource
1010from mindee .parsing .common .async_predict_response import AsyncPredictResponse
1111from mindee .parsing .common .document import Document , serialize_for_json
12- from mindee .parsing .common .feedback_response import FeedbackResponse
1312from mindee .parsing .common .inference import Inference
1413from mindee .parsing .common .predict_response import PredictResponse
15- from mindee .parsing .common .string_dict import StringDict
1614
1715
1816class MindeeArgumentParser (ArgumentParser ):
@@ -75,19 +73,6 @@ def add_sending_options(self) -> None:
7573 )
7674 self .add_argument (dest = "path" , help = "Full path to the file" )
7775
78- def add_feedback_options (self ) -> None :
79- """Adds the option to give feedback manually."""
80- self .add_argument (
81- dest = "document_id" ,
82- help = "Mindee UUID of the document." ,
83- type = str ,
84- )
85- self .add_argument (
86- dest = "feedback" ,
87- type = json .loads ,
88- help = 'Feedback JSON string to send, ex \' {"key": "value"}\' .' ,
89- )
90-
9176 def add_custom_options (self ) -> None :
9277 """Adds options to custom-type documents."""
9378 self .add_argument (
@@ -128,8 +113,6 @@ class MindeeParser:
128113 """Document to be parsed."""
129114 product_class : Type [Inference ]
130115 """Product to parse."""
131- feedback : Optional [StringDict ]
132- """Dict representation of a feedback."""
133116
134117 def __init__ (
135118 self ,
@@ -147,38 +130,11 @@ def __init__(
147130 else :
148131 api_key = self .parsed_args .api_key if "api_key" in self .parsed_args else ""
149132 self .client = Client (api_key = api_key )
150- self ._set_input ()
133+ self .input_doc = self . _get_input_doc ()
151134 self .document_info = (
152135 document_info if document_info else PRODUCTS [self .parsed_args .product_name ]
153136 )
154137
155- def call_endpoint (self ) -> None :
156- """Calls the proper type of endpoint according to given command."""
157- if self .parsed_args .parse_type == "parse" :
158- self .call_parse ()
159- else :
160- self .call_feedback ()
161-
162- def call_feedback (self ) -> None :
163- """Sends feedback to an API."""
164- custom_endpoint : Optional [Endpoint ] = None
165- if self .parsed_args .product_name in ("custom" , "generated" ):
166- custom_endpoint = self .client .create_endpoint (
167- self .parsed_args .endpoint_name ,
168- self .parsed_args .account_name ,
169- self .parsed_args .api_version ,
170- )
171- if self .feedback is None :
172- raise MindeeClientError ("Invalid feedback provided." )
173-
174- response : FeedbackResponse = self .client .send_feedback (
175- self .document_info .doc_class ,
176- self .parsed_args .document_id ,
177- {"feedback" : self .feedback },
178- custom_endpoint ,
179- )
180- print (json .dumps (response .feedback , indent = 2 ))
181-
182138 def call_parse (self ) -> None :
183139 """Calls an endpoint with the appropriate method, and displays the results."""
184140 response : Union [PredictResponse , AsyncPredictResponse ]
@@ -277,19 +233,13 @@ def _set_args(self) -> Namespace:
277233 for name , info in PRODUCTS .items ():
278234 parse_subparser = parse_product_subparsers .add_parser (name , help = info .help )
279235
280- call_parser = parse_subparser .add_subparsers (
281- dest = "parse_type" , required = True
282- )
283- parse_subp = call_parser .add_parser ("parse" )
284- feedback_subp = call_parser .add_parser ("feedback" )
285-
286- parse_subp .add_main_options ()
287- parse_subp .add_sending_options ()
288- parse_subp .add_display_options ()
236+ parse_subparser .add_main_options ()
237+ parse_subparser .add_sending_options ()
238+ parse_subparser .add_display_options ()
289239 if name in ("custom" , "generated" ):
290- parse_subp .add_custom_options ()
240+ parse_subparser .add_custom_options ()
291241 else :
292- parse_subp .add_argument (
242+ parse_subparser .add_argument (
293243 "-t" ,
294244 "--full-text" ,
295245 dest = "include_words" ,
@@ -298,7 +248,7 @@ def _set_args(self) -> Namespace:
298248 )
299249
300250 if info .is_async and info .is_sync :
301- parse_subp .add_argument (
251+ parse_subparser .add_argument (
302252 "-A" ,
303253 "--asynchronous" ,
304254 dest = "async_parse" ,
@@ -308,9 +258,6 @@ def _set_args(self) -> Namespace:
308258 default = False ,
309259 )
310260
311- feedback_subp .add_main_options ()
312- feedback_subp .add_feedback_options ()
313-
314261 parsed_args = self .parser .parse_args ()
315262 return parsed_args
316263
@@ -332,36 +279,3 @@ def _get_input_doc(self) -> Union[LocalInputSource, UrlInputSource]:
332279 elif self .parsed_args .input_type == "url" :
333280 return self .client .source_from_url (self .parsed_args .path )
334281 return self .client .source_from_path (self .parsed_args .path )
335-
336- def _get_feedback_doc (self ) -> StringDict :
337- """Loads a feedback."""
338- json_doc : StringDict = {}
339- if self .parsed_args .input_type == "file" :
340- with open (self .parsed_args .path , "rb" , buffering = 30 ) as f_f :
341- json_doc = json .loads (f_f .read ())
342- elif self .parsed_args .input_type == "base64" :
343- with open (self .parsed_args .path , "rt" , encoding = "ascii" ) as f_b64 :
344- json_doc = json .loads (f_b64 .read ())
345- elif self .parsed_args .input_type == "bytes" :
346- with open (self .parsed_args .path , "rb" ) as f_b :
347- json_doc = json .loads (f_b .read ())
348- else :
349- if (
350- not self .parsed_args .feedback
351- or "feedback" not in self .parsed_args .feedback
352- ):
353- raise MindeeClientError ("Invalid feedback." )
354- if not json_doc or "feedback" not in json_doc :
355- raise MindeeClientError ("Invalid feedback." )
356- return json_doc
357-
358- def _set_input (self ) -> None :
359- """Loads an input document, or a feedback document."""
360- self .feedback = None
361- if self .parsed_args .parse_type == "feedback" :
362- if not self .parsed_args .feedback :
363- self .feedback = self ._get_feedback_doc ()
364- else :
365- self .feedback = self .parsed_args .feedback
366- else :
367- self .input_doc = self ._get_input_doc ()
0 commit comments