From 2f80fccaaf52bb91414086439b662f104507c0dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ianar=C3=A9=20s=C3=A9vi?= Date: Tue, 24 Nov 2026 15:01:26 +0100 Subject: [PATCH] :sparkles: pass text context to chained model --- .gitignore | 1 + AGENTS.md | 18 +++++++++ .../BaseClassificationProductParameters.php | 38 +++++++++++++++++++ .../Params/ClassificationParameters.php | 10 +++-- src/V2/Product/Crop/Params/CropParameters.php | 10 +++-- .../Product/Split/Params/SplitParameters.php | 10 +++-- ...aseClassificationProductParametersTest.php | 38 +++++++++++++++++++ 7 files changed, 113 insertions(+), 12 deletions(-) create mode 100644 AGENTS.md create mode 100644 src/V2/ClientOptions/BaseClassificationProductParameters.php create mode 100644 tests/V2/ClientOptions/BaseClassificationProductParametersTest.php diff --git a/.gitignore b/.gitignore index 818808e9..e57772a6 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ composer.lock # IDE .vscode/ .idea +.junie # Mac OS .DS_Store diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 00000000..6577e4af --- /dev/null +++ b/AGENTS.md @@ -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. diff --git a/src/V2/ClientOptions/BaseClassificationProductParameters.php b/src/V2/ClientOptions/BaseClassificationProductParameters.php new file mode 100644 index 00000000..ee122ca0 --- /dev/null +++ b/src/V2/ClientOptions/BaseClassificationProductParameters.php @@ -0,0 +1,38 @@ +|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 Request parameters. + */ + public function getRequestParameters(): array + { + $outHash = parent::getRequestParameters(); + if ($this->extractionTextContext !== null) { + $outHash['extraction_text_context'] = $this->extractionTextContext; + } + return $outHash; + } +} diff --git a/src/V2/Product/Classification/Params/ClassificationParameters.php b/src/V2/Product/Classification/Params/ClassificationParameters.php index 523359f4..4a9b8b01 100644 --- a/src/V2/Product/Classification/Params/ClassificationParameters.php +++ b/src/V2/Product/Classification/Params/ClassificationParameters.php @@ -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. @@ -20,12 +20,14 @@ class ClassificationParameters extends BaseProductParameters * @param string $modelId ID of the model. * @param string|null $alias Optional file alias. * @param array|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); } } diff --git a/src/V2/Product/Crop/Params/CropParameters.php b/src/V2/Product/Crop/Params/CropParameters.php index 1adae2b3..8d161060 100644 --- a/src/V2/Product/Crop/Params/CropParameters.php +++ b/src/V2/Product/Crop/Params/CropParameters.php @@ -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. @@ -20,12 +20,14 @@ class CropParameters extends BaseProductParameters * @param string $modelId ID of the model. * @param string|null $alias Optional file alias. * @param array|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); } } diff --git a/src/V2/Product/Split/Params/SplitParameters.php b/src/V2/Product/Split/Params/SplitParameters.php index fbc42a03..1850bd89 100644 --- a/src/V2/Product/Split/Params/SplitParameters.php +++ b/src/V2/Product/Split/Params/SplitParameters.php @@ -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. @@ -20,12 +20,14 @@ class SplitParameters extends BaseProductParameters * @param string $modelId ID of the model. * @param string|null $alias Optional file alias. * @param array|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); } } diff --git a/tests/V2/ClientOptions/BaseClassificationProductParametersTest.php b/tests/V2/ClientOptions/BaseClassificationProductParametersTest.php new file mode 100644 index 00000000..41076621 --- /dev/null +++ b/tests/V2/ClientOptions/BaseClassificationProductParametersTest.php @@ -0,0 +1,38 @@ + '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'; + }; + } +}