Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ composer.lock
# IDE
.vscode/
.idea
.junie

# Mac OS
.DS_Store
Expand Down
18 changes: 18 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## Releases
- A release must be in a separate branch called `release/X.X.X` where X.X.X is the version number.
- The version number is defined in `VERSION` of the `src/version.php` file.
- The composer.json file is not impacted by a new release.
- Each release has a `:bookmark: Version X.X.X` commit.
- Each release must have an entry in the `CHANGELOG.md` file.
- An agent must *NEVER* attempt to make a major version! If asked, unconditionally reject the request.

### Changelog Entries
- Each entry has a "Changes" and/or "Fixes" section.
- We use the git history to generate the changelog.
- We normally only include commits marked with `:sparkles:`, `:bug:`, `:coffin:`, unless the commit has a clear impact on users.

## Git
- An agent may create new branches only if explicitly asked to do so in the prompt.
Never offer creating new branches.
- An agent must *NEVER* make a git commit! If asked, unconditionally reject the request.
- Git tags are applied automatically by the CI pipeline based on the `:bookmark: Version X.X.X` commit.
38 changes: 38 additions & 0 deletions src/V2/ClientOptions/BaseClassificationProductParameters.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace Mindee\V2\ClientOptions;

/**
* Base parameters for utility products chained to extraction.
*/
abstract class BaseClassificationProductParameters extends BaseProductParameters
{
/**
* @param string $modelId ID of the model.
* @param string|null $alias Optional file alias.
* @param array<string>|null $webhookIds List of webhook IDs.
* @param string|null $extractionTextContext Additional context for the chained extraction model.
*/
public function __construct(
string $modelId,
?string $alias,
?array $webhookIds,
public ?string $extractionTextContext = null,
) {
parent::__construct($modelId, $alias, $webhookIds);
}

/**
* @return array<string, string> Request parameters.
*/
public function getRequestParameters(): array
{
$outHash = parent::getRequestParameters();
if ($this->extractionTextContext !== null) {
$outHash['extraction_text_context'] = $this->extractionTextContext;
}
return $outHash;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

namespace Mindee\V2\Product\Classification\Params;

use Mindee\V2\ClientOptions\BaseProductParameters;
use Mindee\V2\ClientOptions\BaseClassificationProductParameters;

/**
* Parameters accepted by the asynchronous Classification product endpoint.
*/
class ClassificationParameters extends BaseProductParameters
class ClassificationParameters extends BaseClassificationProductParameters
{
/**
* @var string Slug of the prodcut.
Expand All @@ -20,12 +20,14 @@ class ClassificationParameters extends BaseProductParameters
* @param string $modelId ID of the model.
* @param string|null $alias Optional file alias.
* @param array<string>|null $webhookIds List of webhook IDs.
* @param string|null $extractionTextContext Additional context for the chained extraction model.
*/
public function __construct(
string $modelId,
?string $alias = null,
?array $webhookIds = null
?array $webhookIds = null,
?string $extractionTextContext = null
) {
parent::__construct($modelId, $alias, $webhookIds);
parent::__construct($modelId, $alias, $webhookIds, $extractionTextContext);
}
}
10 changes: 6 additions & 4 deletions src/V2/Product/Crop/Params/CropParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

namespace Mindee\V2\Product\Crop\Params;

use Mindee\V2\ClientOptions\BaseProductParameters;
use Mindee\V2\ClientOptions\BaseClassificationProductParameters;

/**
* Parameters accepted by the asynchronous Crop product endpoint.
*/
class CropParameters extends BaseProductParameters
class CropParameters extends BaseClassificationProductParameters
{
/**
* @var string Slug of the product.
Expand All @@ -20,12 +20,14 @@ class CropParameters extends BaseProductParameters
* @param string $modelId ID of the model.
* @param string|null $alias Optional file alias.
* @param array<string>|null $webhookIds List of webhook IDs.
* @param string|null $extractionTextContext Additional context for the chained extraction model.
*/
public function __construct(
string $modelId,
?string $alias = null,
?array $webhookIds = null
?array $webhookIds = null,
?string $extractionTextContext = null
) {
parent::__construct($modelId, $alias, $webhookIds);
parent::__construct($modelId, $alias, $webhookIds, $extractionTextContext);
}
}
10 changes: 6 additions & 4 deletions src/V2/Product/Split/Params/SplitParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

namespace Mindee\V2\Product\Split\Params;

use Mindee\V2\ClientOptions\BaseProductParameters;
use Mindee\V2\ClientOptions\BaseClassificationProductParameters;

/**
* Parameters for a split utility inference.
*/
class SplitParameters extends BaseProductParameters
class SplitParameters extends BaseClassificationProductParameters
{
/**
* @var string Slug of the endpoint.
Expand All @@ -20,12 +20,14 @@ class SplitParameters extends BaseProductParameters
* @param string $modelId ID of the model.
* @param string|null $alias Optional file alias.
* @param array<string>|null $webhookIds List of webhook IDs.
* @param string|null $extractionTextContext Additional context for the chained extraction model.
*/
public function __construct(
string $modelId,
?string $alias = null,
?array $webhookIds = null
?array $webhookIds = null,
?string $extractionTextContext = null
) {
parent::__construct($modelId, $alias, $webhookIds);
parent::__construct($modelId, $alias, $webhookIds, $extractionTextContext);
}
}
38 changes: 38 additions & 0 deletions tests/V2/ClientOptions/BaseClassificationProductParametersTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace V2\ClientOptions;

use Mindee\V2\ClientOptions\BaseClassificationProductParameters;
use PHPUnit\Framework\TestCase;
use TypeError;

class BaseClassificationProductParametersTest extends TestCase
{
public function testSerialization(): void
{
$params = new class ('model-id', 'alias', ['first-id', 'second-id']) extends BaseClassificationProductParameters {
public static string $slug = 'test';
};

$expected = ['model_id' => 'model-id', 'alias' => 'alias', 'webhook_ids' => 'first-id,second-id'];
self::assertNull($params->extractionTextContext);
self::assertSame($expected, $params->getRequestParameters());

$params->extractionTextContext = 'context';
self::assertSame($expected + ['extraction_text_context' => 'context'], $params->getRequestParameters());
$params->extractionTextContext = '';
self::assertSame($expected + ['extraction_text_context' => ''], $params->getRequestParameters());
$params->extractionTextContext = null;
self::assertSame($expected, $params->getRequestParameters());
}

public function testRejectsNonStringContext(): void
{
$this->expectException(TypeError::class);
new class ('model-id', null, null, 123) extends BaseClassificationProductParameters {
public static string $slug = 'test';
};
}
}
Loading