1
1
# -*- coding: utf-8 -*-
2
2
3
3
"""
4
- firstlanguage
4
+ firstlanguage_python
5
5
6
6
This file was automatically generated by APIMATIC v3.0 (
7
7
https://www.apimatic.io ).
8
8
"""
9
9
10
10
from firstlanguage_python .api_helper import APIHelper
11
11
from firstlanguage_python .configuration import Server
12
- from firstlanguage_python .controllers .base_controller import BaseController
13
- from firstlanguage_python .http .auth .custom_header_auth import CustomHeaderAuth
12
+ from firstlanguage_python .controllers .base_controller import BaseController
14
13
from firstlanguage_python .models .responseclassify import Responseclassify
15
14
from firstlanguage_python .models .api_qa_response import ApiQaResponse
15
+ from firstlanguage_python .models .api_tableqa_response import ApiTableqaResponse
16
16
from firstlanguage_python .models .api_ner_response import ApiNerResponse
17
17
from firstlanguage_python .models .api_summary_response import ApiSummaryResponse
18
18
from firstlanguage_python .models .api_translate_response import ApiTranslateResponse
24
24
25
25
class AdvancedAPIsController (BaseController ):
26
26
27
- """A Controller to access Endpoints in the firstlanguage API."""
28
-
29
- def __init__ (self , config , call_back = None ):
30
- super (AdvancedAPIsController , self ).__init__ (config , call_back )
27
+ """A Controller to access Endpoints in the firstlanguage_python API."""
28
+ def __init__ (self , config , auth_managers , call_back = None ):
29
+ super (AdvancedAPIsController , self ).__init__ (config , auth_managers , call_back )
31
30
32
31
def get_classification (self ,
33
32
body ):
@@ -86,7 +85,9 @@ def get_classification(self,
86
85
87
86
# Prepare and execute request
88
87
_request = self .config .http_client .post (_query_url , headers = _headers , parameters = APIHelper .json_serialize (body ))
89
- CustomHeaderAuth .apply (self .config , _request )
88
+ # Apply authentication scheme on request
89
+ self .apply_auth_schemes (_request , 'global' )
90
+
90
91
_response = self .execute_request (_request )
91
92
92
93
# Endpoint and global error handling using HTTP status codes.
@@ -147,7 +148,9 @@ def get_qa(self,
147
148
148
149
# Prepare and execute request
149
150
_request = self .config .http_client .post (_query_url , headers = _headers , parameters = APIHelper .json_serialize (body ))
150
- CustomHeaderAuth .apply (self .config , _request )
151
+ # Apply authentication scheme on request
152
+ self .apply_auth_schemes (_request , 'global' )
153
+
151
154
_response = self .execute_request (_request )
152
155
153
156
# Endpoint and global error handling using HTTP status codes.
@@ -163,6 +166,91 @@ def get_qa(self,
163
166
164
167
return decoded
165
168
169
+ def get_table_qa (self ,
170
+ body = None ):
171
+ """Does a POST request to /api/tableqa.
172
+
173
+ # TableQA : Defintion and it's usage
174
+ Table QA uses TAPAS based model to get answers from table input. The
175
+ table can be parsed into a JSON object or it can be a link to a CSV
176
+ file. Currently only Plain CSV file is supported.
177
+ This API works only for English language currently
178
+ Example for flattend table in JSON Format:<br/>
179
+ {"Cities": ["Paris, France", "London, England", "Lyon, France"],
180
+ "Inhabitants": ["2.161", "8.982", "0.513"]}
181
+ The API can return the original table rows from which the answer was
182
+ extracted based on the flag 'sendBackRows'
183
+
184
+ Args:
185
+ body (object, optional): Add a JSON Input as per the schema
186
+ defined below. For URL input, if you are providing Google
187
+ drive or Google Spreadsheet url ensure that you provide a link
188
+ which can download the file directly and not the share link.
189
+ Example: For Google Spreadsheet, the url format will be like
190
+ below:
191
+ https://docs.google.com/spreadsheets/d/1TtzPAHqpaTB7Ltdq0zwZ8Fa
192
+ mF7O9aC4KH4EpmwI/export?format=csv&gid=151344200 Or for
193
+ Google Drive, it will be like below:
194
+ https://drive.google.com/uc?id=idofthefile For Flat table
195
+ input check the example out.
196
+
197
+ Returns:
198
+ list of ApiTableqaResponse: Response from the API. Answers for the
199
+ questions posted along with the original rows if the flag is
200
+ true.
201
+
202
+ The anwer will be of format:
203
+
204
+ AGGREGRATE >
205
+ answer
206
+
207
+ Aggregrate can be one of the
208
+ following:
209
+ NONE,
210
+ SUM,
211
+ COUNT,
212
+ AVERAGE
213
+
214
+ Raises:
215
+ APIException: When an error occurs while fetching the data from
216
+ the remote API. This exception includes the HTTP Response
217
+ code, an error message, and the HTTP body that was received in
218
+ the request.
219
+
220
+ """
221
+
222
+ # Prepare query URL
223
+ _url_path = '/api/tableqa'
224
+ _query_builder = self .config .get_base_uri ()
225
+ _query_builder += _url_path
226
+ _query_url = APIHelper .clean_url (_query_builder )
227
+
228
+ # Prepare headers
229
+ _headers = {
230
+ 'accept' : 'application/json' ,
231
+ 'Content-Type' : 'application/json'
232
+ }
233
+
234
+ # Prepare and execute request
235
+ _request = self .config .http_client .post (_query_url , headers = _headers , parameters = APIHelper .json_serialize (body ))
236
+ # Apply authentication scheme on request
237
+ self .apply_auth_schemes (_request , 'global' )
238
+
239
+ _response = self .execute_request (_request )
240
+
241
+ # Endpoint and global error handling using HTTP status codes.
242
+ if _response .status_code == 400 :
243
+ raise ErrorsException ('Bad Request' , _response )
244
+ elif _response .status_code == 426 :
245
+ raise M426ErrorException ('Please use HTTPS protocol' , _response )
246
+ elif _response .status_code == 429 :
247
+ raise APIException ('Too Many Requests' , _response )
248
+ self .validate_response (_response )
249
+
250
+ decoded = APIHelper .json_deserialize (_response .text , ApiTableqaResponse .from_dictionary )
251
+
252
+ return decoded
253
+
166
254
def get_ner (self ,
167
255
body = None ):
168
256
"""Does a POST request to /api/ner.
@@ -221,7 +309,9 @@ def get_ner(self,
221
309
222
310
# Prepare and execute request
223
311
_request = self .config .http_client .post (_query_url , headers = _headers , parameters = APIHelper .json_serialize (body ))
224
- CustomHeaderAuth .apply (self .config , _request )
312
+ # Apply authentication scheme on request
313
+ self .apply_auth_schemes (_request , 'global' )
314
+
225
315
_response = self .execute_request (_request )
226
316
227
317
# Endpoint and global error handling using HTTP status codes.
@@ -319,7 +409,9 @@ def get_summary(self,
319
409
320
410
# Prepare and execute request
321
411
_request = self .config .http_client .post (_query_url , headers = _headers , parameters = APIHelper .json_serialize (body ))
322
- CustomHeaderAuth .apply (self .config , _request )
412
+ # Apply authentication scheme on request
413
+ self .apply_auth_schemes (_request , 'global' )
414
+
323
415
_response = self .execute_request (_request )
324
416
325
417
# Endpoint and global error handling using HTTP status codes.
@@ -432,7 +524,9 @@ def get_translate(self,
432
524
433
525
# Prepare and execute request
434
526
_request = self .config .http_client .post (_query_url , headers = _headers , parameters = APIHelper .json_serialize (body ))
435
- CustomHeaderAuth .apply (self .config , _request )
527
+ # Apply authentication scheme on request
528
+ self .apply_auth_schemes (_request , 'global' )
529
+
436
530
_response = self .execute_request (_request )
437
531
438
532
# Endpoint and global error handling using HTTP status codes.
0 commit comments