Documentation
¶
Overview ¶
Package jinja implements a Jinja2-compatible template engine.
Package jinja implements a Jinja template engine purpose-built for LLM chat templates.
Index ¶
- type Callable
- type Dict
- type Kind
- type List
- type Template
- type Value
- func FromGoValue(v any) Value
- func NewBool(b bool) Value
- func NewCallable(name string, fn func(args []Value, kwargs map[string]Value) (Value, error)) Value
- func NewDict() Value
- func NewFloat(f float64) Value
- func NewInt(n int64) Value
- func NewList(items []Value) Value
- func NewString(s string) Value
- func None() Value
- func Undefined() Value
- func (v Value) AsBool() bool
- func (v Value) AsCallable() *Callable
- func (v Value) AsDict() *Dict
- func (v Value) AsFloat() float64
- func (v Value) AsInt() int64
- func (v Value) AsList() *List
- func (v Value) AsString() string
- func (v Value) Equals(other Value) bool
- func (v Value) IsBool() bool
- func (v Value) IsCallable() bool
- func (v Value) IsDict() bool
- func (v Value) IsFloat() bool
- func (v Value) IsInt() bool
- func (v Value) IsList() bool
- func (v Value) IsNone() bool
- func (v Value) IsNumber() bool
- func (v Value) IsString() bool
- func (v Value) IsTruthy() bool
- func (v Value) IsUndefined() bool
- func (v Value) String() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dict ¶
Dict is an ordered map of string keys to values. Insertion order is preserved via the Keys slice.
func (*Dict) OrderedKeys ¶
OrderedKeys returns the keys in insertion order.
type List ¶
type List struct {
Items []Value
}
List holds an ordered sequence of values.
type Template ¶
type Template struct {
// contains filtered or unexported fields
}
Template is a compiled Jinja template ready for rendering.
func Compile ¶
Compile parses a Jinja template source string and returns a compiled template that can be rendered multiple times with different data.
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Value is a tagged union over JSON-like types used throughout the template engine. The v field holds one of: bool, int64, float64, string, *List, *Dict, or Callable.
func FromGoValue ¶
FromGoValue converts a plain Go value to a Value. Supported source types are nil, bool, int, int64, float64, string, []any, map[string]any, and []Value. For map[string]any the keys are sorted for deterministic order. Unrecognized types produce Undefined.
func NewCallable ¶
NewCallable returns a callable value.
func (Value) AsCallable ¶
AsCallable returns the *Callable held by v. It panics if v is not callable.
func (Value) IsCallable ¶
IsCallable reports whether v is callable.
func (Value) IsUndefined ¶
IsUndefined reports whether v is undefined.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
basic
command
This example demonstrates basic Jinja template rendering including variable substitution, for loops, conditionals, and filters.
|
This example demonstrates basic Jinja template rendering including variable substitution, for loops, conditionals, and filters. |
|
chat
command
This example demonstrates rendering an LLM chat template.
|
This example demonstrates rendering an LLM chat template. |
|
toolcall
command
This example demonstrates rendering a chat template that includes tool definitions, which is how function calling is formatted for LLMs.
|
This example demonstrates rendering a chat template that includes tool definitions, which is how function calling is formatted for LLMs. |