Skip to content

Commit f5a792d

Browse files
committed
📝 harmonize custom doc sample code
1 parent df8265b commit f5a792d

File tree

3 files changed

+41
-20
lines changed

3 files changed

+41
-20
lines changed

README.md

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,25 @@ print(result.document)
7878
```python
7979
from mindee import Client, product
8080

81-
# Init a new client and add your custom endpoint (document)
81+
# Init a new client
8282
mindee_client = Client(api_key="my-api-key")
83-
custom_endpoint = mindee_client.create_endpoint(
84-
account_name="john",
85-
endpoint_name="wnine",
83+
84+
# Add your custom endpoint (document)
85+
my_endpoint = mindee_client.create_endpoint(
86+
account_name="my-account",
87+
endpoint_name="my-endpoint",
8688
)
8789

8890
# Load a file from disk
8991
input_doc = mindee_client.source_from_path("/path/to/the/file.ext")
9092

9193
# Parse the file.
92-
# The endpoint must be specified since it can't be determined from the class.
93-
result = parse(product.CustomV1, endpoint=custom_endpoint)
94+
# The endpoint must be specified since it cannot be determined from the class.
95+
result = mindee_client.parse(
96+
product.CustomV1,
97+
input_doc,
98+
endpoint=my_endpoint
99+
)
94100

95101
# Print a brief summary of the parsed data
96102
print(result.document)
@@ -109,12 +115,14 @@ Allows sending only certain pages in a PDF.
109115
In this example we only send the first, penultimate and last pages:
110116

111117
```python
112-
api_response = mindee_client.parse(
113-
mindee.product.InvoiceV4,
118+
from mindee import Client, product, PageOptions
119+
120+
result = mindee_client.parse(
121+
product.InvoiceV4,
114122
input_source,
115-
page_options=mindee.PageOptions(
123+
page_options=PageOptions(
116124
page_indexes=[0, -2, -1],
117-
operation: mindee.PageOptions.KEEP_ONLY,
125+
operation=PageOptions.KEEP_ONLY,
118126
on_min_pages=2
119127
)
120128
)

docs/extras/code_samples/custom_v1.txt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,22 @@ from mindee import Client, PredictResponse, product
33
# Init a new client
44
mindee_client = Client(api_key="my-api-key")
55

6-
custom_endpoint = mindee_client.create_endpoint("my-endpoint", "my-account")
6+
# Add your custom endpoint (document)
7+
my_endpoint = mindee_client.create_endpoint(
8+
account_name="my-account",
9+
endpoint_name="my-endpoint",
10+
)
711

812
# Load a file from disk
913
input_doc = mindee_client.source_from_path("/path/to/the/file.ext")
1014

11-
# Load a file from disk and parse it.
12-
# The endpoint name must be specified since it cannot be determined from the class.
13-
result: PredictResponse = mindee_client.parse(product.CustomV1, input_doc, endpoint=custom_endpoint)
15+
# Parse the file.
16+
# The endpoint must be specified since it cannot be determined from the class.
17+
result: PredictResponse = mindee_client.parse(
18+
product.CustomV1,
19+
input_doc,
20+
endpoint=my_endpoint
21+
)
1422

1523
# Print a brief summary of the parsed data
1624
print(result.document)

docs/extras/guide/custom_v1.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@ from mindee import Client, product
1212
# Init a new client
1313
mindee_client = Client(api_key="my-api-key")
1414

15-
# Load a file from disk
16-
input_doc = mindee_client.source_from_path("/path/to/the/file.ext")
15+
# Add your custom endpoint (document)
1716
my_endpoint = mindee_client.create_endpoint(
17+
account_name="my-account",
1818
endpoint_name="my-endpoint",
19-
account_name="my-account-name",
20-
version="my-version",
2119
)
2220

23-
# Parse the document as an invoice by passing the appropriate type
21+
# Load a file from disk
22+
input_doc = mindee_client.source_from_path("/path/to/the/file.ext")
23+
24+
# Parse the file.
25+
# The endpoint must be specified since it cannot be determined from the class.
2426
result = mindee_client.parse(
2527
product.CustomV1,
2628
input_doc,
@@ -29,6 +31,10 @@ result = mindee_client.parse(
2931

3032
# Print a brief summary of the parsed data
3133
print(result.document)
34+
35+
# Iterate over all the fields in the document
36+
for field_name, field_values in result.document.fields.items():
37+
print(field_name, "=", field_values)
3238
```
3339

3440
# Custom Endpoints
@@ -47,7 +53,6 @@ If it is not set, it will default to "1".
4753

4854
A `ListField` is a special type of custom list that implements the following:
4955

50-
5156
* **confidence** (`float`): the confidence score of the field prediction.
5257
* **reconstructed** (`bool`): indicates whether or not an object was reconstructed (not extracted as the API gave it).
5358
* **values** (`List[`[ListFieldValue](#list-field-value)`]`): list of value fields

0 commit comments

Comments
 (0)