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
8 changes: 4 additions & 4 deletions docs/code_samples/v2_extraction_polling.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

use Mindee\V2\Client;
use Mindee\V2\Product\Extraction\Params\InferenceParameters;
use Mindee\V2\Product\Extraction\Params\ExtractionParameters;
use Mindee\Input\PathInput;
use Mindee\V2\Parsing\Inference\InferenceResponse;
use Mindee\V2\Product\Extraction\ExtractionResponse;

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

// Set inference parameters
// Note: modelId is mandatory.
$inferenceParams = new InferenceParameters(
$inferenceParams = new ExtractionParameters(
// ID of the model, required.
$modelId,

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

// Send for processing using polling
$response = $mindeeClient->enqueueAndGetResult(
InferenceResponse::class,
ExtractionResponse::class,
$inputSource,
$inferenceParams
);
Expand Down
4 changes: 2 additions & 2 deletions docs/code_samples/v2_extraction_webhook.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

use Mindee\V2\Client;
use Mindee\V2\Product\Extraction\Params\InferenceParameters;
use Mindee\V2\Product\Extraction\Params\ExtractionParameters;
use Mindee\Input\PathInput;

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

// Set inference parameters
// Note: modelId is mandatory.
$inferenceParams = new InferenceParameters(
$inferenceParams = new ExtractionParameters(
// ID of the model, required.
$modelId,
webhooksIds: ["MY_WEBHOOK_ID"],
Expand Down
2 changes: 1 addition & 1 deletion src/V1/Parsing/Common/Inference.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Mindee\V1\Parsing\Common\Extras\Extras;

/**
* Base Inference class for all predictions.
* Base ExtractionInference class for all predictions.
Comment thread
sebastianMindee marked this conversation as resolved.
Outdated
*/
abstract class Inference
{
Expand Down
51 changes: 14 additions & 37 deletions src/V2/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

namespace Mindee\V2;

use Mindee\ClientOptions\PollingOptions;
use Mindee\CustomSleepMixin;
use Mindee\Error\MindeeException;
use Mindee\Input\InputSource;
use Mindee\V2\ClientOptions\BaseParameters;
use Mindee\V2\HTTP\MindeeAPIV2;
use Mindee\V2\Parsing\Inference\BaseResponse;
use Mindee\V2\Parsing\Inference\InferenceResponse;
use Mindee\V2\Parsing\JobResponse;
use Mindee\V2\Product\Extraction\Params\InferenceParameters;
use Mindee\V2\Product\Extraction\Params\ExtractionParameters;

/**
* Mindee Client V2.
Expand All @@ -37,15 +37,15 @@ public function __construct(?string $apiKey = null)
/**
* Send the document to an asynchronous endpoint and return its ID in the queue.
*
* @param InputSource $inputSource File to parse.
* @param InferenceParameters $params Parameters relating to prediction options.
* @param InputSource $inputSource File to parse.
* @param ExtractionParameters $params Parameters relating to prediction options.
* @return JobResponse A JobResponse containing the job (queue) corresponding to a document.
* @throws MindeeException Throws if the input document is not provided.
* @category Asynchronous
*/
public function enqueueInference(
InputSource $inputSource,
InferenceParameters $params
ExtractionParameters $params
): JobResponse {
return $this->enqueue($inputSource, $params);
}
Expand All @@ -65,17 +65,6 @@ public function enqueue(
return $this->mindeeApi->reqPostEnqueue($inputSource, $params);
}

/**
* Retrieves an inference.
*
* @param string $inferenceId ID of the queue to poll.
* @return InferenceResponse An InferenceResponse containing a Job.
* @category Asynchronous
*/
public function getInference(string $inferenceId): InferenceResponse
{
return $this->mindeeApi->reqGetInference($inferenceId);
}

/**
* @template T of BaseResponse
Expand Down Expand Up @@ -118,40 +107,28 @@ public function getJob(string $jobId): JobResponse
return $this->mindeeApi->reqGetJob($jobId);
}

/**
* Send a document to an endpoint and poll the server until the result is sent or
* until the maximum number of tries is reached.
*
* @param InputSource $inputDoc Input document to parse.
* @param InferenceParameters $params Parameters relating to prediction options.
* @return InferenceResponse A response containing parsing results.
* @throws MindeeException Throws if enqueueing fails, job fails, or times out.
*/
public function enqueueAndGetInference(
InputSource $inputDoc,
InferenceParameters $params
): InferenceResponse {
return $this->enqueueAndGetResult(InferenceResponse::class, $inputDoc, $params);
}

/**
* Send a document to an endpoint and poll the server until the result is sent or
* until the maximum number of tries is reached.
*
* @template T of BaseResponse
* @param string $responseClass The response class to construct.
* @param string $responseClass The response class to construct.
* @phpstan-param class-string<T> $responseClass
* @param InputSource $inputDoc Input document to parse.
* @param BaseParameters $params Parameters relating to prediction options.
* @param InputSource $inputDoc Input document to parse.
* @param BaseParameters $params Parameters relating to prediction options.
* @param PollingOptions|null $pollingOptions Options to apply to the polling.
* @return BaseResponse A response containing parsing results.
* @throws MindeeException Throws if enqueueing fails, job fails, or times out.
*/
public function enqueueAndGetResult(
string $responseClass,
InputSource $inputDoc,
BaseParameters $params
BaseParameters $params,
?PollingOptions $pollingOptions = null
): BaseResponse {
$pollingOptions = $params->pollingOptions;
if (!$pollingOptions) {
$pollingOptions = new PollingOptions();
}

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

Expand Down
20 changes: 4 additions & 16 deletions src/V2/ClientOptions/BaseParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Mindee\V2\ClientOptions;

use Mindee\ClientOptions\PollingOptions;

/**
* Base parameters for running an inference.
*/
Expand All @@ -25,17 +23,11 @@ abstract class BaseParameters
public array $webhooksIds;

/**
* @var PollingOptions Polling options.
* @param string $modelId ID of the model.
* @param string|null $alias Optional file alias.
* @param array<string>|null $webhooksIds List of webhook IDs.
*/
public PollingOptions $pollingOptions;

/**
* @param string $modelId ID of the model.
* @param string|null $alias Optional file alias.
* @param array<string>|null $webhooksIds List of webhook IDs.
* @param PollingOptions|null $pollingOptions Polling options.
*/
public function __construct(string $modelId, ?string $alias, ?array $webhooksIds, ?PollingOptions $pollingOptions)
public function __construct(string $modelId, ?string $alias, ?array $webhooksIds)
{
$this->modelId = $modelId;

Expand All @@ -47,10 +39,6 @@ public function __construct(string $modelId, ?string $alias, ?array $webhooksIds
} else {
$this->webhooksIds = [];
}
if (!$pollingOptions) {
$pollingOptions = new PollingOptions();
}
$this->pollingOptions = $pollingOptions;
}

/**
Expand Down
21 changes: 3 additions & 18 deletions src/V2/HTTP/MindeeAPIV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
use Mindee\V2\ClientOptions\BaseParameters;
use Mindee\V2\Parsing\ErrorResponse;
use Mindee\V2\Parsing\Inference\BaseResponse;
use Mindee\V2\Parsing\Inference\InferenceResponse;
use Mindee\V2\Parsing\JobResponse;
use Mindee\V2\Product\Extraction\ExtractionResponse;
use ReflectionClass;
use ReflectionException;
use ReflectionProperty;

use const Mindee\V1\HTTP\API_KEY_ENV_NAME;
use const Mindee\VERSION;

// phpcs:disable
Expand Down Expand Up @@ -230,22 +231,6 @@ private function processJobResponse(array $result): JobResponse
}
}

/**
* Requests the job of a queued document from the API.
* Throws an error if the server's response contains one.
* @param string $inferenceId ID of the inference.
* @return InferenceResponse
* @throws MindeeException Throws if the server's response contains an error.
* @throws MindeeException Throws if the inference ID is not provided.
*/
public function reqGetInference(string $inferenceId): InferenceResponse
{
if (!isset($inferenceId)) {
throw new MindeeException("Inference ID must be provided.", ErrorCode::USER_INPUT_ERROR);
}
return $this->reqGetResult(InferenceResponse::class, $inferenceId);
}

/**
* Requests the job of a queued document from the API.
* Throws an error if the server's response contains one.
Expand Down Expand Up @@ -360,7 +345,7 @@ private function sendGetRequest(string $url): array
* Starts a CURL session using POST.
*
* @param InputSource $inputSource File to upload.
* @param BaseParameters $params Inference parameters.
* @param BaseParameters $params ExtractionInference parameters.
* @return array
* @throws MindeeException Throws if the cURL operation doesn't go succeed.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/V2/Parsing/Inference/InferenceFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Mindee\V2\Parsing\Inference;

/**
* Inference result file class.
* ExtractionInference result file class.
*/
class InferenceFile
{
Expand Down
2 changes: 1 addition & 1 deletion src/V2/Parsing/Inference/InferenceJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Mindee\V2\Parsing\Inference;

/**
* Information on the Job associated to a given Inference.
* Information on the Job associated to a given ExtractionInference.
*/
class InferenceJob
{
Expand Down
2 changes: 1 addition & 1 deletion src/V2/Parsing/Inference/InferenceModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Mindee\V2\Parsing\Inference;

/**
* Inference result model class.
* ExtractionInference result model class.
*/
class InferenceModel
{
Expand Down
28 changes: 0 additions & 28 deletions src/V2/Parsing/Inference/InferenceResponse.php

This file was deleted.

8 changes: 4 additions & 4 deletions src/V2/Product/Classification/ClassificationClassifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Mindee\V2\Product\Classification;

use Mindee\V2\Parsing\Inference\InferenceResponse;
use Mindee\V2\Product\Extraction\ExtractionResponse;

/**
* Classification of document type from the source file.
Expand All @@ -15,9 +15,9 @@ class ClassificationClassifier
public string $documentType;

/**
* @var InferenceResponse|null $extractionResponse The extraction response associated with the classification.
* @var ExtractionResponse|null $extractionResponse The extraction response associated with the classification.
*/
public ?InferenceResponse $extractionResponse;
public ?ExtractionResponse $extractionResponse;

/**
* @param array $rawPrediction Raw prediction array.
Expand All @@ -26,7 +26,7 @@ public function __construct(array $rawPrediction)
{
$this->documentType = $rawPrediction['document_type'];
$this->extractionResponse = isset($rawPrediction['extraction_response']) ?
new InferenceResponse($rawPrediction['extraction_response']) : null;
new ExtractionResponse($rawPrediction['extraction_response']) : null;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/V2/Product/Classification/ClassificationResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class ClassificationResponse extends BaseResponse
{
/**
* @var ClassificationInference Inference results for the classification.
* @var ClassificationInference ExtractionInference results for the classification.
*/
public ClassificationInference $inference;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@ class ClassificationParameters extends BaseParameters
public static string $slug = "classification";

/**
* @param string $modelId ID of the model.
* @param string|null $alias Optional file alias.
* @param array<string>|null $webhooksIds List of webhook IDs.
* @param PollingOptions|null $pollingOptions Polling options.
* @param string $modelId ID of the model.
* @param string|null $alias Optional file alias.
* @param array<string>|null $webhooksIds List of webhook IDs.
*/
public function __construct(
string $modelId,
?string $alias = null,
?array $webhooksIds = null,
?PollingOptions $pollingOptions = null
?array $webhooksIds = null
) {
parent::__construct($modelId, $alias, $webhooksIds, $pollingOptions);
parent::__construct($modelId, $alias, $webhooksIds);
}
}
8 changes: 4 additions & 4 deletions src/V2/Product/Crop/CropItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Mindee\V2\Product\Crop;

use Mindee\V2\Parsing\Inference\Field\FieldLocation;
use Mindee\V2\Parsing\Inference\InferenceResponse;
use Mindee\V2\Product\Extraction\ExtractionResponse;

/**
* Result of a cropped document region.
Expand All @@ -21,9 +21,9 @@ class CropItem
public string $objectType;

/**
* @var InferenceResponse|null $extractionResponse The extraction response associated with the crop.
* @var ExtractionResponse|null $extractionResponse The extraction response associated with the crop.
*/
public ?InferenceResponse $extractionResponse;
public ?ExtractionResponse $extractionResponse;
/**
* @param array $rawResponse Raw server response array.
*/
Expand All @@ -32,7 +32,7 @@ public function __construct(array $rawResponse)
$this->location = new FieldLocation($rawResponse['location']);
$this->objectType = $rawResponse['object_type'];
$this->extractionResponse = isset($rawResponse['extraction_response']) ?
new InferenceResponse($rawResponse['extraction_response']) : null;
new ExtractionResponse($rawResponse['extraction_response']) : null;
}

/**
Expand Down
Loading
Loading