Skip to content
Merged
Show file tree
Hide file tree
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
17 changes: 15 additions & 2 deletions .github/workflows/_test-code-samples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ on:
workflow_call:
workflow_dispatch:

env:
MINDEE_API_KEY: ${{ secrets.MINDEE_API_KEY_SE_TESTS }}
MINDEE_V2_API_KEY: ${{ secrets.MINDEE_V2_SE_TESTS_API_KEY }}
MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID }}
MINDEE_V2_SE_TESTS_CLASSIFICATION_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_CLASSIFICATION_MODEL_ID }}
MINDEE_V2_SE_TESTS_CROP_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_CROP_MODEL_ID }}
MINDEE_V2_SE_TESTS_SPLIT_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_SPLIT_MODEL_ID }}
MINDEE_V2_SE_TESTS_OCR_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_OCR_MODEL_ID }}

jobs:
test:
name: Run Code Samples
Expand Down Expand Up @@ -38,9 +47,13 @@ jobs:
python -m pip install pip
pip install -e .

- name: Tests code samples
- name: Tests v2 sample code
run: |
./tests/test_v2_code_samples.sh

- name: Tests v1 sample code
run: |
./tests/test_code_samples.sh ${{ secrets.MINDEE_ACCOUNT_SE_TESTS }} ${{ secrets.MINDEE_ENDPOINT_SE_TESTS }} ${{ secrets.MINDEE_API_KEY_SE_TESTS }} ${{ secrets.MINDEE_V2_SE_TESTS_API_KEY }} ${{ secrets.MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID }} ${{ secrets.MINDEE_V2_SE_TESTS_CLASSIFICATION_MODEL_ID }} ${{ secrets.MINDEE_V2_SE_TESTS_CROP_MODEL_ID }} ${{ secrets.MINDEE_V2_SE_TESTS_OCR_MODEL_ID }} ${{ secrets.MINDEE_V2_SE_TESTS_SPLIT_MODEL_ID }}
./tests/test_v1_code_samples.sh ${{ secrets.MINDEE_ACCOUNT_SE_TESTS }} ${{ secrets.MINDEE_ENDPOINT_SE_TESTS }}

- name: Notify Slack Action on Failure
uses: ravsamhq/notify-slack-action@2.3.0
Expand Down
2 changes: 1 addition & 1 deletion docs/extras/code_samples/v2_classification.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ from mindee import (

input_path = "/path/to/the/file.ext"
api_key = "MY_API_KEY"
model_id = "MY_CLASSIFICATION_MODEL_ID"
model_id = "MY_MODEL_ID"

# Init a new client
mindee_client = ClientV2(api_key)
Expand Down
2 changes: 1 addition & 1 deletion docs/extras/code_samples/v2_crop.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ from mindee import (

input_path = "/path/to/the/file.ext"
api_key = "MY_API_KEY"
model_id = "MY_CROP_MODEL_ID"
model_id = "MY_MODEL_ID"

# Init a new client
mindee_client = ClientV2(api_key)
Expand Down
3 changes: 3 additions & 0 deletions docs/extras/code_samples/v2_extraction.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ response = mindee_client.enqueue_and_get_result(

# Print a brief summary of the parsed data
print(response.inference)

# Access the result fields
fields: dict = response.inference.result.fields
4 changes: 2 additions & 2 deletions docs/extras/code_samples/v2_ocr.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ from mindee import (

input_path = "/path/to/the/file.ext"
api_key = "MY_API_KEY"
model_id = "MY_OCR_MODEL_ID"
model_id = "MY_MODEL_ID"

# Init a new client
mindee_client = ClientV2(api_key)
Expand All @@ -31,5 +31,5 @@ response = mindee_client.enqueue_and_get_result(
# Print a brief summary of the parsed data
print(response.inference)

# Access the ocr result
# Access the OCR result
pages: list = response.inference.result.pages
2 changes: 1 addition & 1 deletion docs/extras/code_samples/v2_split.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ from mindee import (

input_path = "/path/to/the/file.ext"
api_key = "MY_API_KEY"
model_id = "MY_SPLIT_MODEL_ID"
model_id = "MY_MODEL_ID"

# Init a new client
mindee_client = ClientV2(api_key)
Expand Down
6 changes: 3 additions & 3 deletions mindee/input/base_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
class BaseParameters(ABC):
"""Base class for parameters accepted by all V2 endpoints."""

_slug: str = field(init=False)
"""Slug of the endpoint."""

model_id: str
"""ID of the model, required."""
alias: Optional[str] = None
Expand All @@ -23,6 +20,9 @@ class BaseParameters(ABC):
close_file: bool = True
"""Whether to close the file after product."""

_slug: str = field(init=False)
"""Slug of the endpoint."""

def get_form_data(self) -> Dict[str, Union[str, List[str]]]:
"""
Return the parameters as a config dictionary.
Expand Down
8 changes: 4 additions & 4 deletions mindee/input/inference_parameters.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from dataclasses import dataclass, asdict, field
from dataclasses import dataclass, asdict
from typing import Dict, List, Optional, Union

from mindee.input.base_parameters import BaseParameters
Expand Down Expand Up @@ -81,9 +81,6 @@ def __post_init__(self) -> None:
class InferenceParameters(BaseParameters):
"""Inference parameters to set when sending a file."""

_slug: str = field(init=False, default="inferences")
"""Slug of the endpoint."""

rag: Optional[bool] = None
"""Enhance extraction accuracy with Retrieval-Augmented Generation."""
raw_text: Optional[bool] = None
Expand All @@ -106,6 +103,9 @@ class InferenceParameters(BaseParameters):
Not recommended, for specific use only.
"""

_slug: str = "inferences"
"""Slug of the endpoint."""

def __post_init__(self):
if isinstance(self.data_schema, str):
self.data_schema = DataSchema(**json.loads(self.data_schema))
Expand Down
96 changes: 0 additions & 96 deletions tests/test_code_samples.sh

This file was deleted.

51 changes: 51 additions & 0 deletions tests/test_v1_code_samples.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#! /bin/sh
set -e

OUTPUT_FILE='./_test_v1.py'
ACCOUNT=$1
ENDPOINT=$2

for f in $(
find ./docs/extras/code_samples -maxdepth 1 -name "*.txt" -not -name "workflow_*.txt" -not -name "v2_*.txt" | sort -h
)
do
if echo "${f}" | grep -q "default_v2.txt"; then
if [ -z "${API_KEY_V2}" ] || [ -z "${MODEL_ID}" ]; then
echo "Skipping ${f} (API_KEY_V2 or MODEL_ID not supplied)"
echo
continue
fi
fi

echo
echo "###############################################"
echo "${f}"
echo "###############################################"
echo

sed "s/my-api-key/${MINDEE_API_KEY}/" "${f}" > $OUTPUT_FILE
sed -i 's/\/path\/to\/the\/file.ext/.\/tests\/data\/file_types\/pdf\/blank_1.pdf/' $OUTPUT_FILE

if echo "$f" | grep -q "custom_v1.txt"
then
sed -i "s/my-account/$ACCOUNT/g" $OUTPUT_FILE
sed -i "s/my-endpoint/$ENDPOINT/g" $OUTPUT_FILE
fi

if echo "${f}" | grep -q "default.txt"
then
sed -i "s/my-account/$ACCOUNT/" $OUTPUT_FILE
sed -i "s/my-endpoint/$ENDPOINT/" $OUTPUT_FILE
sed -i "s/my-version/1/" $OUTPUT_FILE
fi

if echo "${f}" | grep -q "default_async.txt"
then
sed -i "s/my-account/mindee/" $OUTPUT_FILE
sed -i "s/my-endpoint/invoice_splitter/" $OUTPUT_FILE
sed -i "s/my-version/1/" $OUTPUT_FILE
fi

sleep 0.5 # avoid too many request errors
python $OUTPUT_FILE
done
46 changes: 46 additions & 0 deletions tests/test_v2_code_samples.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#! /bin/sh
set -e

OUTPUT_FILE='./_test_v2.py'

for f in $(
find ./docs/extras/code_samples -maxdepth 1 -name "v2_*.txt" | sort -h
)
do
echo
echo "###############################################"
echo "${f}"
echo "###############################################"
echo

sed "s/MY_API_KEY/${MINDEE_V2_API_KEY}/" "${f}" > $OUTPUT_FILE
sed -i 's/\/path\/to\/the\/file.ext/.\/tests\/data\/file_types\/pdf\/blank_1.pdf/' $OUTPUT_FILE

if echo "${f}" | grep -q "v2_extraction.txt"
then
sed -i "s/MY_MODEL_ID/${MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID}/" $OUTPUT_FILE
fi

if echo "${f}" | grep -q "v2_classification.txt"
then
sed -i "s/MY_MODEL_ID/${MINDEE_V2_SE_TESTS_CLASSIFICATION_MODEL_ID}/" $OUTPUT_FILE
fi

if echo "${f}" | grep -q "v2_crop.txt"
then
sed -i "s/MY_MODEL_ID/${MINDEE_V2_SE_TESTS_CROP_MODEL_ID}/" $OUTPUT_FILE
fi

if echo "${f}" | grep -q "v2_split.txt"
then
sed -i "s/MY_MODEL_ID/${MINDEE_V2_SE_TESTS_SPLIT_MODEL_ID}/" $OUTPUT_FILE
fi

if echo "${f}" | grep -q "v2_ocr.txt"
then
sed -i "s/MY_MODEL_ID/${MINDEE_V2_SE_TESTS_OCR_MODEL_ID}/" $OUTPUT_FILE
fi

sleep 0.5 # avoid too many request errors
python $OUTPUT_FILE
done