Sycophant.Registry (sycophant v0.4.2)

Copy Markdown

Extensible registry for auth strategies and wire protocols.

Built-in adapters are seeded when the Sycophant application starts. Library users can register additional adapters from their own Application.start/2:

Sycophant.Registry.register_auth!(:my_provider, MyApp.Auth.Custom)
Sycophant.Registry.register_protocol!(:chat, :my_proto, MyApp.WireProtocol.Custom)
Sycophant.Registry.register_protocol!(:embedding, :my_embed, MyApp.EmbeddingProto.Custom)

Overriding a built-in key is allowed -- the last registration wins.

Summary

Functions

Looks up the auth strategy module for provider.

Looks up the protocol adapter module for the given kind and protocol_name.

Registers a custom authentication strategy for the given provider.

Registers a custom protocol adapter under the given kind and protocol_name.

Types

kind()

@type kind() :: :chat | :embedding

Functions

fetch_auth(provider)

@spec fetch_auth(atom()) :: {:ok, module()} | :error

Looks up the auth strategy module for provider.

fetch_protocol(kind, protocol_name)

@spec fetch_protocol(kind(), atom()) :: {:ok, module()} | :error

Looks up the protocol adapter module for the given kind and protocol_name.

register_auth!(provider, module)

@spec register_auth!(atom(), module()) :: :ok

Registers a custom authentication strategy for the given provider.

The module must implement the Sycophant.Auth behaviour. Raises Sycophant.Error.Invalid.InvalidRegistration if it does not.

Sycophant.Registry.register_auth!(:my_provider, MyApp.Auth.Custom)

register_protocol!(kind, protocol_name, module)

@spec register_protocol!(kind(), atom(), module()) :: :ok

Registers a custom protocol adapter under the given kind and protocol_name.

The module must implement Sycophant.WireProtocol for :chat kind or Sycophant.EmbeddingWireProtocol for :embedding kind. Raises Sycophant.Error.Invalid.InvalidRegistration if it does not.

Sycophant.Registry.register_protocol!(:chat, :my_proto, MyApp.WireProtocol.Custom)
Sycophant.Registry.register_protocol!(:embedding, :my_embed, MyApp.EmbeddingProto.Custom)