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: 0 additions & 1 deletion bin/V2/SearchModelsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int

try {
$response = $client->search(
ModelSearchResponse::class,
new ModelSearchParameters($name ?: null, $modelType ?: null)
);
} catch (MindeeV2HttpException $e) {
Expand Down
1 change: 0 additions & 1 deletion bin/V2/SearchRagDocumentsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int

try {
$response = $client->search(
RagDocumentSearchResponse::class,
new RagDocumentSearchParameters($modelId, $filename ?: null)
);
} catch (MindeeV2HttpException $e) {
Expand Down
12 changes: 4 additions & 8 deletions src/V2/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public function enqueue(
return $this->mindeeApi->reqPostEnqueue($inputSource, $params);
}


/**
* @template T of BaseResponse
* @param string $responseClass The response class to construct.
Expand Down Expand Up @@ -255,27 +254,24 @@ public function deleteExtractionRagDocument(string $documentId): bool
* Searches for resources matching the given criteria.
*
* @template T of BaseSearchResponse
* @param string $responseClass The response class to construct.
* @phpstan-param class-string<T> $responseClass
* @param BaseSearchParameters $params Search parameters.
* @param BaseSearchParameters<T> $params Search parameters.
* @return T
*/
public function search(string $responseClass, BaseSearchParameters $params): BaseSearchResponse
public function search(BaseSearchParameters $params): BaseSearchResponse
Comment thread
ianardee marked this conversation as resolved.
{
return $this->mindeeApi->reqGetSearch($responseClass, $params);
return $this->mindeeApi->reqGetSearch($params);
}

/**
* Searches for a list of available models for the given API key.
* @param string|null $modelName Optional model name to filter by.
* @param string|null $modelType Optional model type to filter by.
* @return ModelSearchResponse The list of models matching the criteria.
* @deprecated Use search(ModelSearchResponse::class, new ModelSearchParameters(...)) instead.
* @deprecated Use search(new ModelSearchParameters(...)) instead.
*/
public function searchModels(?string $modelName = null, ?string $modelType = null): ModelSearchResponse
{
return $this->mindeeApi->reqGetSearch(
ModelSearchResponse::class,
new ModelSearchParameters($modelName, $modelType)
);
}
Expand Down
22 changes: 20 additions & 2 deletions src/V2/ClientOptions/BaseSearchParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

namespace Mindee\V2\ClientOptions;

use Mindee\V2\Parsing\Search\BaseSearchResponse;

/**
* Base parameters for searches.
* @template TSearchResponse of BaseSearchResponse
*/
abstract class BaseSearchParameters
{
Expand All @@ -14,6 +17,11 @@ abstract class BaseSearchParameters
*/
public static string $slug;

/**
* @var class-string<TSearchResponse> $responseClass Response class.
*/
protected static string $responseClass;

/**
* @param integer|null $page 1-based page index.
* @param integer|null $perPage Number of items per page.
Expand All @@ -24,11 +32,21 @@ public function __construct(
) {}

/**
* Gets the query parameters for the search request.
* Gets the response class associated with the parameters.
*
* @return class-string<TSearchResponse> Response class.
*/
public function getResponseClass(): string
{
return static::$responseClass;
}

/**
* Gets the request parameters for the search request.
*
* @return array<string, string> Query parameters.
*/
public function getQueryParams(): array
public function getRequestParameters(): array
{
$params = [];
if ($this->page !== null && $this->page > 0) {
Expand Down
10 changes: 4 additions & 6 deletions src/V2/Http/MindeeApiV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -524,14 +524,12 @@ public function reqDeleteExtractionRagDocument(string $documentId): bool
* Makes a GET call to a search endpoint and returns the deserialized response.
*
* @template T of BaseSearchResponse
* @param string $responseClass The response class to construct.
* @phpstan-param class-string<T> $responseClass
* @param BaseSearchParameters $params Search parameters (slug and query params derived from this).
* @param BaseSearchParameters<T> $params Search parameters (slug and query params derived from this).
* @return T
*/
public function reqGetSearch(string $responseClass, BaseSearchParameters $params): BaseResponse
public function reqGetSearch(BaseSearchParameters $params): BaseResponse
Comment thread
ianardee marked this conversation as resolved.
{
$queryParams = $params->getQueryParams();
$queryParams = $params->getRequestParameters();
$url = $this->baseUrl . "/v2/search/" . $params::$slug;
if (!empty($queryParams)) {
$url .= '?' . http_build_query($queryParams);
Expand All @@ -546,6 +544,6 @@ public function reqGetSearch(string $responseClass, BaseSearchParameters $params
'code' => curl_getinfo($ch, CURLINFO_HTTP_CODE),
];
curl_close($ch);
return $this->deserializeResponse($responseClass, $resp);
return $this->deserializeResponse($params->getResponseClass(), $resp);
}
}
18 changes: 15 additions & 3 deletions src/V2/Search/Models/ModelSearchParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@
use Mindee\V2\ClientOptions\BaseSearchParameters;

/**
* Search parameters for models.
* Search for models within the organization linked to the API key.
*
* All search filters are optional.
* If no search filters are given, all models belonging to the organization are returned.
*
* Results are paginated.
*
* @extends BaseSearchParameters<ModelSearchResponse>
*/
class ModelSearchParameters extends BaseSearchParameters
{
Expand All @@ -16,6 +23,11 @@ class ModelSearchParameters extends BaseSearchParameters
*/
public static string $slug = "models";

/**
* @var class-string<ModelSearchResponse> Response class.
*/
protected static string $responseClass = ModelSearchResponse::class;

/**
* @param string|null $name Case-insensitive search term for the model name.
* @param string|null $modelType Case-insensitive search term for the model type.
Expand All @@ -34,9 +46,9 @@ public function __construct(
/**
* @return array<string, string> Query parameters.
*/
public function getQueryParams(): array
public function getRequestParameters(): array
{
$params = parent::getQueryParams();
$params = parent::getRequestParameters();
if (!empty($this->name)) {
$params['name'] = $this->name;
}
Expand Down
20 changes: 16 additions & 4 deletions src/V2/Search/RagDocuments/RagDocumentSearchParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@
use Mindee\V2\ClientOptions\BaseSearchParameters;

/**
* Search parameters for RAG documents.
* Search for RAG documents within the organization linked to the API key.
*
* The model ID is required, search filters are optional.
* If no search filters are given, all documents linked to the model are returned.
*
* Results are paginated.
*
* @extends BaseSearchParameters<RagDocumentSearchResponse>
*/
class RagDocumentSearchParameters extends BaseSearchParameters
{
Expand All @@ -18,11 +25,16 @@ class RagDocumentSearchParameters extends BaseSearchParameters
*/
public static string $slug = "rag-documents";

/**
* @var class-string<RagDocumentSearchResponse> Response class.
*/
protected static string $responseClass = RagDocumentSearchResponse::class;

/**
* @param string|null $modelId Model identifier to search in (required).
* @param string|null $filename Case-insensitive substring search on filename.
* @param integer|null $page 1-based page index.
* @param integer|null $perPage Number of items per page.
* @param integer|null $perPage Number of result items per page.
*/
public function __construct(
public ?string $modelId = null,
Expand All @@ -37,9 +49,9 @@ public function __construct(
* @return array<string, string> Query parameters.
* @throws MindeeException Throws if the model ID is not provided.
*/
public function getQueryParams(): array
public function getRequestParameters(): array
{
$params = parent::getQueryParams();
$params = parent::getRequestParameters();
if (!empty($this->modelId)) {
$params['model_id'] = $this->modelId;
} else {
Expand Down
4 changes: 1 addition & 3 deletions tests/V2/Search/ModelSearchFunctional.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Mindee\V2\Client;
use Mindee\V2\Search\Models\ModelSearchParameters;
use Mindee\V2\Search\Models\ModelSearchResponse;
use PHPUnit\Framework\TestCase;

class ModelSearchFunctional extends TestCase
Expand All @@ -20,7 +19,7 @@ protected function setUp(): void

public function testModelSearch_mustHaveResults(): void
{
$response = $this->client->search(ModelSearchResponse::class, new ModelSearchParameters());
$response = $this->client->search(new ModelSearchParameters());

self::assertNotNull($response);
self::assertNotNull($response->models);
Expand All @@ -33,7 +32,6 @@ public function testModelSearch_mustHaveResults(): void
public function testModelSearch_mustReturnEmpty(): void
{
$response = $this->client->search(
ModelSearchResponse::class,
new ModelSearchParameters(name: "je n'existe pas tralala")
);

Expand Down
2 changes: 0 additions & 2 deletions tests/V2/Search/RagDocumentSearchFunctional.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Mindee\V2\Client;
use Mindee\V2\Search\RagDocuments\RagDocumentSearchParameters;
use Mindee\V2\Search\RagDocuments\RagDocumentSearchResponse;
use PHPUnit\Framework\TestCase;

class RagDocumentSearchFunctional extends TestCase
Expand All @@ -23,7 +22,6 @@ protected function setUp(): void
public function testRagDocumentSearch_mustHaveResults(): void
{
$response = $this->client->search(
RagDocumentSearchResponse::class,
new RagDocumentSearchParameters(modelId: $this->findocModelId)
);

Expand Down
Loading