Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update information extract api #11

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions open_parser/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
)
Expand Down Expand Up @@ -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
Expand Down
Loading