-
Notifications
You must be signed in to change notification settings - Fork 6
Invoice splitter update #130
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
Merged
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
9fc4717
base layout for functions, doesn't work yet
sebastianMindee fc2a1a1
added all basic needed support for async (untested)
sebastianMindee ef8fb56
fixed queue polling functions
sebastianMindee 9768787
revamped inheritance and fixed AsyncPredictionResponse generation
sebastianMindee 4ff8bfc
fixed polling for jobs, document access not working yet
sebastianMindee 518d732
added some safety checks
sebastianMindee bc2b816
Fixes for draft PR
sebastianMindee e49c259
added test & fixed InvoiceSplitterV1 class
sebastianMindee 61a0d1f
InvoiceSplitterV1 class cleanup
sebastianMindee 8c5579c
Clarified DocString & added documentation support
sebastianMindee e969c28
Clarified DocString & added documentation support
sebastianMindee a9c21f4
Added unit testint for Async & fixed some obsolete AsyncPrediction no…
sebastianMindee 2daaf18
renamed async unittest file to avoid confusion
sebastianMindee 09ac89c
put api tests together
ianardee 80df96e
rework a bit the structure
ianardee 7920f6b
add empty files for docs
ianardee 8aaf753
added doc support for async, refactored AsyncPredict class to fit wit…
sebastianMindee 0fa7c37
tweaked import for retrocompatibility
sebastianMindee 9c8c361
retrocompatibility tweak
sebastianMindee fbe2e45
further tweaking
sebastianMindee c37e8ec
fixed typo
sebastianMindee 0d7347a
fixed typo... again...
sebastianMindee 497d647
fixed txt test, again.
sebastianMindee f579852
fixed code sample for invoicesplitter
sebastianMindee 2b46983
fixed typing in invoicesplitter
sebastianMindee 5e38352
revamped sample code
sebastianMindee d9b6ffb
Update docs/extras/code_samples/invoice_splitter_v1_async.txt
sebastianMindee 8119184
Update docs/extras/code_samples/invoice_splitter_v1_async.txt
sebastianMindee fc4c6aa
fixed code sample & added comments
sebastianMindee 8c92a7a
removed needless import
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| from mindee import Client, documents | ||
| from time import sleep | ||
|
|
||
| # Init a new client | ||
| mindee_client = Client(api_key="my-api-key") | ||
|
|
||
| # Load a file from disk | ||
| input_doc = mindee_client.doc_from_path("/path/to/the/file.ext") | ||
|
|
||
| # Put the document class in a local variable to keep the code DRY | ||
|
|
||
| doc_class = documents.TypeInvoiceSplitterV1 | ||
|
|
||
| # Limit the amount of API calls to retrieve your document | ||
| MAX_RETRIES = 10 | ||
|
|
||
| # How many seconds to wait in-between tries | ||
| INTERVAL_SECS = 6 | ||
|
|
||
| # Counter to keep track of how many times we try to retrieve the document | ||
| times_tried = 1 | ||
|
|
||
|
|
||
| queue_result = input_doc.enqueue(doc_class) | ||
|
|
||
| # Get the id of the queue (job) | ||
| queue_id = queue_result.job.job_id | ||
|
|
||
| # Recursive function that tries to retrieve the completed document. | ||
| # If the document is not "complete", try again | ||
| def get_doc_from_async_queue(queue_id, times_tried=0): | ||
|
|
||
| # Have we exceeded our retry count? | ||
| if times_tried >= MAX_RETRIES: | ||
| raise Exception(f"Maximum retries reached {times_tried}") | ||
|
|
||
| # Wait for a few seconds before fetching | ||
| sleep(INTERVAL_SECS) | ||
|
|
||
| # Fetch and parse the result, using the same type | ||
| parsed_result = input_doc.parse_queued(doc_class, queue_id) | ||
|
|
||
| # Check whether the result is ready | ||
| if parsed_result.job.status == "completed": | ||
|
|
||
| # Print a brief summary of the parsed data | ||
| print(parsed_result.document.document) | ||
| return | ||
|
|
||
| # Otherwise, try again... | ||
| else: | ||
| get_doc_from_async_queue(queue_id, times_tried+1) | ||
|
|
||
| # Start the recursion... | ||
| get_doc_from_async_queue(queue_id) | ||
10 changes: 10 additions & 0 deletions
10
docs/predictions/standard/documents/invoice_splitter_v1.rst
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,10 @@ | ||
| Invoice Splitter V1 | ||
| ------------------- | ||
|
|
||
| **Sample Code:** | ||
|
|
||
| .. literalinclude:: /extras/code_samples/invoice_splitter_v1_async.txt | ||
| :language: Python | ||
|
|
||
| .. autoclass:: mindee.documents.InvoiceSplitterV1 | ||
| :members: |
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 |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| from mindee.client import Client, PageOptions | ||
| from mindee.response import PredictResponse | ||
| from mindee.response import AsyncPredictResponse, Job, PredictResponse |
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 |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from .invoice_splitter_v1 import InvoiceSplitterV1, TypeInvoiceSplitterV1 |
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.