chat

package
v2.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 15 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package chat renders the chat templates models ship, the Jinja Hugging Face tokenizer configs and GGUF files carry, into the text a conversation is sent to the model as: the template language with the filters, tests, methods and globals these templates use

Index

Constants

This section is empty.

Variables

View Source
var HuggingFace = Options{TrimBlocks: true, LStripBlocks: true}

What transformers renders chat templates with: blocks trimmed and stripped

Functions

func FromGo

func FromGo(v any) any

The value of a Go value of JSON's kinds: maps and slices as dicts and lists, numbers as int64 or float64

Types

type Callable

type Callable func(c *call) (any, error)

Something a template calls: a global, a macro or a bound method

type Conversation

type Conversation struct {
	// The messages, each with its role, content, and for an assistant's its tool calls, for a tool's result the call it answers
	Messages []map[string]any
	// Definitions of the tools the model may call, as JSON schemas of functions
	Tools []map[string]any
	// The template ends with what opens the assistant's reply
	AddGenerationPrompt bool
	// Special tokens by name, such as bos_token and eos_token
	Tokens map[string]string
	// Further variables a template reads, such as enable_thinking
	Extra map[string]any
	// The time strftime_now tells, the present when zero
	Now time.Time
}

What a conversation is rendered with, as transformers' apply_chat_template hands it to a template

type Dict

type Dict struct {
	// contains filtered or unexported fields
}

A mapping in the order its keys were put in, as Python's dicts are

func NewDict

func NewDict() *Dict

func (*Dict) Delete

func (d *Dict) Delete(k any) (any, bool)

func (*Dict) Get

func (d *Dict) Get(k any) (any, bool)

func (*Dict) Keys

func (d *Dict) Keys() []any

func (*Dict) Len

func (d *Dict) Len() int

func (*Dict) Set

func (d *Dict) Set(k, v any)

type List

type List struct {
	Items []any
	// Written with parentheses, as a tuple
	Tuple bool
}

A list, shared by every name it is bound to so appending through one is seen through all, as Python's lists are

type Namespace

type Namespace struct{ *Dict }

A namespace() object, whose attributes a set statement may change from inside a loop

type Options

type Options struct {
	// The first newline after a block or comment tag is removed
	TrimBlocks bool
	// Spaces and tabs from the start of a line to a block or comment tag are removed
	LStripBlocks bool
	// A newline ending the template is kept
	KeepTrailingNewline bool
}

How a template treats the whitespace around its tags, as Jinja's environment options say

type Template

type Template struct {
	// contains filtered or unexported fields
}

A parsed template

func Parse

func Parse(source string, opts Options) (*Template, error)

The template of a source, its whitespace treated as the options say

func (*Template) Conversation

func (t *Template) Conversation(c Conversation) (string, error)

The text of a conversation as the template renders it

func (*Template) Render

func (t *Template) Render(vars map[string]any) (string, error)

The text the template renders with the variables, Go values of JSON's kinds

type TemplateError

type TemplateError struct{ Message string }

An error a template raised itself through raise_exception, such as a role it does not take

func (*TemplateError) Error

func (e *TemplateError) Error() string

type Undefined

type Undefined struct{ Name string }

A name nothing defines, which prints as nothing and is false

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL