Skip to main content

ModelAdapter

Trait ModelAdapter 

Source
pub trait ModelAdapter:
    Send
    + Sync
    + Debug {
    type Task: Task;

    // Required methods
    fn info(&self) -> AdapterInfo;
    fn execute(
        &self,
        input: <Self::Task as Task>::Input,
        config: Option<&<Self::Task as Task>::Config>,
    ) -> Result<<Self::Task as Task>::Output, OCRError>;

    // Provided methods
    fn schema(&self) -> TaskSchema { ... }
    fn validate_compatibility(
        &self,
        schema: &TaskSchema,
    ) -> Result<(), OCRError> { ... }
    fn supports_batching(&self) -> bool { ... }
    fn recommended_batch_size(&self) -> usize { ... }
}
Expand description

Core trait for model adapters.

Adapters bridge the gap between task interfaces and concrete model implementations. They handle model-specific preprocessing, inference, and postprocessing while conforming to the task’s input/output schema.

Required Associated Types§

Source

type Task: Task

The task type this adapter executes

Required Methods§

Source

fn info(&self) -> AdapterInfo

Returns information about this adapter.

Source

fn execute( &self, input: <Self::Task as Task>::Input, config: Option<&<Self::Task as Task>::Config>, ) -> Result<<Self::Task as Task>::Output, OCRError>

Executes the model on the given input.

This method handles the complete pipeline:

  1. Validate input
  2. Preprocess
  3. Run inference
  4. Postprocess
  5. Validate output
§Arguments
  • input - The task input to process
  • config - Optional configuration for execution
§Returns

The task output or an error

Provided Methods§

Source

fn schema(&self) -> TaskSchema

Returns the schema that this adapter conforms to.

Source

fn validate_compatibility(&self, schema: &TaskSchema) -> Result<(), OCRError>

Validates that this adapter is compatible with the given task schema.

§Arguments
  • schema - The schema to check compatibility with
§Returns

Result indicating success or incompatibility error

Source

fn supports_batching(&self) -> bool

Returns whether this adapter can handle batched inputs efficiently.

Source

fn recommended_batch_size(&self) -> usize

Returns the recommended batch size for this adapter.

Implementors§