View Source Magma.Generation behaviour (Magma v0.2.0)
Generic adapter-based Magma.Prompt execution.
The Magma.Generation module is primarily responsible for handling the
execution of prompts. It is designed to be adaptable and flexible,
supporting different LLMs via specific adapters.
The module defines a behaviour that each adapter should implement,
ensuring a consistent interface for executing prompts.
The currently implemented adapters are:
Magma.Generation.OpenAIfor the OpenAI APIMagma.Generation.Manualfor manual prompt execution
The default values for the generation specification embedded within a prompt
document (the magma_generation_type and magma_generation_params properties
in its YAML frontmatter) can be configured for your application in config.exs
like this:
config :magma,
  default_generation: Magma.Generation.OpenAI
config :magma, Magma.Generation.OpenAI,
  model: "gpt-4",
  temperature: 0.6Except within the :test environment, the defaults can be configured also
with the default_generation_type and :default_generation_params properties
in YAML frontmatter of the magma_config.md document in your vault, taking
precedence over the ones from the application config.
Unlike, the default generation params from the magma_config.md document,
the ones from the application config are used also as initial defaults on the
new/1 function of a Magma.Generation implementation, meaning you only
have to provide the values differing from the application configured ones.
Summary
Functions
Extracts generation information from YAML frontmatter metadata.
Renders generation YAML frontmatter properties.
Returns the short version of the Magma.Generation implementation name.
Returns the generation module for the given string.
Types
Callbacks
Functions
Extracts generation information from YAML frontmatter metadata.
The function attempts to retrieve the magma_generation_type and
magma_generation_params from the metadata. It returns a tuple containing
the generation (if found and valid), and the remaining metadata.
Renders generation YAML frontmatter properties.
Returns the short version of the Magma.Generation implementation name.
This is used as the magma_generation value in the YAML frontmatter.
Example
iex> Magma.Generation.short_name(Magma.Generation.OpenAI)
OpenAI
iex> Magma.Generation.short_name(Magma.Generation.Bumblebee.TextGeneration.Llama)
Bumblebee.TextGeneration.Llama
  Returns the generation module for the given string.
Example
iex> Magma.Generation.type("OpenAI")
Magma.Generation.OpenAI
iex> Magma.Generation.type("Manual")
Magma.Generation.Manual
iex> Magma.Generation.type("Mock")
Magma.Generation.Mock
iex> Magma.Generation.type("Vault")
nil
iex> Magma.Generation.type("NonExisting")
nil