View Source Magma.Generation behaviour (Magma v0.1.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.6
Summary
Functions
Extracts generation information from YAML frontmatter metadata.
Returns the short version of the Magma.Generation implementation name.
Returns the generation module for the given string.
Types
Callbacks
@callback execute(t(), Magma.Artefact.Prompt.t(), options()) :: {:ok, result()} | {:error, any()}
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.
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