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
32 changes: 21 additions & 11 deletions mindee/v2/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
from mindee.mindee_http.cancellation_token import CancellationToken
from mindee.parsing.common.common_response import CommonStatus
from mindee.v2.client_options.base_product_parameters import BaseProductParameters
from mindee.v2.client_options.base_search_parameters import (
BaseSearchParameters,
TypeSearchResponse,
)
from mindee.v2.mindee_http.mindee_api_v2 import MindeeAPIV2
from mindee.v2.parsing.inference.base_inference_response import BaseInferenceResponse
from mindee.v2.parsing.job.job_response import JobResponse
Expand Down Expand Up @@ -57,7 +61,7 @@ def enqueue(
:return: A valid inference response.
"""
logger.debug("Enqueuing inference using model: %s", params.model_id)
return self.mindee_api.enqueue(input_source, params)
return self.mindee_api.req_post_product_enqueue(input_source, params)

def get_job(self, job_id: str) -> JobResponse:
"""
Expand All @@ -70,15 +74,15 @@ def get_job(self, job_id: str) -> JobResponse:
"""
logger.debug("Fetching job: %s", job_id)

return self.mindee_api.get_job(job_id)
return self.mindee_api.req_get_job_by_id(job_id)

def get_result(
self,
response_type: type[TypeBaseInferenceResponse],
inference_id: str,
) -> TypeBaseInferenceResponse:
"""
Get the result of an inference that was previously enqueued.
Get the result of an inference that was previously enqueued by its ID.

The inference will only be available after it has finished processing.

Expand All @@ -88,7 +92,7 @@ def get_result(
"""
logger.debug("Fetching result: %s", inference_id)

return self.mindee_api.get_result(response_type, inference_id)
return self.mindee_api.req_get_product_result_by_id(response_type, inference_id)

def get_result_from_url(
self, response_type: type[TypeBaseInferenceResponse], url: str
Expand All @@ -100,7 +104,7 @@ def get_result_from_url(
:param url: URL of the inference to retrieve.
:return: The result of the inference.
"""
return self.mindee_api.get_result_by_url(response_type, url)
return self.mindee_api.req_get_product_result_by_url(response_type, url)

def enqueue_and_get_result(
self,
Expand Down Expand Up @@ -169,17 +173,23 @@ def enqueue_and_get_result(

raise MindeeError(f"Couldn't retrieve document after {try_counter + 1} tries.")

def search(
self, params: BaseSearchParameters[TypeSearchResponse]
) -> TypeSearchResponse:
"""
Search for resources matching the given criteria.
:param params: Search parameters
:return: A search response containing the matching resources
"""
return self.mindee_api.req_search(params)

def search_models(
self, name: str | None = None, model_type: str | None = None
) -> SearchResponse:
"""
Get a list of models matching the provided name and type.

:param name: Name of the model to filter by.
:param model_type: Type of the model to filter by.
:return: A list of models matching the provided criteria.
Deprecated. Use `search` instead.
"""
return self.mindee_api.get_models(name, model_type)
return self.mindee_api.req_get_search_models(name, model_type)

def close(self) -> None:
"""Closes the underlying HTTP client."""
Expand Down
4 changes: 2 additions & 2 deletions mindee/v2/client_options/base_product_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@dataclass
class BaseProductParameters(ABC):
"""Base parameters for sending a document to a product."""
"""Base parameters for sending a file to a Mindee V2 product."""

model_id: str
"""Model ID to use for the inference. Required."""
Expand All @@ -32,7 +32,7 @@ class BaseProductParameters(ABC):
"""Whether to close the file after product."""

_slug: ClassVar[str]
"""Slug of the endpoint."""
"""Slug of the product."""

def get_request_parameters(self) -> dict[str, str | list[str]]:
"""
Expand Down
47 changes: 47 additions & 0 deletions mindee/v2/client_options/base_search_parameters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from abc import ABC
from dataclasses import dataclass
from typing import ClassVar, Generic, TypeVar

from mindee.v2.parsing.search.base_search_response import BaseSearchResponse

TypeSearchResponse = TypeVar("TypeSearchResponse", bound=BaseSearchResponse)


@dataclass(kw_only=True)
class BaseSearchParameters(ABC, Generic[TypeSearchResponse]):
"""Base parameters for searches."""

page: int | None = None
"""1-based page index."""

per_page: int | None = None
"""Number of items per page."""

_slug: ClassVar[str]
"""Slug of the searchable resource."""

_response_class: type[TypeSearchResponse]
"""Response class for the search."""

def get_request_parameters(self) -> dict[str, str | list[str]]:
"""
Gets the request parameters for the search request.

:return: A dict of parameters.
"""
data: dict[str, str | list[str]] = {}

if self.page is not None:
data["page"] = str(self.page)
if self.per_page is not None:
data["per_page"] = str(self.per_page)

return data

def get_slug(self) -> str:
"""Gets the slug of the resource."""
return self._slug

def get_response_class(self) -> type[TypeSearchResponse]:
"""Gets the response class for the search."""
return self._response_class
Loading