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:

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

@type options() :: keyword()
@type prompt() :: binary()
@type result() :: binary()
@type system_prompt() :: prompt()
@type t() :: struct()

Callbacks

@callback execute(t(), Magma.Artefact.Prompt.t(), options()) ::
  {:ok, result()} | {:error, any()}

Functions

Link to this function

execute(generation, prompt, opts \\ [])

View Source
Link to this function

extract_from_metadata(metadata)

View Source

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