From ff1dddb000a4dbb28a6c87ec12c9f66e9a7e5cbd Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Wed, 19 Nov 2025 11:49:35 +0100 Subject: [PATCH] :sparkles: add support for textContext parameter in V2 --- src/Http/MindeeApiV2.php | 3 +++ src/Input/InferenceParameters.php | 11 +++++++++++ tests/V2/ClientV2Test.php | 2 +- tests/V2/ClientV2TestFunctional.php | 7 ++++--- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/Http/MindeeApiV2.php b/src/Http/MindeeApiV2.php index cce82496..ec122cb9 100644 --- a/src/Http/MindeeApiV2.php +++ b/src/Http/MindeeApiV2.php @@ -334,6 +334,9 @@ private function documentEnqueuePost( if (isset($params->alias)) { $postFields['alias'] = $params->alias; } + if (isset($params->textContext)) { + $postFields['text_context'] = $params->textContext; + } $url = $this->baseUrl . '/inferences/enqueue'; curl_setopt($ch, CURLOPT_URL, $url); diff --git a/src/Input/InferenceParameters.php b/src/Input/InferenceParameters.php index 7e2b6b33..754685bb 100644 --- a/src/Input/InferenceParameters.php +++ b/src/Input/InferenceParameters.php @@ -43,6 +43,12 @@ class InferenceParameters */ public array $webhooksIds; + /** + * @var string|null Additional text context used by the model during inference. + * Not recommended, for specific use only. + */ + public ?string $textContext; + /** * @var PollingOptions Polling options. */ @@ -56,6 +62,7 @@ class InferenceParameters * @param boolean|null $confidence Whether to calculate confidence scores for all fields. * @param string|null $alias Optional file alias. * @param array|null $webhooksIds List of webhook IDs. + * @param string|null $textContext Additional text context used by the model during inference. * @param PollingOptions|null $pollingOptions Polling options. */ public function __construct( @@ -66,6 +73,7 @@ public function __construct( ?bool $confidence = null, ?string $alias = null, ?array $webhooksIds = null, + ?string $textContext = null, ?PollingOptions $pollingOptions = null, ) { $this->modelId = $modelId; @@ -81,6 +89,9 @@ public function __construct( if (isset($alias)) { $this->alias = $alias; } + if (isset($textContext)) { + $this->textContext = $textContext; + } if (isset($webhooksIds)) { $this->webhooksIds = $webhooksIds; } else { diff --git a/tests/V2/ClientV2Test.php b/tests/V2/ClientV2Test.php index af7f6fe5..497e7b91 100644 --- a/tests/V2/ClientV2Test.php +++ b/tests/V2/ClientV2Test.php @@ -40,7 +40,7 @@ public function testEnqueuePostAsync(): void $mindeeClient = self::makeClientWithMockedApi($predictable); $input = new PathInput(\TestingUtilities::getFileTypesDir() . '/pdf/blank_1.pdf'); - $params = new InferenceParameters('dummy-model-id'); + $params = new InferenceParameters('dummy-model-id', textContext: 'dummy text context'); $response = $mindeeClient->enqueueInference($input, $params); diff --git a/tests/V2/ClientV2TestFunctional.php b/tests/V2/ClientV2TestFunctional.php index bf6f91f3..14781ac6 100644 --- a/tests/V2/ClientV2TestFunctional.php +++ b/tests/V2/ClientV2TestFunctional.php @@ -63,7 +63,7 @@ public function testParseFileFilledSinglePageMustSucceed(): void \TestingUtilities::getV1DataDir() . '/products/financial_document/default_sample.jpg' ); - $inferenceParams = new InferenceParameters($this->modelId, rag: false); + $inferenceParams = new InferenceParameters($this->modelId, rag: false, textContext: 'this is an invoice'); $response = $this->mindeeClient->enqueueAndGetInference($source, $inferenceParams); $this->assertNotNull($response); @@ -111,7 +111,7 @@ public function testUnknownModelMustThrowError(): void { $source = new PathInput(\TestingUtilities::getFileTypesDir() . '/pdf/multipage_cut-2.pdf'); - $inferenceParams = new InferenceParameters('fc405e37-4ba4-4d03-aeba-533a8d1f0f21'); + $inferenceParams = new InferenceParameters('fc405e37-4ba4-4d03-aeba-533a8d1f0f21', textContext: 'this is invalid'); try { $this->mindeeClient->enqueueInference($source, $inferenceParams); @@ -145,7 +145,8 @@ public function testInvalidWebhookIDsMustThrowError() null, null, null, - ['fc405e37-4ba4-4d03-aeba-533a8d1f0f21', 'fc405e37-4ba4-4d03-aeba-533a8d1f0f21'] + ['fc405e37-4ba4-4d03-aeba-533a8d1f0f21', 'fc405e37-4ba4-4d03-aeba-533a8d1f0f21'], + null ); try {