LazyDoc.Provider behaviour (LazyDoc v0.4.0)

## 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

Parameters

  • callback_module - the module that contains the check_parameters? function to be called.
  • params - the parameters that need to be validated.

Description

Validates the parameters by delegating the check to a specified callback module.

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()

Parameters

  • callback_module - the module that contains the check_parameters? function to be called.
  • params - the parameters that need to be validated.

Description

Validates the parameters by delegating the check to a specified callback module.

Returns

the result of the parameter validation from the callback module.

get_docs_from_response(callback_module, response)

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

Parameters

callback_module - a module that implements the method to retrieve documents. response - data received from an external source that needs to be processed.

Description Calls the method get_docs_from_response on the provided callback_module with the given response to retrieve documents.

Returns the documents extracted from the response.

model(callback_module, model)

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

Parameters

callback_module - a module that contains the model function to be invoked. model - the model that needs to be passed to the callback module's model function. Description Invokes the model function of the provided callback module with the specified model.

Returns the result from the callback module's model function.

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()}

Parameters

callback_module - a module that handles the request for the prompt. prompt - the text prompt to be processed. model - the model to be used for generating the response to the prompt. token - authorization token to access the service.

Description Initiates a request to generate a response based on the provided prompt using the specified model and token.

Returns the response generated by the callback_module for the given prompt.