Documentation
¶
Index ¶
- Constants
- Variables
- type Asset
- type Book
- type BookEntry
- type BookEntryCore
- type BookEntryExtension
- type BookEntryExtensions
- type BookMerger
- func (bm *BookMerger) AppendBook(book *Book)
- func (bm *BookMerger) AppendEntries(entries []*BookEntry)
- func (bm *BookMerger) AppendEntry(entry *BookEntry)
- func (bm *BookMerger) AppendMapExtensions(extensions map[string]any)
- func (bm *BookMerger) AppendNameAndDescription(name string, description string)
- func (bm *BookMerger) AppendProperties(scanDepth int, tokenBudget int, recursiveScanning bool)
- func (bm *BookMerger) Build() *Book
- type Content
- type DepthPrompt
- type Revision
- type Sheet
- func (s *Sheet) DeepEquals(other *Sheet) bool
- func (s *Sheet) MarshalJSON() ([]byte, error)
- func (s *Sheet) SetRevision(revision Revision)
- func (s *Sheet) ToBytes(opts ...jsonx.Options) ([]byte, error)
- func (s *Sheet) ToFile(path string, opts ...jsonx.Options) error
- func (s *Sheet) ToJSON(w io.Writer, opts ...jsonx.Options) error
- func (s *Sheet) UnmarshalJSON(data []byte) error
- type Spec
- type Stamp
- type Version
Constants ¶
const ( BookNameSeparator string = " -- " BookDescriptionSeparator string = "\n----------------------\n" BookNamePlaceholder = `<<||-@PLACEHOLDER@-||>>` )
const ( DefaultEntryProbability float64 = 100.00 // Default probability for entries DefaultEntryDepth int = 4 // Default depth for entries )
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
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 ¶
var Stamps = map[Revision]Stamp{ RevisionV2: {Spec: SpecV2, Version: V2, Revision: RevisionV2}, RevisionV3: {Spec: SpecV3, Version: V3, Revision: RevisionV3}, }
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 ¶
FilledBookEntry returns a lorebook entry with the given name and description (default values for other fields)
func (*BookEntry) MarshalJSON ¶
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 ¶
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 (*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
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) MarshalJSON ¶
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 ¶
UnmarshalJSON unmarshals JSON into the Content, with fallbacks and best effort strategies using Sonic
type DepthPrompt ¶
DepthPrompt depth prompt structure of a V3 chara card
type Sheet ¶
Sheet structure of a V3 chara card
func DefaultSheet ¶
DefaultSheet returns an empty chara sheet with the given Revision
func FromBytes ¶
FromBytes decodes the JSON from the given input byte slice and returns the decoded sheet
func FromJSON ¶
FromJSON decodes the JSON from the given input io.Reader and returns the decoded sheet using Sonic streaming
func (*Sheet) DeepEquals ¶
DeepEquals returns true if the two sheets are deeply equal
func (*Sheet) MarshalJSON ¶
MarshalJSON marshals Sheet into JSON format with Content wrapped under "data" using Sonic
func (*Sheet) SetRevision ¶
SetRevision sets the sheet revision, spec and version
func (*Sheet) ToBytes ¶
ToBytes converts the sheet to its JSON representation and returns the JSON byte slice
func (*Sheet) ToFile ¶
ToFile converts the sheet to its JSON representation and writes it to the given output file destination
func (*Sheet) ToJSON ¶
ToJSON converts the sheet to its JSON representation and writes it to the given output io.Writer using Sonic streaming
func (*Sheet) UnmarshalJSON ¶
UnmarshalJSON decode a chara sheet from JSON using Sonic