GenAI.Model.EncoderBehaviour behaviour (GenAI Core v0.2.0)

Link to this section Summary

Link to this section Types

Link to this type

completion()

@type completion() :: any()
@type context() :: any()
@type headers() :: list()
@type json() :: any()
@type message() :: any()
@type messages() :: list()
@type method() :: :get | :post | :put | :delete | :option | :patch
@type model() :: any()
@type options() :: any()
Link to this type

request_body()

@type request_body() :: any()
@type session() :: any()
@type settings() :: map()
@type tool() :: any()
@type tools() :: list() | nil
@type uri() :: url()
@type url() :: String.t()

Link to this section Callbacks

Link to this callback

completion_response(json, model, settings, session, context, options)

@callback completion_response(
  json(),
  model(),
  settings(),
  session(),
  context(),
  options()
) ::
  {:ok, completion()} | {:error, term()}
Link to this callback

default_hyper_params(model, settings, session, context, options)

@callback default_hyper_params(model(), settings(), session(), context(), options()) ::
  {:ok, {settings(), session()}} | {:error, term()}
Link to this callback

encode_message(message, model, session, context, options)

@callback encode_message(message(), model(), session(), context(), options()) ::
  {:ok, {message(), session()}} | {:error, term()}

Format message for provider/model type.

Link to this callback

encode_tool(tool, model, session, context, options)

@callback encode_tool(tool(), model(), session(), context(), options()) ::
  {:ok, {tool(), session()}} | {:error, term()}

Format tool for provider/model type.

Link to this callback

endpoint(model, settings, session, context, options)

@callback endpoint(model(), settings(), session(), context(), options()) ::
  {:ok, {method(), uri()}}
  | {:ok, {{method(), uri()}, session()}}
  | {:error, term()}

Prepare endpoint and method to make inference call to

Link to this callback

headers(model, settings, session, context, options)

@callback headers(model(), settings(), session(), context(), options()) ::
  {:ok, headers()} | {:ok, {headers(), session()}} | {:error, term()}

Prepare request headers

Link to this callback

hyper_params(model, settings, session, context, options)

@callback hyper_params(model(), settings(), session(), context(), options()) ::
  {:ok, {settings(), session()}} | {:error, term()}

Obtain list of hyper params supported by given model including mapping and conditional rules/alterations

Link to this callback

normalize_messages(messages, model, session, context, options)

@callback normalize_messages(messages(), model(), session(), context(), options()) ::
  {:ok, {any(), any()}} | {:error, any()}
Link to this callback

request_body(model, messages, tools, settings, session, context, options)

@callback request_body(
  model(),
  messages(),
  tools(),
  settings(),
  session(),
  context(),
  options()
) ::
  {:ok, headers()} | {:ok, {headers(), session()}} | {:error, term()}

Prepare request body to be passed to inference call.

Link to this callback

with_dynamic_setting(body, setting, model, settings)

@callback with_dynamic_setting(
  body :: term(),
  setting :: term(),
  model :: term(),
  settings :: term()
) ::
  term()

Set setting with dynamic model based logic.

Link to this callback

with_dynamic_setting(body, setting, model, settings, default)

@callback with_dynamic_setting(
  body :: term(),
  setting :: term(),
  model :: term(),
  settings :: term(),
  default :: term()
) :: term()
Link to this callback

with_dynamic_setting_as(body, as_setting, setting, model, settings)

@callback with_dynamic_setting_as(
  body :: term(),
  as_setting :: term(),
  setting :: term(),
  model :: term(),
  settings :: term()
) :: term()

Set setting as_setting with dynamic model based logic.

Link to this callback

with_dynamic_setting_as(body, as_setting, setting, model, settings, default)

@callback with_dynamic_setting_as(
  body :: term(),
  as_setting :: term(),
  setting :: term(),
  model :: term(),
  settings :: term(),
  default :: term()
) :: term()