Magika.Server (Magika v0.1.0-rc.0)

Copy Markdown View Source

A supervised process that owns a loaded Magika instance.

The server loads the ONNX model and configuration once in init/1 and publishes the resulting Magika.t() into :persistent_term. The model and configuration are immutable and ONNX Runtime inference is thread-safe, so callers fetch the instance with instance/1 and run inference directly in their own process — there is no serialization through the server's mailbox and no per-call copying of the (large) configuration.

The server therefore owns the lifecycle of the instance: it loads it on start and erases the published term on shutdown. It is normally started for you by Magika.Application, but you can also place it in your own supervision tree:

children = [
  {Magika.Server, prediction_mode: :high_confidence}
]

Multiple independently-named servers can coexist:

{Magika.Server, name: MyApp.Magika, model_path: "..."}

and are then addressed via Magika.identify(content, server: MyApp.Magika).

Summary

Functions

Returns a specification to start this module under a supervisor.

The default registered name used when none is given.

Returns the hosted Magika.t() for the given server name.

Returns true if a server with the given name has published its instance.

Starts the server.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

default_name()

@spec default_name() :: atom()

The default registered name used when none is given.

instance(name \\ Magika.Server)

@spec instance(atom()) :: Magika.t()

Returns the hosted Magika.t() for the given server name.

Raises if the named server is not running.

running?(name \\ Magika.Server)

@spec running?(atom()) :: boolean()

Returns true if a server with the given name has published its instance.

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Starts the server.

Accepts all options of Magika.new/1 plus :name (the registered process name, defaulting to Magika.Server).