tzap

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2023 License: MIT Imports: 15 Imported by: 7

Documentation

Overview

package tzap provides a library to simplify manual workflows when dealing with chatgpt.

Index

Constants

This section is empty.

Variables

View Source
var (
	LastExecutionTime time.Time

	MessageBuffer []string
)

Package-level variables for global throttling

View Source
var Mem = map[string]*types.Message{}

Mem represents a global memory storage for messages.

Functions

func CheckData

func CheckData(data types.MappedInterface) error

func Flush

func Flush()

func GetMemory

func GetMemory(key string) string

GetMemory returns the content of a memory key, or an empty string if the key does not exist.

func GetMessages

func GetMessages(t *Tzap) []types.Message

func GetNames

func GetNames(t *Tzap) []string

func Log

func Log(t *Tzap, messages ...interface{})

func Logf

func Logf(t *Tzap, format string, args ...any)

func ResetFilepathOccurrences

func ResetFilepathOccurrences()

ResetFilepathOccurrences clears the global filepath occurrences tracking.

func ResetFlush

func ResetFlush()

func TotalLength

func TotalLength(t *Tzap) int

TotalLength calculates the total length of the Tzap instance chain.

func TruncateToMaxWords

func TruncateToMaxWords(messages []types.Message, wordLimit int) []types.Message

Not accurate way of counting tokens, but an approximation.

Types

type Tzap

type Tzap struct {
	Id      int
	Name    string
	Header  string
	Message types.Message
	Data    types.MappedInterface `json:"-"`
	C       context.Context       `json:"-"`

	types.ITzap[*Tzap] `json:"-"`

	Parent *Tzap

	TG types.TGenerator
}

Tzap is a structure that holds data and methods related to Tzap objects.

func InternalNew

func InternalNew() *Tzap

NewTzap creates a new Tzap with default values, and returns its pointer. Mainly for mocking purposes. Does not have a connector, will likely crash.

func NewWithConnector

func NewWithConnector(connector types.TzapConnector) *Tzap

func (*Tzap) Accumulate

func (t *Tzap) Accumulate(fn func(*Tzap) *Tzap) *Tzap

func (*Tzap) AddAssistantMessage

func (t *Tzap) AddAssistantMessage(contents ...string) *Tzap

AddAssistantMessage adds an assistant message to the Tzap

func (*Tzap) AddSystemMessage

func (t *Tzap) AddSystemMessage(contents ...string) *Tzap

AddSystemMessage adds a system message to the Tzap

func (*Tzap) AddTzap

func (t *Tzap) AddTzap(tc *Tzap) *Tzap

AddTzap (mostly internal use) initializes and adds a new Tzap child to the current Tzap object.

func (*Tzap) AddUserMessage

func (t *Tzap) AddUserMessage(contents ...string) *Tzap

AddUserMessage adds a user message to the Tzap

func (*Tzap) AppendContent

func (t *Tzap) AppendContent(sep string, s ...string) *Tzap

AppendContent appends content to the current message in the Tzap

func (*Tzap) AppendMessage

func (t *Tzap) AppendMessage(content string) *Tzap

AppendMessage appends a message to the current message in the Tzap

func (*Tzap) AppendParentContext

func (t *Tzap) AppendParentContext() *Tzap

AppendParentContext assigns the parent's context to the Tzap object, if present.

func (*Tzap) ApplyTemplate

func (t *Tzap) ApplyTemplate(nt types.NamedTemplate[*Tzap]) *Tzap

func (*Tzap) ApplyTemplateFN

func (t *Tzap) ApplyTemplateFN(nt func(*Tzap) *Tzap) *Tzap

ApplyTemplateFN applies a function that takes a Tzap instance and returns a modified Tzap instance. Returns the result of the given function applied to the current Tzap instance.

func (*Tzap) ApplyTemplateP

func (t *Tzap) ApplyTemplateP(template *Tzap) *Tzap

ApplyTemplateP applies a given template Tzap instance to the current Tzap instance. Returns the applied template with its Parent set to the current Tzap instance.

func (*Tzap) ChangeFilepath

func (t *Tzap) ChangeFilepath(filepath string) *Tzap

ChangeFilepath updates the filepath metadata in the Tzap data

func (*Tzap) CheckAndHandleGlobalOccurrences

func (t *Tzap) CheckAndHandleGlobalOccurrences(references int, filename string, noOccurrence, handleOccurrence func(*Tzap) *Tzap) *Tzap

CheckAndHandleGlobalOccurrences checks and handles the global occurrences of the given filename within the data. Calls either noOccurrence or handleOccurrence based on the provided references.

func (*Tzap) CheckAndHandleRecurrences

func (t *Tzap) CheckAndHandleRecurrences(references int, filename string, noReccurance, handleRecurrence func(*Tzap) *Tzap) *Tzap

CheckAndHandleRecurrences counts the number of recurrences of the given filename within the data and calls either noReccurance or handleRecurrence based on the threshold provided as references.

func (*Tzap) CloneTzap

func (t *Tzap) CloneTzap(tc *Tzap) *Tzap

CloneTzap (mostly internal use) clones a Tzap object and assigns values based on the provided Tzap object.

func (*Tzap) CombineMessage

func (t *Tzap) CombineMessage(nt1 func(*Tzap) *Tzap, nt2 func(*Tzap) *Tzap) *Tzap

CombineMessage combines two message functions and creates a new message in the Tzap

func (*Tzap) CountTokens

func (t *Tzap) CountTokens(content string) (int, error)

RequestOpenAIChat initializes the openai chat completion request and creates a new Tzap with the edited content.

func (*Tzap) Each

func (t *Tzap) Each(fn func(*Tzap)) *Tzap

func (*Tzap) Exit

func (t *Tzap) Exit() *Tzap

Exit raises a panic to exit from the current Tzap.

func (*Tzap) FetchTask

func (t *Tzap) FetchTask() *Tzap

FetchTask initializes the chat completion request, fetches the edited content, and sets up the environment.

func (*Tzap) FileMustContainHandleGlobalOccurrences

func (t *Tzap) FileMustContainHandleGlobalOccurrences(references int, filename string, noOccurrence, handleOccurrence func(*Tzap) *Tzap) *Tzap

FileMustContainHandleGlobalOccurrences checks and handles the global occurrences of the provided filename within the data. Calls either noOccurrence or handleOccurrence based on the provided references.

func (*Tzap) HijackTzap

func (t *Tzap) HijackTzap(tc *Tzap) *Tzap

HijackTzap (mostly internal use) effectively de-attaches from previous Tzap by changing the own parent to parents parent. This can be used AddUserMessage("H").LoadTaskOrRequestNewTask().Hijack() .() Tzap replaces the current Tzap's context and parent with the provided Tzap's context and parent.

func (*Tzap) IsolatedTzap

func (t *Tzap) IsolatedTzap(fn func(*Tzap)) *Tzap

IsolatedTzap executes the provided function with a new isolated Tzap object. It does not modify the current Tzap object but returns it.

func (*Tzap) LoadFileDir

func (t *Tzap) LoadFileDir(dir string, match string) *Tzap

LoadFileDir exposes an array of Tzaps in the previous elements .Data["children"]. Each child is a .LoadTask(file)

func (*Tzap) LoadFiles

func (t *Tzap) LoadFiles(filepaths []string) *Tzap

LoadFiles exposes an array of Tzaps in with .Data["children"]. Each child is a .LoadTask(file)

func (*Tzap) LoadTask

func (t *Tzap) LoadTask(filepath string) *Tzap

LoadTask loads a file and returns a Tzap with the file's content

func (*Tzap) LoadTaskOrRequestNewTask

func (t *Tzap) LoadTaskOrRequestNewTask(filepath string) *Tzap

LoadTaskOrRequestNewTask loads a file if it exists, otherwise requests a new file content from OpenAI and applies the changes to the original file

func (*Tzap) LoadTaskOrRequestNewTaskMD5

func (t *Tzap) LoadTaskOrRequestNewTaskMD5(filepath string) *Tzap

LoadTaskOrRequestNewTaskMD5 loads a task file if it exists and its MD5 checksum matches, otherwise requests a new task content from OpenAI and applies the changes to the original file

func (*Tzap) LoadUserMessageFromFileOrStdinInput

func (t *Tzap) LoadUserMessageFromFileOrStdinInput(filepath string, task string) *Tzap

LoadUserMessageFromFileOrStdinInput adds a user message from a file or standard input

func (*Tzap) Map

func (t *Tzap) Map(fn func(*Tzap) *Tzap) *Tzap

Map iterates through the children Tzap objects and applies the provided function. Returns a new Tzap object containing the result of the function application.

func (*Tzap) Memorize

func (t *Tzap) Memorize(key string) *Tzap

Memorize stores the current Tzap message content under a given key.

func (*Tzap) MemorizeReq

func (t *Tzap) MemorizeReq(key string) *Tzap

MemorizeReq stores the Chat message content under a given key.

func (*Tzap) Memory

func (t *Tzap) Memory(role, key string) *Tzap

Memory adds a new Tzap tied to a memory key.

func (*Tzap) MutationTzap

func (t *Tzap) MutationTzap(fn func(*Tzap) *Tzap) *Tzap

MutationTzap applies the provided function to the current Tzap object and returns a new Tzap object.

func (*Tzap) New

func (t *Tzap) New() *Tzap

New returns a new Tzap with default values.

func (*Tzap) OffsetTokens

func (t *Tzap) OffsetTokens(content string, from int, to int) (string, error)

RequestOpenAIChat initializes the openai chat completion request and creates a new Tzap with the edited content.

func (*Tzap) Plugin

func (t *Tzap) Plugin(pluginFunc func(tg types.TGenerator) (types.TGenerator, error)) *Tzap

func (*Tzap) PrepareOutputTask

func (t *Tzap) PrepareOutputTask(filepath string) *Tzap

PrepareOutputTask creates a Tzap with an empty file content to be used for outputting to a file

func (*Tzap) PrependContent

func (t *Tzap) PrependContent(sep string, s ...string) *Tzap

PrependContent prepends content to the current message in the Tzap

func (*Tzap) Recursive

func (t *Tzap) Recursive(tf func(tzapThatCreatesNewChildren *Tzap) *Tzap) *Tzap

Recursive applies the provided function recursively to the Tzap object and its children.

func (*Tzap) RequestChat

func (t *Tzap) RequestChat() *Tzap

RequestOpenAIChat initializes the openai chat completion request and creates a new Tzap with the edited content.

func (*Tzap) RequestTextToSpeech

func (t *Tzap) RequestTextToSpeech(language string, voice string) *Tzap

RequestTextToSpeech requests synthesized speech using specific (google voices) language and voice. It returns a pointer to a new Tzap containing the synthesised speech 'audioContent'.

func (*Tzap) RequestTextifySpeech

func (t *Tzap) RequestTextifySpeech(audioContent *[]byte, language string) *Tzap

func (*Tzap) SetHeader

func (t *Tzap) SetHeader(header string) *Tzap

func (*Tzap) WorkTzap

func (t *Tzap) WorkTzap(fn func(*Tzap)) *Tzap

WorkTzap executes the provided function and returns the Tzap object.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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