Magic facade provides the primary interface for interacting with LLM Magic. It offers convenient static methods for chat, extraction, embeddings, and quick question-answering operations.
Methods
ask
Quickly ask a question and get a structured or simple response.The question or prompt to ask the LLM
JSON schema defining the expected response type. Can be ‘string’, ‘number’, ‘boolean’, ‘array’, or ‘object’ with properties
The model to use. If null, uses the default configured model
Whether to respond with a full sentence (true) or just the answer (false)
The extracted answer matching the specified schema type
chat
Create a new chat builder for conversational interactions.A new chat builder instance for configuring and executing chat operations
extract
Create a new extraction builder for extracting structured data from documents.A new extraction builder instance for configuring and executing extraction operations
embeddings
Create a new embeddings builder for generating text embeddings.The text input to generate embeddings for, or a closure that returns the input
The embedding model to use. If null, uses the default configured model
A new embeddings builder instance
function
Use the LLM as a function that returns a specific type of value.Description of what the function should return
The type of value to return
Optional JSON schema for complex types (array or object)
The model to use. If null, uses the default configured model
The value returned by the LLM function
Thrown when the LLM cannot complete the requested task
Thrown when the LLM returns an invalid response
models
Get all registered models in a collection.Collection of model keys and labels, sorted alphabetically by key
error
Create a tool call exception for use in tool implementations.The error message
Optional error code
Previous exception for exception chaining
A new tool call exception instance
end
Create an end conversation signal with output.The output value to return when ending the conversation
An end conversation signal object
Helper Methods
defaultModelName
Get the configured default model name.The default model name from configuration
defaultModelLabel
Get the human-readable label for the default model.The default model’s display label
defaultModel
Get the default model instance.The default LLM model instance
getExtractionStrategies
Get all registered extraction strategies.Collection of strategy keys and class names
registerStrategy
Register a custom extraction strategy.The unique identifier for the strategy
The fully qualified class name of the strategy implementation