Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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