From 082a3ffeaea7daf546957e050a8709db3a1df486 Mon Sep 17 00:00:00 2001 From: SeisSerenata Date: Wed, 10 Apr 2024 15:48:46 +0000 Subject: [PATCH] fix: update information extract api --- open_parser/base.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/open_parser/base.py b/open_parser/base.py index f91e334..01e2b94 100644 --- a/open_parser/base.py +++ b/open_parser/base.py @@ -29,8 +29,8 @@ def extract(self, file_path): return result["file_content"] def parse(self, file_path, prompt, mode="advanced"): - user_id, job_id, s3_key = self._request_and_upload_by_apiKey(file_path, prompt) - result = self._request_info_extraction(user_id, job_id, s3_key, mode) + user_id, job_id, s3_key = self._request_and_upload_by_apiKey(file_path) + result = self._request_info_extraction(user_id, job_id, s3_key, mode, prompt) return result["results"] def _error_handler(self, response): @@ -41,8 +41,8 @@ def _error_handler(self, response): else: raise Exception(f"Error: {response.status_code} {response.text}") - def _request_and_upload_by_apiKey(self, file_path, prompt=""): - params = {"fileName": file_path, "prompt": prompt} + def _request_and_upload_by_apiKey(self, file_path): + params = {"fileName": file_path} response = requests.get( self._uploadurl, headers=self._request_header, params=params ) @@ -77,14 +77,15 @@ def _request_file_extraction(self, user_id, job_id, s3_key): self._error_handler(response) - def _request_info_extraction(self, user_id, job_id, s3_key, mode): + def _request_info_extraction(self, user_id, job_id, s3_key, mode, prompt=""): if mode not in ["advanced", "basic"]: raise ValueError("Invalid mode. Choose either 'advanced' or 'basic'.") payload = { "userId": user_id, "jobId": job_id, "fileKey": s3_key, - "extract": True if mode == "advanced" else False, + "user_prompt": prompt, + "use_textract": True if mode == "advanced" else False, } response = requests.post( self._parseurl, headers=self._request_header, json=payload