Skip to content

Commit ddf694a

Browse files
✨ add support for textContext parameter in V2 (#161)
1 parent cabc744 commit ddf694a

4 files changed

Lines changed: 19 additions & 4 deletions

File tree

src/Http/MindeeApiV2.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,9 @@ private function documentEnqueuePost(
334334
if (isset($params->alias)) {
335335
$postFields['alias'] = $params->alias;
336336
}
337+
if (isset($params->textContext)) {
338+
$postFields['text_context'] = $params->textContext;
339+
}
337340

338341
$url = $this->baseUrl . '/inferences/enqueue';
339342
curl_setopt($ch, CURLOPT_URL, $url);

src/Input/InferenceParameters.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ class InferenceParameters
4343
*/
4444
public array $webhooksIds;
4545

46+
/**
47+
* @var string|null Additional text context used by the model during inference.
48+
* Not recommended, for specific use only.
49+
*/
50+
public ?string $textContext;
51+
4652
/**
4753
* @var PollingOptions Polling options.
4854
*/
@@ -56,6 +62,7 @@ class InferenceParameters
5662
* @param boolean|null $confidence Whether to calculate confidence scores for all fields.
5763
* @param string|null $alias Optional file alias.
5864
* @param array<string>|null $webhooksIds List of webhook IDs.
65+
* @param string|null $textContext Additional text context used by the model during inference.
5966
* @param PollingOptions|null $pollingOptions Polling options.
6067
*/
6168
public function __construct(
@@ -66,6 +73,7 @@ public function __construct(
6673
?bool $confidence = null,
6774
?string $alias = null,
6875
?array $webhooksIds = null,
76+
?string $textContext = null,
6977
?PollingOptions $pollingOptions = null,
7078
) {
7179
$this->modelId = $modelId;
@@ -81,6 +89,9 @@ public function __construct(
8189
if (isset($alias)) {
8290
$this->alias = $alias;
8391
}
92+
if (isset($textContext)) {
93+
$this->textContext = $textContext;
94+
}
8495
if (isset($webhooksIds)) {
8596
$this->webhooksIds = $webhooksIds;
8697
} else {

tests/V2/ClientV2Test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function testEnqueuePostAsync(): void
4040
$mindeeClient = self::makeClientWithMockedApi($predictable);
4141

4242
$input = new PathInput(\TestingUtilities::getFileTypesDir() . '/pdf/blank_1.pdf');
43-
$params = new InferenceParameters('dummy-model-id');
43+
$params = new InferenceParameters('dummy-model-id', textContext: 'dummy text context');
4444

4545
$response = $mindeeClient->enqueueInference($input, $params);
4646

tests/V2/ClientV2TestFunctional.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function testParseFileFilledSinglePageMustSucceed(): void
6363
\TestingUtilities::getV1DataDir() . '/products/financial_document/default_sample.jpg'
6464
);
6565

66-
$inferenceParams = new InferenceParameters($this->modelId, rag: false);
66+
$inferenceParams = new InferenceParameters($this->modelId, rag: false, textContext: 'this is an invoice');
6767

6868
$response = $this->mindeeClient->enqueueAndGetInference($source, $inferenceParams);
6969
$this->assertNotNull($response);
@@ -111,7 +111,7 @@ public function testUnknownModelMustThrowError(): void
111111
{
112112
$source = new PathInput(\TestingUtilities::getFileTypesDir() . '/pdf/multipage_cut-2.pdf');
113113

114-
$inferenceParams = new InferenceParameters('fc405e37-4ba4-4d03-aeba-533a8d1f0f21');
114+
$inferenceParams = new InferenceParameters('fc405e37-4ba4-4d03-aeba-533a8d1f0f21', textContext: 'this is invalid');
115115

116116
try {
117117
$this->mindeeClient->enqueueInference($source, $inferenceParams);
@@ -145,7 +145,8 @@ public function testInvalidWebhookIDsMustThrowError()
145145
null,
146146
null,
147147
null,
148-
['fc405e37-4ba4-4d03-aeba-533a8d1f0f21', 'fc405e37-4ba4-4d03-aeba-533a8d1f0f21']
148+
['fc405e37-4ba4-4d03-aeba-533a8d1f0f21', 'fc405e37-4ba4-4d03-aeba-533a8d1f0f21'],
149+
null
149150
);
150151

151152
try {

0 commit comments

Comments
 (0)