From f5a792d7d2c3695528d3cc745b34ea91773d1a0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ianar=C3=A9=20S=C3=A9vi?= Date: Wed, 22 Nov 2023 16:46:50 +0100 Subject: [PATCH] :memo: harmonize custom doc sample code --- README.md | 28 +++++++++++++++++--------- docs/extras/code_samples/custom_v1.txt | 16 +++++++++++---- docs/extras/guide/custom_v1.md | 17 ++++++++++------ 3 files changed, 41 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index a040dad9..e0339d45 100644 --- a/README.md +++ b/README.md @@ -78,19 +78,25 @@ print(result.document) ```python from mindee import Client, product -# Init a new client and add your custom endpoint (document) +# Init a new client mindee_client = Client(api_key="my-api-key") -custom_endpoint = mindee_client.create_endpoint( - account_name="john", - endpoint_name="wnine", + +# Add your custom endpoint (document) +my_endpoint = mindee_client.create_endpoint( + account_name="my-account", + endpoint_name="my-endpoint", ) # Load a file from disk input_doc = mindee_client.source_from_path("/path/to/the/file.ext") # Parse the file. -# The endpoint must be specified since it can't be determined from the class. -result = parse(product.CustomV1, endpoint=custom_endpoint) +# The endpoint must be specified since it cannot be determined from the class. +result = mindee_client.parse( + product.CustomV1, + input_doc, + endpoint=my_endpoint +) # Print a brief summary of the parsed data print(result.document) @@ -109,12 +115,14 @@ Allows sending only certain pages in a PDF. In this example we only send the first, penultimate and last pages: ```python -api_response = mindee_client.parse( - mindee.product.InvoiceV4, +from mindee import Client, product, PageOptions + +result = mindee_client.parse( + product.InvoiceV4, input_source, - page_options=mindee.PageOptions( + page_options=PageOptions( page_indexes=[0, -2, -1], - operation: mindee.PageOptions.KEEP_ONLY, + operation=PageOptions.KEEP_ONLY, on_min_pages=2 ) ) diff --git a/docs/extras/code_samples/custom_v1.txt b/docs/extras/code_samples/custom_v1.txt index 9bae87c1..82abd496 100644 --- a/docs/extras/code_samples/custom_v1.txt +++ b/docs/extras/code_samples/custom_v1.txt @@ -3,14 +3,22 @@ from mindee import Client, PredictResponse, product # Init a new client mindee_client = Client(api_key="my-api-key") -custom_endpoint = mindee_client.create_endpoint("my-endpoint", "my-account") +# Add your custom endpoint (document) +my_endpoint = mindee_client.create_endpoint( + account_name="my-account", + endpoint_name="my-endpoint", +) # Load a file from disk input_doc = mindee_client.source_from_path("/path/to/the/file.ext") -# Load a file from disk and parse it. -# The endpoint name must be specified since it cannot be determined from the class. -result: PredictResponse = mindee_client.parse(product.CustomV1, input_doc, endpoint=custom_endpoint) +# Parse the file. +# The endpoint must be specified since it cannot be determined from the class. +result: PredictResponse = mindee_client.parse( + product.CustomV1, + input_doc, + endpoint=my_endpoint +) # Print a brief summary of the parsed data print(result.document) diff --git a/docs/extras/guide/custom_v1.md b/docs/extras/guide/custom_v1.md index f388ddf7..83c289c5 100644 --- a/docs/extras/guide/custom_v1.md +++ b/docs/extras/guide/custom_v1.md @@ -12,15 +12,17 @@ from mindee import Client, product # Init a new client mindee_client = Client(api_key="my-api-key") -# Load a file from disk -input_doc = mindee_client.source_from_path("/path/to/the/file.ext") +# Add your custom endpoint (document) my_endpoint = mindee_client.create_endpoint( + account_name="my-account", endpoint_name="my-endpoint", - account_name="my-account-name", - version="my-version", ) -# Parse the document as an invoice by passing the appropriate type +# Load a file from disk +input_doc = mindee_client.source_from_path("/path/to/the/file.ext") + +# Parse the file. +# The endpoint must be specified since it cannot be determined from the class. result = mindee_client.parse( product.CustomV1, input_doc, @@ -29,6 +31,10 @@ result = mindee_client.parse( # Print a brief summary of the parsed data print(result.document) + +# Iterate over all the fields in the document +for field_name, field_values in result.document.fields.items(): + print(field_name, "=", field_values) ``` # Custom Endpoints @@ -47,7 +53,6 @@ If it is not set, it will default to "1". A `ListField` is a special type of custom list that implements the following: - * **confidence** (`float`): the confidence score of the field prediction. * **reconstructed** (`bool`): indicates whether or not an object was reconstructed (not extracted as the API gave it). * **values** (`List[`[ListFieldValue](#list-field-value)`]`): list of value fields