scenario

package
v0.0.0-...-8abfa7c Latest Latest
Warning

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

Go to latest
Published: May 4, 2022 License: GPL-3.0 Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Category

type Category struct {
	Name                *string             `json:"name,omitempty" yaml:"name"`
	Id                  *string             `json:"id,omitempty" yaml:"id"`
	Enabled             *bool               `json:"enabled,omitempty" yaml:"enabled"`
	CreateSubcontext    *bool               `json:"createSubcontext,omitempty" yaml:"createSubcontext"`
	SubcontextSettings  *LorebookEntry      `json:"subcontextSettings,omitempty" yaml:"subcontextSettings"`
	UseCategoryDefaults *bool               `json:"useCategoryDefaults,omitempty" yaml:"useCategoryDefaults"`
	CategoryDefaults    *LorebookEntry      `json:"categoryDefaults,omitempty" yaml:"categoryDefaults"`
	CategoryBiasGroups  *structs.BiasGroups `json:"categoryBiasGroups,omitempty" yaml:"categoryBiasGroups"`
}

type ContextBuilder

type ContextBuilder struct {
	Encoder      *gpt_bpe.GPTEncoder
	Contexts     ContextEntries
	Placeholders *Placeholders
}

func NewContextBuilder

func NewContextBuilder(encoder *gpt_bpe.GPTEncoder) *ContextBuilder

func (*ContextBuilder) AppendContext

func (cb *ContextBuilder) AppendContext(context *ContextEntry)

func (*ContextBuilder) AppendContexts

func (cb *ContextBuilder) AppendContexts(contexts *ContextEntries)

func (*ContextBuilder) PrependContext

func (cb *ContextBuilder) PrependContext(context *ContextEntry)

func (*ContextBuilder) Realize

func (cb *ContextBuilder) Realize(budget int) (string, ContextReport)

func (*ContextBuilder) ResolvePlaceholder

func (cb *ContextBuilder) ResolvePlaceholder(context *ContextEntry)

func (*ContextBuilder) ResolvePlaceholders

func (cb *ContextBuilder) ResolvePlaceholders()

type ContextConfig

type ContextConfig struct {
	Prefix               *string `json:"prefix,omitempty" yaml:"prefix"`
	Suffix               *string `json:"suffix,omitempty" yaml:"suffix"`
	TokenBudget          *int    `json:"tokenBudget,omitempty" yaml:"tokenBudget"`
	ReservedTokens       *int    `json:"reservedTokens,omitempty" yaml:"reservedTokens"`
	BudgetPriority       *int    `json:"budgetPriority,omitempty" yaml:"budgetPriority"`
	TrimDirection        *string `json:"trimDirection,omitempty" yaml:"trimDirection"`
	InsertionType        *string `json:"insertionType,omitempty" yaml:"insertionType"`
	MaximumTrimType      *string `json:"maximumTrimType,omitempty" yaml:"maximumTrimType"`
	InsertionPosition    *int    `json:"insertionPosition,omitempty" yaml:"insertionPosition"`
	AllowInnerInsertion  *bool   `json:"allowInnerInsertion,omitempty" yaml:"allowInnerInsertion"`
	AllowInsertionInside *bool   `json:"allowInsertionInside,omitempty" yaml:"allowInsertionInside"`
	Force                *bool   `json:"forced,omitempty" yaml:"forced"`
}

func CreateDefaultContextConfig

func CreateDefaultContextConfig() ContextConfig

type ContextEntries

type ContextEntries []ContextEntry

func (*ContextEntries) ApplyTokenizer

func (contexts *ContextEntries) ApplyTokenizer(tokenizer *gpt_bpe.GPTEncoder)

func (ContextEntries) Len

func (contexts ContextEntries) Len() int

func (ContextEntries) Less

func (contexts ContextEntries) Less(i, j int) bool

func (ContextEntries) Swap

func (contexts ContextEntries) Swap(i, j int)

type ContextEntry

type ContextEntry struct {
	Text         *string              `json:"text,omitempty" yaml:"text"`
	ContextCfg   *ContextConfig       `json:"contextConfig,omitempty" yaml:"config"`
	Tokens       *gpt_bpe.Tokens      `json:"-" yaml:"-"`
	Label        string               `json:"-" yaml:"-"`
	MatchIndexes []map[string][][]int `json:"-" yaml:"-"`
	Index        uint                 `json:"-" yaml:"-"`
}

func (*ContextEntry) Clone

func (context *ContextEntry) Clone() ContextEntry

func (*ContextEntry) ResolveTrim

func (context *ContextEntry) ResolveTrim(encoder *gpt_bpe.GPTEncoder, budget int) (
	trimmedTokens *gpt_bpe.Tokens)

type ContextReport

type ContextReport []ContextReportEntry

type ContextReportEntry

type ContextReportEntry struct {
	Label             string               `json:"label"`
	InsertionPos      int                  `json:"insertion_pos"`
	TokenCount        int                  `json:"token_count"`
	TokensInserted    int                  `json:"tokens_inserted"`
	BudgetRemaining   int                  `json:"budget_remaining"`
	ReservedRemaining int                  `json:"reserved_remaining"`
	MatchIndexes      []map[string][][]int `json:"matches"`
	Forced            bool                 `json:"forced"`
}

type Lorebook

type Lorebook struct {
	Version    int              `json:"lorebookVersion"`
	Entries    []LorebookEntry  `json:"entries"`
	Settings   LorebookSettings `json:"settings"`
	Categories []Category       `json:"categories"`
}

func (*Lorebook) ResolveContexts

func (lorebook *Lorebook) ResolveContexts(placeholders *Placeholders,
	contexts *ContextEntries) (entries ContextEntries)

func (*Lorebook) ToFile

func (lorebook *Lorebook) ToFile(path string)

func (*Lorebook) ToPlaintext

func (lorebook *Lorebook) ToPlaintext() string

func (*Lorebook) ToPlaintextFile

func (lorebook *Lorebook) ToPlaintextFile(path string)

type LorebookEntry

type LorebookEntry struct {
	Text                *string             `json:"text,omitempty" yaml:"text"`
	ContextCfg          *ContextConfig      `json:"contextConfig,omitempty" yaml:"contextConfig"`
	LastUpdatedAt       *int                `json:"lastUpdatedAt,omitempty" yaml:"lastUpdatedAt"`
	DisplayName         *string             `json:"displayName,omitempty" yaml:"displayName"`
	Keys                *[]string           `json:"keys,omitempty" yaml:"keys"`
	SearchRange         *int                `json:"searchRange,omitempty" yaml:"searchRange"`
	Enabled             *bool               `json:"enabled,omitempty" yaml:"enabled"`
	ForceActivation     *bool               `json:"forceActivation,omitempty" yaml:"forceActivation"`
	KeyRelative         *bool               `json:"keyRelative,omitempty" yaml:"keyRelative"`
	NonStoryActivatable *bool               `json:"nonStoryActivatable,omitempty" yaml:"nonStoryActivatable"`
	CategoryId          *string             `json:"category,omitempty" yaml:"categoryId"`
	LoreBiasGroups      *structs.BiasGroups `json:"loreBiasGroups,omitempty" yaml:"loreBiasGroups"`
	KeysRegex           []*regexp.Regexp    `json:"-" yaml:"-"`
}

func (*LorebookEntry) RealizeDefaults

func (defaults *LorebookEntry) RealizeDefaults(entry *LorebookEntry)

type LorebookSettings

type LorebookSettings struct {
	OrderByKeyLocations bool `json:"orderByKeyLocations" yaml:"orderByKeyLocations"`
}

type MaxTrimType

type MaxTrimType uint
const (
	TrimSentences MaxTrimType = iota
	TrimNewlines  MaxTrimType = iota
	TrimTokens    MaxTrimType = iota
)

type Placeholder

type Placeholder struct {
	Variable        string `json:"key" yaml:"key"`
	Defaults        string `json:"defaultValue" yaml:"default"`
	Description     string `json:"description" yaml:"description"`
	LongDescription string `json:"longDescription" yaml:"longDescription"`
	Value           string `json:"-" yaml:"value"`
}

type Placeholders

type Placeholders map[string]*Placeholder

func DiscoverPlaceholderDefs

func DiscoverPlaceholderDefs(text string) Placeholders

func DiscoverPlaceholderTable

func DiscoverPlaceholderTable(text string) Placeholders

func (Placeholders) Add

func (accPlaceholders Placeholders) Add(new Placeholders)

func (Placeholders) Realize

func (accPlaceholders Placeholders) Realize()

func (Placeholders) ReplacePlaceholders

func (variables Placeholders) ReplacePlaceholders(text string) (replaced string)

func (*Placeholders) UpdateValues

func (target *Placeholders) UpdateValues(kvs map[string]string)

type Scenario

type Scenario struct {
	ScenarioVersion    int                 `json:"scenarioVersion"`
	Title              string              `json:"title"`
	Author             string              `json:"author"`
	Description        string              `json:"description"`
	Prompt             string              `json:"prompt"`
	Tags               []string            `json:"tags,omitempty"`
	Context            ContextEntries      `json:"context,omitempty"`
	Settings           ScenarioSettings    `json:"settings,omitempty"`
	Lorebook           Lorebook            `json:"lorebook,omitempty"`
	Placeholders       []Placeholder       `json:"placeholders,omitempty"`
	StoryContextConfig *ContextConfig      `json:"storyContextConfig,omitempty"`
	Biases             *structs.BiasGroups `json:"-" yaml:"biases"`
	AIModule           *aimodules.AIModule `json:"-"`
	PlaceholderMap     Placeholders        `json:"-"`
	Encoder            *gpt_bpe.GPTEncoder `json:"-"`
}

func ScenarioFromFile

func ScenarioFromFile(path string) (scenario Scenario,
	err error)

func ScenarioFromSpec

func ScenarioFromSpec(prompt string, memory string, an string,
	model string) (scenario Scenario)

func (Scenario) GenerateContext

func (scenario Scenario) GenerateContext(story string, budget int) (
	newContext string,
	ctxReport ContextReport)

func (*Scenario) GetEncoder

func (scenario *Scenario) GetEncoder() *gpt_bpe.GPTEncoder

func (*Scenario) GetPlaceholderDefs

func (scenario *Scenario) GetPlaceholderDefs() (defs Placeholders)

func (*Scenario) SetAuthorsNote

func (scenario *Scenario) SetAuthorsNote(an string)

func (*Scenario) SetMemory

func (scenario *Scenario) SetMemory(memory string)

type ScenarioAIModule

type ScenarioAIModule struct {
	Id          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
	RemoteID    string `json:"remoteId"`
}

type ScenarioSettings

type ScenarioSettings struct {
	Parameters       *novelai_api.NaiGenerateParams `json:"parameters,omitempty"`
	TrimResponses    *bool                          `json:"trimResponses,omitempty"`
	BanBrackets      *bool                          `json:"banBrackets,omitempty"`
	Prefix           *string                        `json:"prefix,omitempty"`
	ScenarioAIModule *ScenarioAIModule              `json:"-,omitempty"`
	Model            *string                        `json:"model,omitempty"`
}

Jump to

Keyboard shortcuts

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