LazyDoc.Provider behaviour (LazyDoc v0.5.3)

View Source

Main functionality

The module LazyDoc.Provider provides a standard interface for making requests to an external service and processing the responses.

Description

It defines a set of callbacks and functions that allow a user to request a prompt, retrieve documents from a response, and interact with models, enabling flexible integration with various providers that conform to this interface.

Summary

Functions

Returns whether the parameters are valid according to the given callback module.

Returns the documents extracted from the response using the specified callback module.

Returns the result of invoking the model method on the specified callback module with the given model.

Returns the result of the request prompt operation initiated with the provided parameters.

Callbacks

check_parameters?(params)

@callback check_parameters?(params :: keyword()) :: boolean()

get_docs_from_response(response)

@callback get_docs_from_response(response :: Req.Response.t()) :: binary()

model(model)

@callback model(model :: atom()) :: binary()

request_prompt(prompt, model, token, params)

@callback request_prompt(
  prompt :: binary(),
  model :: binary(),
  token :: binary(),
  params :: keyword()
) :: {:ok, Req.Response.t()} | {:error, Exception.t()}

Functions

check_parameters?(callback_module, params)

@spec check_parameters?(callback_module :: module(), params :: keyword()) :: boolean()

Returns whether the parameters are valid according to the given callback module.

Parameters

  • callback_module - the module that contains the check_parameters? method to validate the parameters.
  • params - the parameters to be validated against the callback module's method.

Description

Invokes the check_parameters? method on the specified callback module to verify the validity of the provided parameters.

get_docs_from_response(callback_module, response)

@spec get_docs_from_response(
  callback_module :: module(),
  response :: Req.Response.t()
) :: binary()

Returns the documents extracted from the response using the specified callback module.

Parameters

  • callback_module - the module responsible for handling the response and extracting the documents.
  • response - the data response from which documents need to be extracted.

Description

Calls the method get_docs_from_response in the provided callback module to process the response.

model(callback_module, model)

@spec model(callback_module :: module(), model :: atom()) :: binary()

Returns the result of invoking the model method on the specified callback module with the given model.

Parameters

  • callback_module - the module that contains the model method.
  • model - the data structure or object to be processed by the model method.

Description

Invokes the model method from the provided callback module with the specified model argument.

request_prompt(callback_module, prompt, model, token, params \\ [])

@spec request_prompt(
  callback_module :: module(),
  prompt :: binary(),
  model :: binary(),
  token :: binary(),
  params :: keyword()
) :: {:ok, Req.Response.t()} | {:error, Exception.t()}

Returns the result of the request prompt operation initiated with the provided parameters.

Parameters

  • callback_module - The module used to handle the request.
  • prompt - The prompt that will be processed by the model.
  • model - The model that will be utilized for generating the response.
  • token - An authorization token for the request.
  • params - Optional additional parameters for the request.

Description

Executes a request through the specified callback module using the given prompt and model.