-
Notifications
You must be signed in to change notification settings - Fork 4
✨ add support for model search #193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Mindee\V2\Parsing\Search; | ||
|
|
||
| use Stringable; | ||
|
|
||
| /** | ||
| * Model webhook information. | ||
| */ | ||
| class ModelWebhook implements Stringable | ||
| { | ||
| /** | ||
| * @var string ID of the webhook. | ||
| */ | ||
| public string $id; | ||
| /** | ||
| * @var string Name of the webhook. | ||
| */ | ||
| public string $name; | ||
| /** | ||
| * @var string URL of the webhook. | ||
| */ | ||
| public string $url; | ||
|
|
||
| /** | ||
| * @param array<string, int|float|string|bool|null|array<array-key, mixed>> $rawResponse | ||
| */ | ||
| public function __construct(array $rawResponse) | ||
| { | ||
| $this->id = $rawResponse['id']; | ||
| $this->name = $rawResponse['name']; | ||
| $this->url = $rawResponse['url']; | ||
| } | ||
|
|
||
| public function __toString(): string | ||
| { | ||
| return ":Name: $this->name\n" | ||
| . ":ID: $this->id\n" | ||
| . ":URL: $this->url\n"; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Mindee\V2\Parsing\Search; | ||
|
|
||
| use Stringable; | ||
|
|
||
| /** | ||
| * Pagination metadata. | ||
| */ | ||
| class PaginationMetadata implements Stringable | ||
| { | ||
| /** | ||
| * @var integer Number of items per page. | ||
| */ | ||
| public int $perPage; | ||
| /** | ||
| * @var integer 1-indexed page number. | ||
| */ | ||
| public int $page; | ||
| /** | ||
| * @var integer Total number of items. | ||
| */ | ||
| public int $totalItems; | ||
| /** | ||
| * @var integer Total number of pages. | ||
| */ | ||
| public int $totalPages; | ||
|
|
||
| /** | ||
| * @param array<string, int|float|string|bool|null|array<array-key, mixed>> $rawResponse Raw server response array. | ||
| */ | ||
| public function __construct(array $rawResponse) | ||
| { | ||
| $this->perPage = $rawResponse['per_page']; | ||
| $this->page = $rawResponse['page']; | ||
| $this->totalItems = $rawResponse['total_items']; | ||
| $this->totalPages = $rawResponse['total_pages']; | ||
| } | ||
|
|
||
| /** | ||
| * @return string String representation. | ||
| */ | ||
| public function __toString(): string | ||
| { | ||
| return ":Per Page: $this->perPage\n" | ||
| . ":Page: $this->page\n" | ||
| . ":Total Items: $this->totalItems\n" | ||
| . ":Total Pages: $this->totalPages\n"; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Mindee\V2\Parsing\Search; | ||
|
|
||
| use Stringable; | ||
|
|
||
| /** | ||
| * Individual model information. | ||
| */ | ||
| class SearchModel implements Stringable | ||
| { | ||
| /** | ||
| * @var string Model ID. | ||
| */ | ||
| public string $id; | ||
| /** | ||
| * @var string Model name. | ||
| */ | ||
| public string $name; | ||
| /** | ||
| * @var string Model type. | ||
| */ | ||
| public string $modelType; | ||
| /** | ||
| * @var array<ModelWebhook> List of webhooks associated with the model. | ||
| */ | ||
| public array $webhooks; | ||
|
|
||
| /** | ||
| * @param array<string, int|float|string|bool|null|array<array-key, mixed>> $rawResponse Raw server response array. | ||
| */ | ||
| public function __construct(array $rawResponse) | ||
| { | ||
| $this->id = $rawResponse['id']; | ||
| $this->name = $rawResponse['name']; | ||
| $this->modelType = $rawResponse['model_type']; | ||
| $this->webhooks = array_map( | ||
| static fn($webhook) => new ModelWebhook($webhook), | ||
| $rawResponse['webhooks'] ?? [] | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * @return string String representation. | ||
| */ | ||
| public function __toString(): string | ||
| { | ||
| return ":Name: $this->name\n" | ||
| . ":ID: $this->id\n" | ||
| . ":Model Type: $this->modelType\n" | ||
| . ":Webhooks: " . implode(', ', array_map(static fn($webhook) => $webhook->name, $this->webhooks)) . "\n"; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Mindee\V2\Parsing\Search; | ||
|
|
||
| use ArrayObject; | ||
| use Stringable; | ||
|
|
||
| use function count; | ||
|
|
||
| /** | ||
| * Array of search models. | ||
| * @extends ArrayObject<int, SearchModel> | ||
| */ | ||
| class SearchModels extends ArrayObject implements Stringable | ||
| { | ||
| /** | ||
| * @param array<array<string, int|float|string|bool|null|array<array-key, mixed>>> $prediction Raw prediction. | ||
| */ | ||
| public function __construct(array $prediction) | ||
| { | ||
| $models = array_map(static fn($entry) => new SearchModel($entry), $prediction); | ||
|
|
||
| parent::__construct($models); | ||
| } | ||
|
|
||
| /** | ||
| * Default string representation. | ||
| */ | ||
| public function __toString(): string | ||
| { | ||
| if ($this->count() === 0) { | ||
| return "\n"; | ||
| } | ||
|
|
||
| $lines = []; | ||
| foreach ($this as $model) { | ||
| $lines[] = "* :Name: " . $model->name; | ||
| $lines[] = " :ID: " . $model->id; | ||
| $lines[] = " :Model Type: " . $model->modelType; | ||
| $lines[] = " :Webhooks: " . count($model->webhooks); | ||
| } | ||
|
|
||
| return implode("\n", $lines) . "\n"; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Mindee\V2\Parsing\Search; | ||
|
|
||
| use Mindee\V2\Parsing\Inference\BaseResponse; | ||
| use Stringable; | ||
|
|
||
| /** | ||
| * Models search response. | ||
| */ | ||
| class SearchResponse extends BaseResponse implements Stringable | ||
| { | ||
| /** | ||
| * @var SearchModels Parsed search payload. | ||
| */ | ||
| public SearchModels $models; | ||
|
|
||
| /** | ||
| * @var PaginationMetadata Pagination metadata for the search results. | ||
| */ | ||
| public PaginationMetadata $paginationMetadata; | ||
|
|
||
| /** | ||
| * @param array<string, int|float|string|bool|null|array<array-key, mixed>> $rawResponse Raw server response array. | ||
| */ | ||
| public function __construct(array $rawResponse) | ||
| { | ||
| parent::__construct($rawResponse); | ||
| $this->models = new SearchModels($rawResponse['models']); | ||
| $this->paginationMetadata = new PaginationMetadata($rawResponse['pagination']); | ||
| } | ||
|
|
||
| /** | ||
| * @return string String representation. | ||
| */ | ||
| public function __toString(): string | ||
| { | ||
| return implode("\n", [ | ||
| 'Models', | ||
| '######', | ||
| (string) $this->models, | ||
| 'Pagination Metadata', | ||
| '###################', | ||
| (string) $this->paginationMetadata, | ||
| '', | ||
| ]); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| <?php | ||
|
|
||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace V2\Parsing; | ||
|
|
||
| use DateTime; | ||
| use Mindee\V2\Parsing\Error\ErrorItem; | ||
| use Mindee\V2\Parsing\Error\ErrorResponse; | ||
| use Mindee\V2\Parsing\Job\JobResponse; | ||
| use Mindee\V2\Parsing\Search\SearchModel; | ||
| use Mindee\V2\Parsing\Search\SearchResponse; | ||
| use PHPUnit\Framework\TestCase; | ||
| use TestingUtilities; | ||
|
|
||
| require_once(__DIR__ . "/../../TestingUtilities.php"); | ||
|
|
||
| /** | ||
| * InferenceV2 – field integrity checks | ||
| */ | ||
| class SearchResponseTest extends TestCase | ||
| { | ||
| public function testSearchResponse(): void | ||
| { | ||
| $fullPath = TestingUtilities::getV2DataDir() . "/search/models.json"; | ||
| $content = file_get_contents($fullPath); | ||
| $json = json_decode($content, true); | ||
| $response = new SearchResponse($json); | ||
| self::assertNotEmpty($response->models); | ||
| foreach ($response->models as $model) { | ||
| self::assertInstanceOf(SearchModel::class, $model); | ||
| self::assertNotEmpty($model->id); | ||
| self::assertNotEmpty($model->name); | ||
| } | ||
| self::assertCount(2, $response->models[0]->webhooks); | ||
| self::assertEquals("https://failure.mindee.com", $response->models[0]->webhooks[0]->url); | ||
|
|
||
| self::assertEquals(50, $response->paginationMetadata->perPage); | ||
| self::assertEquals(1, $response->paginationMetadata->page); | ||
| self::assertGreaterThanOrEqual(5, $response->paginationMetadata->totalItems); | ||
| self::assertEquals(1, $response->paginationMetadata->totalPages); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.