|
22 | 22 | use Mindee\V2\Parsing\Error\ErrorResponse; |
23 | 23 | use Mindee\V2\Parsing\Inference\BaseResponse; |
24 | 24 | use Mindee\V2\Parsing\Job\JobResponse; |
| 25 | +use Mindee\V2\Parsing\Search\SearchResponse; |
25 | 26 | use ReflectionClass; |
26 | 27 | use ReflectionException; |
27 | 28 | use ReflectionProperty; |
@@ -106,7 +107,7 @@ public function __construct(?string $apiKey) |
106 | 107 | throw new MindeeException( |
107 | 108 | "Missing API key for call," |
108 | 109 | . " check your Client configuration.You can set this using the " |
109 | | - . API_KEY_ENV_NAME . ' environment variable.', |
| 110 | + . API_V2_KEY_ENV_NAME . ' environment variable.', |
110 | 111 | ErrorCode::USER_INPUT_ERROR |
111 | 112 | ); |
112 | 113 | } |
@@ -386,4 +387,44 @@ private function checkValidResponse(array $result): void |
386 | 387 | throw new MindeeV2HttpUnknownException(json_encode($result, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT)); |
387 | 388 | } |
388 | 389 | } |
| 390 | + |
| 391 | + /** |
| 392 | + * @return array<string, integer|float|string|bool|null|array<mixed>> Server response. |
| 393 | + */ |
| 394 | + private function reqGetSearchModels(?string $modelName = null, ?string $modelType = null): array |
| 395 | + { |
| 396 | + $url = $this->baseUrl . "/v2/search/models"; |
| 397 | + $params = []; |
| 398 | + if ($modelName) { |
| 399 | + $params['name'] = $modelName; |
| 400 | + } |
| 401 | + if ($modelType) { |
| 402 | + $params['model_type'] = $modelType; |
| 403 | + } |
| 404 | + if (!empty($params)) { |
| 405 | + $url .= '?' . http_build_query($params); |
| 406 | + } |
| 407 | + |
| 408 | + $ch = $this->initChannel(); |
| 409 | + curl_setopt($ch, CURLOPT_URL, $url); |
| 410 | + curl_setopt($ch, CURLOPT_HTTPGET, true); |
| 411 | + |
| 412 | + $resp = [ |
| 413 | + 'data' => curl_exec($ch), |
| 414 | + 'code' => curl_getinfo($ch, CURLINFO_HTTP_CODE), |
| 415 | + ]; |
| 416 | + curl_close($ch); |
| 417 | + return $resp; |
| 418 | + } |
| 419 | + |
| 420 | + /** |
| 421 | + * Retrieves a list of models based on criteria. |
| 422 | + * @param string|null $modelName Optional model name to filter by. |
| 423 | + * @param string|null $modelType Optional model type to filter by. |
| 424 | + * @return SearchResponse The list of models matching the criteria. |
| 425 | + */ |
| 426 | + public function searchModels(?string $modelName = null, ?string $modelType = null): SearchResponse |
| 427 | + { |
| 428 | + return $this->processResponse(SearchResponse::class, $this->reqGetSearchModels($modelName, $modelType)); |
| 429 | + } |
389 | 430 | } |
0 commit comments