Skip to content

Commit b85984c

Browse files
♻️ 💥 fully remove v2 Inference in favor of Extraction (#186)
1 parent 1ad217f commit b85984c

35 files changed

Lines changed: 166 additions & 252 deletions

docs/code_samples/v2_extraction_polling.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22

33
use Mindee\V2\Client;
4-
use Mindee\V2\Product\Extraction\Params\InferenceParameters;
4+
use Mindee\V2\Product\Extraction\Params\ExtractionParameters;
55
use Mindee\Input\PathInput;
6-
use Mindee\V2\Parsing\Inference\InferenceResponse;
6+
use Mindee\V2\Product\Extraction\ExtractionResponse;
77

88
$apiKey = "MY_API_KEY";
99
$filePath = "/path/to/the/file.ext";
@@ -14,7 +14,7 @@ $mindeeClient = new Client($apiKey);
1414

1515
// Set inference parameters
1616
// Note: modelId is mandatory.
17-
$inferenceParams = new InferenceParameters(
17+
$inferenceParams = new ExtractionParameters(
1818
// ID of the model, required.
1919
$modelId,
2020

@@ -36,7 +36,7 @@ $inputSource = new PathInput($filePath);
3636

3737
// Send for processing using polling
3838
$response = $mindeeClient->enqueueAndGetResult(
39-
InferenceResponse::class,
39+
ExtractionResponse::class,
4040
$inputSource,
4141
$inferenceParams
4242
);

docs/code_samples/v2_extraction_webhook.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
use Mindee\V2\Client;
4-
use Mindee\V2\Product\Extraction\Params\InferenceParameters;
4+
use Mindee\V2\Product\Extraction\Params\ExtractionParameters;
55
use Mindee\Input\PathInput;
66

77
$apiKey = "MY_API_KEY";
@@ -13,7 +13,7 @@ $mindeeClient = new Client($apiKey);
1313

1414
// Set inference parameters
1515
// Note: modelId is mandatory.
16-
$inferenceParams = new InferenceParameters(
16+
$inferenceParams = new ExtractionParameters(
1717
// ID of the model, required.
1818
$modelId,
1919
webhooksIds: ["MY_WEBHOOK_ID"],

src/V1/Parsing/Common/ApiResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
abstract class ApiResponse
99
{
1010
/**
11-
* @var \Mindee\V1\Parsing\Common\ApiRequest Request part of the response.
11+
* @var ApiRequest Request part of the response.
1212
*/
1313
public ApiRequest $apiRequest;
1414
/**

src/V1/Parsing/Common/AsyncPredictResponse.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
class AsyncPredictResponse extends ApiResponse
1111
{
1212
/**
13-
* @var \Mindee\V1\Parsing\Common\Job Job object link to the prediction.
13+
* @var Job Job object link to the prediction.
1414
* As long as it isn't complete, the prediction doesn't exist.
1515
*/
1616
public Job $job;
1717
/**
18-
* @var \Mindee\V1\Parsing\Common\Document|null Document object. Can be null when enqueuing.
18+
* @var Document|null Document object. Can be null when enqueuing.
1919
*/
2020
public ?Document $document;
2121

src/V1/Parsing/Common/Document.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
use Mindee\Error\MindeeApiException;
77
use Mindee\V1\Parsing\Common\Extras\Extras;
88
use Mindee\V1\Parsing\Common\OCR\OCR;
9+
use ReflectionClass;
10+
use ReflectionException;
911

1012
/**
1113
* Base class for all predictions.
@@ -17,7 +19,7 @@ class Document
1719
*/
1820
public string $filename;
1921
/**
20-
* @var \Mindee\V1\Parsing\Common\Inference|object|string Result of the base inference.
22+
* @var Inference|object|string Result of the base inference.
2123
*/
2224
public Inference $inference;
2325
/**
@@ -29,28 +31,28 @@ class Document
2931
*/
3032
public int $nPages;
3133
/**
32-
* @var \Mindee\V1\Parsing\Common\Extras\Extras|null Potential Extras fields sent back along with the prediction.
34+
* @var Extras|null Potential Extras fields sent back along with the prediction.
3335
*/
3436
public ?Extras $extras;
3537
/**
36-
* @var \Mindee\V1\Parsing\Common\OCR\OCR|null Potential raw text results read by the OCR (limited feature)
38+
* @var OCR|null Potential raw text results read by the OCR (limited feature)
3739
*/
3840
public ?OCR $ocr;
3941

4042
/**
4143
* @param string $predictionType Type of prediction.
4244
* @param array $rawResponse Raw HTTP response.
43-
* @throws \Mindee\Error\MindeeApiException Throws if the prediction type isn't recognized.
45+
* @throws MindeeApiException Throws if the prediction type isn't recognized.
4446
*/
4547
public function __construct(string $predictionType, array $rawResponse)
4648
{
4749
$this->id = $rawResponse['id'];
4850
$this->nPages = $rawResponse['n_pages'];
4951
$this->filename = $rawResponse['name'];
5052
try {
51-
$reflection = new \ReflectionClass($predictionType);
53+
$reflection = new ReflectionClass($predictionType);
5254
$this->inference = $reflection->newInstance($rawResponse['inference']);
53-
} catch (\ReflectionException $e) {
55+
} catch (ReflectionException $e) {
5456
throw new MindeeApiException(
5557
"Unable to create custom product " . $predictionType,
5658
ErrorCode::INTERNAL_LIBRARY_ERROR,

src/V1/Parsing/Common/Inference.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
abstract class Inference
1111
{
1212
/**
13-
* @var \Mindee\V1\Parsing\Common\Product Name and version of a given product, as sent back by the API.
13+
* @var Product Name and version of a given product, as sent back by the API.
1414
*/
1515
public Product $product;
1616
/**
@@ -22,7 +22,7 @@ abstract class Inference
2222
*/
2323
public static string $endpointVersion;
2424
/**
25-
* @var \Mindee\V1\Parsing\Common\Prediction A document's top-level Prediction.
25+
* @var Prediction A document's top-level Prediction.
2626
*/
2727
public Prediction $prediction;
2828
/**
@@ -38,7 +38,7 @@ abstract class Inference
3838
*/
3939
public ?int $pageId;
4040
/**
41-
* @var \Mindee\V1\Parsing\Common\Extras\Extras|null Potential Extras fields sent back along with the prediction.
41+
* @var Extras|null Potential Extras fields sent back along with the prediction.
4242
*/
4343
public ?Extras $extras;
4444

src/V1/Parsing/Common/OCR/OCR.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class OCR
99
{
1010
/**
11-
* @var \Mindee\V1\Parsing\Common\OCR\MVisionV1 Mindee Vision v1 results.
11+
* @var MVisionV1 Mindee Vision v1 results.
1212
*/
1313
public MVisionV1 $mvisionV1;
1414

src/V1/Parsing/Standard/PositionField.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,23 @@
1111
class PositionField extends BaseField
1212
{
1313
/**
14-
* @var \Mindee\Geometry\Polygon|null Polygon of cropped area, identical to the `polygon` property.
14+
* @var Polygon|null Polygon of cropped area, identical to the `polygon` property.
1515
*/
1616
public $value;
1717
/**
18-
* @var \Mindee\Geometry\Polygon|null Polygon of cropped area.
18+
* @var Polygon|null Polygon of cropped area.
1919
*/
2020
public ?Polygon $polygon;
2121
/**
22-
* @var \Mindee\Geometry\Polygon|null Quadrangle of cropped area (does not exceed the canvas).
22+
* @var Polygon|null Quadrangle of cropped area (does not exceed the canvas).
2323
*/
2424
public ?Polygon $quadrangle;
2525
/**
26-
* @var \Mindee\Geometry\Polygon|null Oriented rectangle of cropped area (may exceed the canvas).
26+
* @var Polygon|null Oriented rectangle of cropped area (may exceed the canvas).
2727
*/
2828
public ?Polygon $rectangle;
2929
/**
30-
* @var \Mindee\Geometry\Polygon|null Straight rectangle of cropped area (does not exceed the canvas).
30+
* @var Polygon|null Straight rectangle of cropped area (does not exceed the canvas).
3131
*/
3232
public ?Polygon $boundingBox;
3333

@@ -36,7 +36,7 @@ class PositionField extends BaseField
3636
*
3737
* @param array $rawPrediction Raw prediction array.
3838
* @param string $key Key to use for the value.
39-
* @return \Mindee\Geometry\Polygon|null
39+
* @return Polygon|null
4040
*/
4141
private static function getQuadrilateral(array $rawPrediction, string $key): ?Polygon
4242
{
@@ -52,7 +52,7 @@ private static function getQuadrilateral(array $rawPrediction, string $key): ?Po
5252
*
5353
* @param array $rawPrediction Raw prediction array.
5454
* @param string $key Key to use for the value.
55-
* @return \Mindee\Geometry\Polygon|null
55+
* @return Polygon|null
5656
*/
5757
private static function getPolygon(array $rawPrediction, string $key): ?Polygon
5858
{

src/V2/Client.php

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
namespace Mindee\V2;
44

5+
use Mindee\ClientOptions\PollingOptions;
56
use Mindee\CustomSleepMixin;
67
use Mindee\Error\MindeeException;
78
use Mindee\Input\InputSource;
89
use Mindee\V2\ClientOptions\BaseParameters;
910
use Mindee\V2\HTTP\MindeeAPIV2;
1011
use Mindee\V2\Parsing\Inference\BaseResponse;
11-
use Mindee\V2\Parsing\Inference\InferenceResponse;
1212
use Mindee\V2\Parsing\JobResponse;
13-
use Mindee\V2\Product\Extraction\Params\InferenceParameters;
13+
use Mindee\V2\Product\Extraction\Params\ExtractionParameters;
1414

1515
/**
1616
* Mindee Client V2.
@@ -37,15 +37,15 @@ public function __construct(?string $apiKey = null)
3737
/**
3838
* Send the document to an asynchronous endpoint and return its ID in the queue.
3939
*
40-
* @param InputSource $inputSource File to parse.
41-
* @param InferenceParameters $params Parameters relating to prediction options.
40+
* @param InputSource $inputSource File to parse.
41+
* @param ExtractionParameters $params Parameters relating to prediction options.
4242
* @return JobResponse A JobResponse containing the job (queue) corresponding to a document.
4343
* @throws MindeeException Throws if the input document is not provided.
4444
* @category Asynchronous
4545
*/
4646
public function enqueueInference(
4747
InputSource $inputSource,
48-
InferenceParameters $params
48+
ExtractionParameters $params
4949
): JobResponse {
5050
return $this->enqueue($inputSource, $params);
5151
}
@@ -65,17 +65,6 @@ public function enqueue(
6565
return $this->mindeeApi->reqPostEnqueue($inputSource, $params);
6666
}
6767

68-
/**
69-
* Retrieves an inference.
70-
*
71-
* @param string $inferenceId ID of the queue to poll.
72-
* @return InferenceResponse An InferenceResponse containing a Job.
73-
* @category Asynchronous
74-
*/
75-
public function getInference(string $inferenceId): InferenceResponse
76-
{
77-
return $this->mindeeApi->reqGetInference($inferenceId);
78-
}
7968

8069
/**
8170
* @template T of BaseResponse
@@ -118,40 +107,28 @@ public function getJob(string $jobId): JobResponse
118107
return $this->mindeeApi->reqGetJob($jobId);
119108
}
120109

121-
/**
122-
* Send a document to an endpoint and poll the server until the result is sent or
123-
* until the maximum number of tries is reached.
124-
*
125-
* @param InputSource $inputDoc Input document to parse.
126-
* @param InferenceParameters $params Parameters relating to prediction options.
127-
* @return InferenceResponse A response containing parsing results.
128-
* @throws MindeeException Throws if enqueueing fails, job fails, or times out.
129-
*/
130-
public function enqueueAndGetInference(
131-
InputSource $inputDoc,
132-
InferenceParameters $params
133-
): InferenceResponse {
134-
return $this->enqueueAndGetResult(InferenceResponse::class, $inputDoc, $params);
135-
}
136-
137110
/**
138111
* Send a document to an endpoint and poll the server until the result is sent or
139112
* until the maximum number of tries is reached.
140113
*
141114
* @template T of BaseResponse
142-
* @param string $responseClass The response class to construct.
115+
* @param string $responseClass The response class to construct.
143116
* @phpstan-param class-string<T> $responseClass
144-
* @param InputSource $inputDoc Input document to parse.
145-
* @param BaseParameters $params Parameters relating to prediction options.
117+
* @param InputSource $inputDoc Input document to parse.
118+
* @param BaseParameters $params Parameters relating to prediction options.
119+
* @param PollingOptions|null $pollingOptions Options to apply to the polling.
146120
* @return BaseResponse A response containing parsing results.
147121
* @throws MindeeException Throws if enqueueing fails, job fails, or times out.
148122
*/
149123
public function enqueueAndGetResult(
150124
string $responseClass,
151125
InputSource $inputDoc,
152-
BaseParameters $params
126+
BaseParameters $params,
127+
?PollingOptions $pollingOptions = null
153128
): BaseResponse {
154-
$pollingOptions = $params->pollingOptions;
129+
if (!$pollingOptions) {
130+
$pollingOptions = new PollingOptions();
131+
}
155132

156133
$enqueueResponse = $this->enqueue($inputDoc, $params);
157134

src/V2/ClientOptions/BaseParameters.php

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace Mindee\V2\ClientOptions;
44

5-
use Mindee\ClientOptions\PollingOptions;
6-
75
/**
86
* Base parameters for running an inference.
97
*/
@@ -25,17 +23,11 @@ abstract class BaseParameters
2523
public array $webhooksIds;
2624

2725
/**
28-
* @var PollingOptions Polling options.
26+
* @param string $modelId ID of the model.
27+
* @param string|null $alias Optional file alias.
28+
* @param array<string>|null $webhooksIds List of webhook IDs.
2929
*/
30-
public PollingOptions $pollingOptions;
31-
32-
/**
33-
* @param string $modelId ID of the model.
34-
* @param string|null $alias Optional file alias.
35-
* @param array<string>|null $webhooksIds List of webhook IDs.
36-
* @param PollingOptions|null $pollingOptions Polling options.
37-
*/
38-
public function __construct(string $modelId, ?string $alias, ?array $webhooksIds, ?PollingOptions $pollingOptions)
30+
public function __construct(string $modelId, ?string $alias, ?array $webhooksIds)
3931
{
4032
$this->modelId = $modelId;
4133

@@ -47,10 +39,6 @@ public function __construct(string $modelId, ?string $alias, ?array $webhooksIds
4739
} else {
4840
$this->webhooksIds = [];
4941
}
50-
if (!$pollingOptions) {
51-
$pollingOptions = new PollingOptions();
52-
}
53-
$this->pollingOptions = $pollingOptions;
5442
}
5543

5644
/**

0 commit comments

Comments
 (0)