Skip to content
Open
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
6 changes: 3 additions & 3 deletions bin/V2/BaseInferenceCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Mindee\Input\PathInput;
use Mindee\Input\UrlInputSource;
use Mindee\V2\Client;
use Mindee\V2\ClientOptions\BaseParameters;
use Mindee\V2\ClientOptions\BaseProductParameters;
use Mindee\V2\Error\MindeeV2HttpException;
use Mindee\V2\Parsing\Inference\BaseResponse;
use Symfony\Component\Console\Command\Command;
Expand Down Expand Up @@ -177,13 +177,13 @@ private function resolveInputSource(string $path): PathInput|UrlInputSource|null
* @param InputInterface $input CLI input, used to read product-specific options.
* @param string $modelId Model identifier.
* @param string|null $alias Optional alias.
* @return BaseParameters Parameters object for the V2 client.
* @return BaseProductParameters Parameters object for the V2 client.
*/
abstract protected function buildParameters(
InputInterface $input,
string $modelId,
?string $alias
): BaseParameters;
): BaseProductParameters;

/**
* @return class-string<BaseResponse> Fully-qualified product response class.
Expand Down
4 changes: 2 additions & 2 deletions bin/V2/ClassificationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Mindee\Cli\V2;

use Mindee\V2\ClientOptions\BaseParameters;
use Mindee\V2\ClientOptions\BaseProductParameters;
use Mindee\V2\Product\Classification\ClassificationResponse;
use Mindee\V2\Product\Classification\Params\ClassificationParameters;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -37,7 +37,7 @@ protected function buildParameters(
InputInterface $input,
string $modelId,
?string $alias
): BaseParameters {
): BaseProductParameters {
return new ClassificationParameters($modelId, $alias);
}
}
4 changes: 2 additions & 2 deletions bin/V2/CropCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Mindee\Cli\V2;

use Mindee\V2\ClientOptions\BaseParameters;
use Mindee\V2\ClientOptions\BaseProductParameters;
use Mindee\V2\Product\Crop\CropResponse;
use Mindee\V2\Product\Crop\Params\CropParameters;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -37,7 +37,7 @@ protected function buildParameters(
InputInterface $input,
string $modelId,
?string $alias
): BaseParameters {
): BaseProductParameters {
return new CropParameters($modelId, $alias);
}
}
4 changes: 2 additions & 2 deletions bin/V2/ExtractionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Mindee\Cli\V2;

use Mindee\V2\ClientOptions\BaseParameters;
use Mindee\V2\ClientOptions\BaseProductParameters;
use Mindee\V2\Parsing\Inference\BaseResponse;
use Mindee\V2\Product\Extraction\ExtractionResponse;
use Mindee\V2\Product\Extraction\Params\ExtractionParameters;
Expand Down Expand Up @@ -76,7 +76,7 @@ protected function buildParameters(
InputInterface $input,
string $modelId,
?string $alias
): BaseParameters {
): BaseProductParameters {
$rag = (bool) $input->getOption('rag');
$rawText = (bool) $input->getOption('raw-text');
$confidence = (bool) $input->getOption('confidence');
Expand Down
4 changes: 2 additions & 2 deletions bin/V2/OcrCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Mindee\Cli\V2;

use Mindee\V2\ClientOptions\BaseParameters;
use Mindee\V2\ClientOptions\BaseProductParameters;
use Mindee\V2\Product\Ocr\OcrResponse;
use Mindee\V2\Product\Ocr\Params\OcrParameters;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -37,7 +37,7 @@ protected function buildParameters(
InputInterface $input,
string $modelId,
?string $alias
): BaseParameters {
): BaseProductParameters {
return new OcrParameters($modelId, $alias);
}
}
5 changes: 4 additions & 1 deletion bin/V2/SearchModelsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Exception;
use Mindee\V2\Client;
use Mindee\V2\Error\MindeeV2HttpException;
use Mindee\V2\Search\Models\ModelSearchParameters;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand Down Expand Up @@ -83,7 +84,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$client = new Client($apiKey ?: null);

try {
$response = $client->searchModels($name ?: null, $modelType ?: null);
$response = $client->searchModels(
new ModelSearchParameters($name ?: null, $modelType ?: null)
);
} catch (MindeeV2HttpException $e) {
$output->writeln('<error>' . $e->getMessage() . '</error>');
return Command::FAILURE;
Expand Down
103 changes: 103 additions & 0 deletions bin/V2/SearchRagDocumentsCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php

declare(strict_types=1);

namespace Mindee\Cli\V2;

use Exception;
use Mindee\V2\Client;
use Mindee\V2\Error\MindeeV2HttpException;
use Mindee\V2\Search\RagDocuments\RagDocumentSearchParameters;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

/**
* V2 `search-rag-docs` CLI command.
*
* Mirrors the canonical .NET implementation in
* `mindee-api-dotnet/src/Mindee.Cli/Commands/V2/SearchRagDocumentsCommand.cs`.
*/
class SearchRagDocumentsCommand extends Command
{
/**
* @return void Configure command options/arguments.
*/
protected function configure(): void
{
$this
->setName('search-rag-docs')
->setDescription('Search available RAG documents for a given model.')
->addOption(
'api-key',
'k',
InputOption::VALUE_REQUIRED,
'Mindee V2 API key. Falls back to the MINDEE_V2_API_KEY environment variable.'
)
->addOption(
'model-id',
'm',
InputOption::VALUE_REQUIRED,
'Filter by model ID.'
)
->addOption(
'filename',
'f',
InputOption::VALUE_REQUIRED,
'Filter by file name partial match (case insensitive).'
)
->addOption(
'raw-json',
'r',
InputOption::VALUE_NONE,
'Whether to output the raw JSON response.'
);
}

/**
* @param InputInterface $input CLI input.
* @param OutputInterface $output CLI output.
* @return integer Exit code.
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$apiKey = $input->getOption('api-key');
if (!$apiKey && !getenv('MINDEE_V2_API_KEY')) {
$output->writeln(
'<error>The Mindee V2 API key is missing. '
. "Please provide it via the '--api-key' option or the MINDEE_V2_API_KEY environment variable.</error>"
);
return Command::FAILURE;
}

$modelId = $input->getOption('model-id');
if (!$modelId) {
$output->writeln('<error>The --model-id option is required.</error>');
return Command::FAILURE;
}
$filename = $input->getOption('filename');
$raw = (bool) $input->getOption('raw-json');

$client = new Client($apiKey ?: null);

try {
$response = $client->searchRagDocuments(
new RagDocumentSearchParameters($modelId, $filename ?: null)
);
} catch (MindeeV2HttpException $e) {
$output->writeln('<error>' . $e->getMessage() . '</error>');
return Command::FAILURE;
} catch (Exception $e) {
$output->writeln("<error>Something went wrong, '" . $e->getMessage() . "' was raised.</error>");
return Command::FAILURE;
}

if ($raw) {
$output->writeln($response->getRawHttp());
} else {
$output->write((string) $response);
}
return Command::SUCCESS;
}
}
4 changes: 2 additions & 2 deletions bin/V2/SplitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Mindee\Cli\V2;

use Mindee\V2\ClientOptions\BaseParameters;
use Mindee\V2\ClientOptions\BaseProductParameters;
use Mindee\V2\Product\Split\Params\SplitParameters;
use Mindee\V2\Product\Split\SplitResponse;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -37,7 +37,7 @@ protected function buildParameters(
InputInterface $input,
string $modelId,
?string $alias
): BaseParameters {
): BaseProductParameters {
return new SplitParameters($modelId, $alias);
}
}
5 changes: 4 additions & 1 deletion bin/cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
require __DIR__ . '/V2/OcrCommand.php';
require __DIR__ . '/V2/SplitCommand.php';
require __DIR__ . '/V2/SearchModelsCommand.php';
require __DIR__ . '/V2/SearchRagDocumentsCommand.php';

use Exception;
use Mindee\Cli\V2\ClassificationCommand;
use Mindee\Cli\V2\CropCommand;
use Mindee\Cli\V2\ExtractionCommand;
use Mindee\Cli\V2\OcrCommand;
use Mindee\Cli\V2\SearchModelsCommand;
use Mindee\Cli\V2\SearchRagDocumentsCommand;
use Mindee\Cli\V2\SplitCommand;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
Expand Down Expand Up @@ -139,8 +141,9 @@ function mindeeRewriteArgvForV1Compat(array $argv, array $knownTopLevelCommands)
$cli->add($command);
}
$cli->add(new SearchModelsCommand());
$cli->add(new SearchRagDocumentsCommand());

$knownTopLevelCommands = ['v1', 'search-models', 'list', 'help', 'completion'];
$knownTopLevelCommands = ['v1', 'search-models', 'search-rag-docs', 'list', 'help', 'completion'];
foreach ($v2InferenceCommands as $command) {
$knownTopLevelCommands[] = $command->getName();
}
Expand Down
51 changes: 51 additions & 0 deletions src/Parsing/DateHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

declare(strict_types=1);

namespace Mindee\Parsing;

use DateTime;
use DateTimeImmutable;
use Exception;

/**
* Utility class to parse date strings returned by the API.
*/
class DateHelper
{
/**
* Parse a date string into a DateTime object.
*
* @param string|null $dateString Date string to parse.
* @return DateTime|null Parsed date, or null if empty/invalid.
*/
public static function parseDate(?string $dateString): ?DateTime
{
if (empty($dateString)) {
return null;
}
try {
return new DateTime($dateString);
} catch (Exception) {
return null;
}
}

/**
* Parse a date string into a DateTimeImmutable object.
*
* @param string|null $dateString Date string to parse.
* @return DateTimeImmutable|null Parsed date, or null if empty/invalid.
*/
public static function parseDateImmutable(?string $dateString): ?DateTimeImmutable
{
if (empty($dateString)) {
return null;
}
try {
return new DateTimeImmutable($dateString);
} catch (Exception) {
return null;
}
}
}
Loading
Loading