-
Notifications
You must be signed in to change notification settings - Fork 5
✨ implement support for V2 API #328
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
Open
sebastianMindee
wants to merge
16
commits into
main
Choose a base branch
from
client-v2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
145f8b4
:sparkles: add support for V2 client
sebastianMindee 9a77744
fix most syntaxes, add tests (integration testing not fully working)
sebastianMindee 440fe3f
fix polling & add tests
sebastianMindee 11cac59
fix python3.8 syntax compatibility
sebastianMindee c64c9ca
add tests & fix miscellaneous naming issues
sebastianMindee d9c9c4b
restore proper coverage
sebastianMindee 8a44f70
it do be coveraging
sebastianMindee f7dc7f2
add even more coverage idk
sebastianMindee c06d20e
remove support for not-yet existing webhooks
sebastianMindee 4376927
[TEMP] enable in-place tests
sebastianMindee c6e9bb5
update PR trigger
sebastianMindee a46e523
move url input sources to where they belong, tweak PR CI
sebastianMindee 42c68d1
use proper local gh targetting syntax
sebastianMindee 4b8b378
fix unused import
sebastianMindee 8869af1
drop support for python 3.7
sebastianMindee 66cd720
bump CI min python versions
sebastianMindee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,6 @@ jobs: | |
- "ubuntu-22.04" | ||
- "windows-2022" | ||
python-version: | ||
- "3.7" | ||
- "3.8" | ||
- "3.9" | ||
- "3.10" | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# | ||
# Install the Python client library by running: | ||
# pip install mindee | ||
# | ||
|
||
from mindee import ClientV2, InferencePredictOptions | ||
from mindee.parsing.v2 import InferenceResponse, PollingResponse | ||
from tests.product import PRODUCT_DATA_DIR | ||
|
||
input_path = "/path/to/the/file.ext" | ||
api_key = "MY_API_KEY" | ||
model_id = "MY_MODEL_ID" | ||
|
||
# Init a new client | ||
mindee_client = ClientV2(api_key) | ||
|
||
# Load a file from disk | ||
input_doc = mindee_client.source_from_path(input_path) | ||
options = InferencePredictOptions(model_id=model_id) | ||
|
||
# Parse the file. | ||
response: InferenceResponse = mindee_client.enqueue_and_parse(input_doc, options) | ||
|
||
# Print a brief summary of the parsed data | ||
print(response.inference) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
from pathlib import Path | ||
from typing import BinaryIO, Union | ||
|
||
from mindee.error import MindeeClientError | ||
from mindee.input import Base64Input, BytesInput, FileInput, PathInput | ||
|
||
|
||
class ClientMixin: | ||
"""Mixin for client Client V1 & V2 common static methods.""" | ||
|
||
@staticmethod | ||
def source_from_path( | ||
input_path: Union[Path, str], fix_pdf: bool = False | ||
) -> PathInput: | ||
""" | ||
Load a document from an absolute path, as a string. | ||
|
||
:param input_path: Path of file to open | ||
:param fix_pdf: Whether to attempt fixing PDF files before sending. | ||
Setting this to `True` can modify the data sent to Mindee. | ||
""" | ||
input_doc = PathInput(input_path) | ||
if fix_pdf: | ||
input_doc.fix_pdf() | ||
return input_doc | ||
|
||
@staticmethod | ||
def source_from_file(input_file: BinaryIO, fix_pdf: bool = False) -> FileInput: | ||
""" | ||
Load a document from a normal Python file object/handle. | ||
|
||
:param input_file: Input file handle | ||
:param fix_pdf: Whether to attempt fixing PDF files before sending. | ||
Setting this to `True` can modify the data sent to Mindee. | ||
""" | ||
input_doc = FileInput(input_file) | ||
if fix_pdf: | ||
input_doc.fix_pdf() | ||
return input_doc | ||
|
||
@staticmethod | ||
def source_from_b64string( | ||
input_string: str, filename: str, fix_pdf: bool = False | ||
) -> Base64Input: | ||
""" | ||
Load a document from a base64 encoded string. | ||
|
||
:param input_string: Input to parse as base64 string | ||
:param filename: The name of the file (without the path) | ||
:param fix_pdf: Whether to attempt fixing PDF files before sending. | ||
Setting this to `True` can modify the data sent to Mindee. | ||
""" | ||
input_doc = Base64Input(input_string, filename) | ||
if fix_pdf: | ||
input_doc.fix_pdf() | ||
return input_doc | ||
|
||
@staticmethod | ||
def source_from_bytes( | ||
input_bytes: bytes, filename: str, fix_pdf: bool = False | ||
) -> BytesInput: | ||
""" | ||
Load a document from raw bytes. | ||
|
||
:param input_bytes: Raw byte input | ||
:param filename: The name of the file (without the path) | ||
:param fix_pdf: Whether to attempt fixing PDF files before sending. | ||
Setting this to `True` can modify the data sent to Mindee. | ||
""" | ||
input_doc = BytesInput(input_bytes, filename) | ||
if fix_pdf: | ||
input_doc.fix_pdf() | ||
return input_doc | ||
|
||
@staticmethod | ||
def _validate_async_params( | ||
initial_delay_sec: float, delay_sec: float, max_retries: int | ||
) -> None: | ||
min_delay = 1 | ||
min_initial_delay = 1 | ||
min_retries = 1 | ||
if delay_sec < min_delay: | ||
raise MindeeClientError( | ||
f"Cannot set auto-parsing delay to less than {min_delay} second(s)." | ||
) | ||
if initial_delay_sec < min_initial_delay: | ||
raise MindeeClientError( | ||
f"Cannot set initial parsing delay to less than {min_initial_delay} second(s)." | ||
) | ||
if max_retries < min_retries: | ||
raise MindeeClientError(f"Cannot set retries to less than {min_retries}.") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.