character

package
v1.0.70 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BookNameSeparator        string = " -- "
	BookDescriptionSeparator string = "\n----------------------\n"
	BookNamePlaceholder             = `<<||-@PLACEHOLDER@-||>>`
)
View Source
const (
	DefaultEntryProbability float64 = 100.00 // Default probability for entries
	DefaultEntryDepth       int     = 4      // Default depth for entries
)
View Source
const (
	NameField                    string = "name"
	DescriptionField             string = "description"
	PersonalityField             string = "personality"
	ScenarioField                string = "scenario"
	FirstMessageField            string = "first_mes"
	MessageExamplesField         string = "mes_example"
	CreatorNotesField            string = "creator_notes"
	PostHistoryInstructionsField string = "post_history_instructions"
	AlternateGreetingsField      string = "alternate_greetings"
	TagsField                    string = "tags"
	CreatorField                 string = "creator"
	DepthPromptKey               string = "depth_prompt"
	DepthPromptPromptKey         string = "prompt"
	DepthPromptDepthKey          string = "depth"
	DefaultDepth                 int    = 4
)

Field names

View Source
const (
	// CreatorNotesSeparator is the separator between different parts of the merged creator notes
	CreatorNotesSeparator = "\n\n"
	// AnonymousCreator is the name used for anonymous creators
	AnonymousCreator = "Anonymous"
)

Variables

Stamps mappings from revision to spec/versions

Functions

This section is empty.

Types

type Asset

type Asset struct {
	Type      property.String `json:"type"`
	URI       property.String `json:"uri"`
	Name      property.String `json:"name"`
	Extension property.String `json:"ext"`
}

Asset asset structure of a V3 chara card

type Book

type Book struct {
	Name              property.String  `json:"name"`
	Description       property.String  `json:"description"`
	ScanDepth         property.Integer `json:"scan_depth"`
	TokenBudget       property.Integer `json:"token_budget"`
	RecursiveScanning property.Bool    `json:"recursive_scanning"`
	Extensions        map[string]any   `json:"extensions,omitempty"`
	Entries           []*BookEntry     `json:"entries"`
}

Book lorebook structure of a V3 chara card

func DefaultBook

func DefaultBook() *Book

DefaultBook creates an empty book with an initialized entry list

func (*Book) NormalizeSymbols

func (b *Book) NormalizeSymbols()

NormalizeSymbols normalizes the book name and description, and all book entries

type BookEntry

type BookEntry struct {
	BookEntryCore
	RawExtensions map[string]any      `json:"-"`
	Extensions    BookEntryExtensions `json:"extensions"`
}

BookEntry lorebook entry structure

func DefaultBookEntry

func DefaultBookEntry() *BookEntry

DefaultBookEntry returns and empty lorebook entry with default value fields

func FilledBookEntry

func FilledBookEntry(entryName, entryDescription string) *BookEntry

FilledBookEntry returns a lorebook entry with the given name and description (default values for other fields)

func (*BookEntry) MarshalJSON

func (e *BookEntry) MarshalJSON() ([]byte, error)

MarshalJSON marshals the BookEntry struct to JSON

func (*BookEntry) MirrorNameAndComment

func (e *BookEntry) MirrorNameAndComment()

MirrorNameAndComment assures that the comment/name of the entry are consistent

func (*BookEntry) UnmarshalJSON

func (e *BookEntry) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals JSON data into the BookEntry struct

type BookEntryCore

type BookEntryCore struct {
	ID             property.Union       `json:"id"`
	Keys           property.StringArray `json:"keys"`
	SecondaryKeys  property.StringArray `json:"secondary_keys"`
	Name           property.String      `json:"name"`
	Comment        property.String      `json:"comment"`
	Content        property.String      `json:"content"`
	Constant       property.Bool        `json:"constant"`
	Selective      property.Bool        `json:"selective"`
	InsertionOrder property.Integer     `json:"insertion_order"`
	Enabled        property.Bool        `json:"enabled"`
	UseRegex       property.Bool        `json:"use_regex"`
}

BookEntryCore lorebook entry core structure

type BookEntryExtension

type BookEntryExtension = string

BookEntryExtension is a string alias for the extension keys of a book entry

const (
	EntryPosition        BookEntryExtension = "position"
	EntryProbability     BookEntryExtension = "probability"
	EntryDepth           BookEntryExtension = "depth"
	EntrySelectiveLogic  BookEntryExtension = "selectiveLogic"
	EntryMatchWholeWords BookEntryExtension = "match_whole_words"
	EntryCaseSensitive   BookEntryExtension = "case_sensitive"
	EntryRole            BookEntryExtension = "role"
	EntrySticky          BookEntryExtension = "sticky"
	EntryCooldown        BookEntryExtension = "cooldown"
	EntryDelay           BookEntryExtension = "delay"
)

type BookEntryExtensions

type BookEntryExtensions struct {
	LorePosition    property.LorePosition   `json:"position"`
	Probability     property.Float          `json:"probability"`
	Depth           property.Integer        `json:"depth"`
	SelectiveLogic  property.SelectiveLogic `json:"selectiveLogic"`
	MatchWholeWords property.Bool           `json:"match_whole_words"`
	CaseSensitive   property.Bool           `json:"case_sensitive"`
	Role            property.Role           `json:"role"`
	Sticky          property.Integer        `json:"sticky"`
	Cooldown        property.Integer        `json:"cooldown"`
	Delay           property.Integer        `json:"delay"`
}

BookEntryExtensions is a typed struct for extensions that can be added to a BookEntry

func DefaultBookEntryExtensions

func DefaultBookEntryExtensions() BookEntryExtensions

DefaultBookEntryExtensions returns an initialized BookEntryExtensions struct with default values

type BookMerger

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

BookMerger merges multiple lorebooks through a safe API

func NewBookMerger

func NewBookMerger() *BookMerger

NewBookMerger creates a new lorebook merger

func (*BookMerger) AppendBook

func (bm *BookMerger) AppendBook(book *Book)

AppendBook appends the given lorebook

func (*BookMerger) AppendEntries

func (bm *BookMerger) AppendEntries(entries []*BookEntry)

AppendEntries appends the given entries

func (*BookMerger) AppendEntry

func (bm *BookMerger) AppendEntry(entry *BookEntry)

AppendEntry appends the given entry

func (*BookMerger) AppendMapExtensions

func (bm *BookMerger) AppendMapExtensions(extensions map[string]any)

AppendMapExtensions Append extension map

func (*BookMerger) AppendNameAndDescription

func (bm *BookMerger) AppendNameAndDescription(name string, description string)

AppendNameAndDescription appends the name and description to the merged book

func (*BookMerger) AppendProperties

func (bm *BookMerger) AppendProperties(scanDepth int, tokenBudget int, recursiveScanning bool)

AppendProperties compute new properties of the merged book

func (*BookMerger) Build

func (bm *BookMerger) Build() *Book

Build builds the merged book

type Content

type Content struct {
	Title                   property.String      `json:"title"`
	Name                    property.String      `json:"name"`
	Description             property.String      `json:"description"`
	Personality             property.String      `json:"personality"`
	Scenario                property.String      `json:"scenario"`
	FirstMessage            property.String      `json:"first_mes"`
	MessageExamples         property.String      `json:"mes_example"`
	CreatorNotes            property.String      `json:"creator_notes"`
	SystemPrompt            property.String      `json:"system_prompt"`
	PostHistoryInstructions property.String      `json:"post_history_instructions"`
	AlternateGreetings      property.StringArray `json:"alternate_greetings"`
	CharacterBook           *Book                `json:"character_book,omitzero"`
	Tags                    property.StringArray `json:"tags"`
	Creator                 property.String      `json:"creator"`
	CharacterVersion        property.String      `json:"character_version"`
	DepthPrompt             DepthPrompt          `json:"-"`
	Extensions              map[string]any       `json:"extensions,omitzero"`

	Assets                   []Asset                    `json:"assets,omitzero"`
	Nickname                 property.String            `json:"nickname"`
	CreatorNotesMultilingual map[string]property.String `json:"creator_notes_multilingual,omitzero"`
	Source                   property.StringArray       `json:"source,omitzero"`
	GroupGreetings           property.StringArray       `json:"group_only_greetings,omitzero"`
	CreationDate             timestamp.Seconds          `json:"creation_date"`
	ModificationDate         timestamp.Seconds          `json:"modification_date"`

	SourceID    property.String `json:"source_id"`
	CharacterID property.String `json:"character_id"`
	PlatformID  property.String `json:"platform_id"`
	DirectLink  property.String `json:"direct_link"`
}

Content content of a V3 chara card

func (*Content) FixUserCharTemplates

func (c *Content) FixUserCharTemplates()

FixUserCharTemplates fixes the user character templates for all fields: {{{user}, {{char}, {char}}, {char} -> {{user}, {{char}}

func (*Content) Integrity

func (c *Content) Integrity() bool

Integrity checks if the sheet is malformed (missing necessary fields)

func (*Content) MarshalJSON

func (c *Content) MarshalJSON() ([]byte, error)

MarshalJSON marshals Content into JSON format to respect Silly Tavern format using Sonic

func (*Content) NormalizeSymbols

func (c *Content) NormalizeSymbols()

NormalizeSymbols replace all abnormal quotes, apostrophes or commas characters from ALL fields with the normal ASCII version (`"`, `,` `'`)

func (*Content) UnmarshalJSON

func (c *Content) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals JSON into the Content, with fallbacks and best effort strategies using Sonic

type DepthPrompt

type DepthPrompt struct {
	Prompt string
	Depth  int
}

DepthPrompt depth prompt structure of a V3 chara card

type Revision

type Revision int // chara card revision

Revision type of chara card

const (
	RevisionV2 Revision = 2
	RevisionV3 Revision = 3
)

Allowed Revision values

type Sheet

type Sheet struct {
	Spec     Spec
	Version  Version
	Revision Revision
	Content
}

Sheet structure of a V3 chara card

func DefaultSheet

func DefaultSheet(revision Revision) *Sheet

DefaultSheet returns an empty chara sheet with the given Revision

func FromBytes

func FromBytes(b []byte) (*Sheet, error)

FromBytes decodes the JSON from the given input byte slice and returns the decoded sheet

func FromFile

func FromFile(path string) (*Sheet, error)

FromFile decodes the JSON from the given input file and returns the decoded sheet

func FromJSON

func FromJSON(r io.Reader) (*Sheet, error)

FromJSON decodes the JSON from the given input io.Reader and returns the decoded sheet using Sonic streaming

func (*Sheet) DeepEquals

func (s *Sheet) DeepEquals(other *Sheet) bool

DeepEquals returns true if the two sheets are deeply equal

func (*Sheet) MarshalJSON

func (s *Sheet) MarshalJSON() ([]byte, error)

MarshalJSON marshals Sheet into JSON format with Content wrapped under "data" using Sonic

func (*Sheet) SetRevision

func (s *Sheet) SetRevision(revision Revision)

SetRevision sets the sheet revision, spec and version

func (*Sheet) ToBytes

func (s *Sheet) ToBytes(opts ...jsonx.Options) ([]byte, error)

ToBytes converts the sheet to its JSON representation and returns the JSON byte slice

func (*Sheet) ToFile

func (s *Sheet) ToFile(path string, opts ...jsonx.Options) error

ToFile converts the sheet to its JSON representation and writes it to the given output file destination

func (*Sheet) ToJSON

func (s *Sheet) ToJSON(w io.Writer, opts ...jsonx.Options) error

ToJSON converts the sheet to its JSON representation and writes it to the given output io.Writer using Sonic streaming

func (*Sheet) UnmarshalJSON

func (s *Sheet) UnmarshalJSON(data []byte) error

UnmarshalJSON decode a chara sheet from JSON using Sonic

type Spec

type Spec string // chara card spec

Spec type of chara card

const (
	SpecV2 Spec = "chara_card_v2"
	SpecV3 Spec = "chara_card_v3"
)

Allowed Spec values

type Stamp

type Stamp struct {
	Spec     Spec
	Version  Version
	Revision Revision
}

Stamp structure of a mapping from revision to spec/version

type Version

type Version string // chara card version

Version type of chara card

const (
	V2 Version = "2.0"
	V3 Version = "3.0"
)

Allowed Version values

Jump to

Keyboard shortcuts

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