Behaviour and dispatcher for character renderers.
A renderer transforms a character map into:
- A system prompt string (
to_system_prompt/2) - A
ReqLLM.Contextstruct (to_context/2)
Configuration Priority
Renderers are resolved in this order:
- Per-call options (
:rendererkey) - Global application config
- Built-in Markdown renderer (default)
Global Configuration
# config/config.exs
config :jido_character, Jido.Character.Renderer,
renderer: MyApp.CustomRenderer,
renderer_opts: [format: :json]Implementing a Custom Renderer
defmodule MyApp.CustomRenderer do
@behaviour Jido.Character.Renderer
@impl true
def to_system_prompt(character, opts) do
# Return a string prompt
"You are #{character.name}..."
end
@impl true
def to_context(character, opts) do
# Return a ReqLLM.Context
prompt = to_system_prompt(character, opts)
ReqLLM.Context.new([ReqLLM.Context.system(prompt)])
end
endThe to_context/2 callback is optional. If not implemented, the dispatcher
will wrap the result of to_system_prompt/2 in a ReqLLM.Context.
Summary
Callbacks
Render a character to a ReqLLM.Context struct.
Render a character to a system prompt string.
Functions
Returns the default renderer module.
Render a character to a ReqLLM.Context struct.
Render a character to a system prompt string.
Types
Callbacks
Functions
@spec default_renderer() :: module()
Returns the default renderer module.
@spec to_context(character(), opts()) :: ReqLLM.Context.t()
Render a character to a ReqLLM.Context struct.
If the renderer doesn't implement to_context/2, falls back to wrapping
the system prompt from to_system_prompt/2.
Options
:renderer- Module implementingJido.Character.Rendererbehaviour:renderer_opts- Options passed to the renderer
Examples
context = Jido.Character.Renderer.to_context(character)
context = Jido.Character.Renderer.to_context(character, renderer: MyCustomRenderer)
Render a character to a system prompt string.
Options
:renderer- Module implementingJido.Character.Rendererbehaviour:renderer_opts- Options passed to the renderer
Examples
prompt = Jido.Character.Renderer.to_system_prompt(character)
prompt = Jido.Character.Renderer.to_system_prompt(character, renderer: MyCustomRenderer)