Documentation
¶
Overview ¶
package tzap provides a library to simplify manual workflows when dealing with chatgpt.
Index ¶
- Variables
- func ConvertGraphvizToSVG(inputFile string, outputFile string) error
- func Flush()
- func GenerateGraphvizDotFile(t *Tzap, graph *GraphVizGraph)
- func GetMemory(key string) string
- func GetNames(t *Tzap) []string
- func GetThread(t *Tzap) []types.Message
- func HandlePanic(fn func()) (err error)
- func Log(t *Tzap, messages ...interface{})
- func Logf(t *Tzap, format string, args ...any)
- func ResetFilepathOccurrences()
- func ResetFlush()
- func TotalLength(t *Tzap) int
- func TruncateToMaxTokens(tg types.TGenerator, messages []types.Message, wordLimit int) []types.Message
- type ErrorTzap
- type GraphVizEdge
- type GraphVizGraph
- type GraphVizLogMessage
- type GraphVizLogMessages
- type GraphVizNode
- type GraphVizSubgraph
- type Tzap
- func (t *Tzap) Accumulate(fn func(*Tzap) *Tzap) *Tzap
- func (t *Tzap) AddAssistantMessage(contents ...string) *Tzap
- func (t *Tzap) AddContextChange(fn func(context.Context) context.Context) *Tzap
- func (t *Tzap) AddSystemMessage(contents ...string) *Tzap
- func (t *Tzap) AddTzap(tc *Tzap) *Tzap
- func (t *Tzap) AddUserMessage(contents ...string) *Tzap
- func (t *Tzap) AppendContent(sep string, s ...string) *Tzap
- func (t *Tzap) AppendMessage(content string) *Tzap
- func (t *Tzap) ApplyErrorWorkflow(nt types.NamedWorkflow[*Tzap, *ErrorTzap], fn func(*ErrorTzap) error) *Tzap
- func (t *Tzap) ApplyWorkflow(nt types.NamedWorkflow[*Tzap, *Tzap]) *Tzap
- func (t *Tzap) ApplyWorkflowFN(nt func(*Tzap) *Tzap) *Tzap
- func (t *Tzap) ApplyWorkflowP(workflow *Tzap) *Tzap
- func (t *Tzap) AsAssistantMessage() *Tzap
- func (t *Tzap) ChangeFilepath(filepath string) *Tzap
- func (t *Tzap) CheckAndHandleGlobalOccurrences(references int, filename string, ...) *Tzap
- func (t *Tzap) CheckAndHandleRecurrences(references int, filename string, ...) *Tzap
- func (previousTzap *Tzap) CloneTzap(suggestedTzap *Tzap) *Tzap
- func (t *Tzap) CombineMessage(nt1 func(*Tzap) *Tzap, nt2 func(*Tzap) *Tzap) *Tzap
- func (t *Tzap) CopyConnection() *Tzap
- func (t *Tzap) CountTokens(content string) (int, error)
- func (t *Tzap) Each(fn func(*Tzap)) *Tzap
- func (t *Tzap) ErrorTzap(err error) *ErrorTzap
- func (t *Tzap) Exit() *Tzap
- func (t *Tzap) FileMustContainHandleGlobalOccurrences(references int, filename string, ...) *Tzap
- func (t *Tzap) GetThread() []types.Message
- func (t *Tzap) GetThreadAsJSON() (string, error)
- func (t *Tzap) HandleShutdown()
- func (previousTzap *Tzap) HijackTzap(bypassWith *Tzap) *Tzap
- func (t *Tzap) If(b bool, tfn func(*Tzap) *Tzap, ffn func(*Tzap) *Tzap) *Tzap
- func (t *Tzap) IfFunctionCall(tzapFunc func(*Tzap) *Tzap, notTzapFunc func(*Tzap) *Tzap) *Tzap
- func (t *Tzap) IsolatedTzap(fn func(*Tzap)) *Tzap
- func (t *Tzap) LoadCompletionOrRequestCompletion(filePath string) *Tzap
- func (t *Tzap) LoadFileAsCompletion(filePath string) *Tzap
- func (t *Tzap) LoadFileDir(dir string) *Tzap
- func (t *Tzap) LoadFiles(filepaths []string) *Tzap
- func (t *Tzap) LoadThread(messages []types.Message) *Tzap
- func (t *Tzap) LoadThreadFile(filePath string) *ErrorTzap
- func (t *Tzap) LoadThreadString(content string) *ErrorTzap
- func (t *Tzap) Map(fn func(*Tzap) *Tzap) *Tzap
- func (t *Tzap) Memorize(key string) *Tzap
- func (t *Tzap) MemorizeReq(key string) *Tzap
- func (t *Tzap) Memory(role, key string) *Tzap
- func (t *Tzap) MutationTzap(fn func(*Tzap) *Tzap) *Tzap
- func (t *Tzap) OffsetTokens(content string, from int, to int) (string, int, error)
- func (t *Tzap) PrependContent(sep string, s ...string) *Tzap
- func (t *Tzap) Recursive(tf func(tzapThatCreatesNewChildren *Tzap) *Tzap) *Tzap
- func (t *Tzap) Reduce(fn func(*Tzap, *Tzap) *Tzap) *Tzap
- func (t *Tzap) RequestChatCompletion() *Tzap
- func (t *Tzap) RequestFunctionCompletion(functions string) *Tzap
- func (t *Tzap) RequestTextToSpeech(language string, voice string) *ErrorTzap
- func (t *Tzap) RequestTextifySpeech(audioContent *[]byte, language string) *ErrorTzap
- func (t *Tzap) SetInitialSystemContent(content string) *Tzap
- func (t *Tzap) StoreCompletion(filePath string) *Tzap
- func (t *Tzap) StoreThread(filePath string) *ErrorTzap
- func (t *Tzap) WorkTzap(fn func(*Tzap)) *Tzap
Constants ¶
This section is empty.
Variables ¶
var ( LastExecutionTime time.Time MessageBuffer []string )
Package-level variables for global throttling
var GlobalGraphVizLogThreads []GraphVizLogMessages
var GlobalTzaps []*Tzap
var Mem = map[string]*types.Message{}
Mem represents a global memory storage for messages.
Functions ¶
func ConvertGraphvizToSVG ¶ added in v0.7.12
func GenerateGraphvizDotFile ¶ added in v0.7.12
func GenerateGraphvizDotFile(t *Tzap, graph *GraphVizGraph)
func GetMemory ¶
GetMemory returns the content of a memory key, or an empty string if the key does not exist.
func HandlePanic ¶ added in v0.7.8
func HandlePanic(fn func()) (err error)
func ResetFilepathOccurrences ¶
func ResetFilepathOccurrences()
ResetFilepathOccurrences clears the global filepath occurrences tracking.
func ResetFlush ¶
func ResetFlush()
func TotalLength ¶
TotalLength calculates the total length of the Tzap instance chain.
func TruncateToMaxTokens ¶ added in v0.8.5
Types ¶
type GraphVizEdge ¶ added in v0.7.6
type GraphVizEdge struct { FromNode *GraphVizNode ToNode *GraphVizNode Tooltip string Style string }
type GraphVizGraph ¶ added in v0.7.6
type GraphVizGraph struct { Label string Tooltip string Nodes []*GraphVizNode Edges []*GraphVizEdge SubGraphs []*GraphVizSubgraph }
func FillGraphVizGraph ¶ added in v0.7.6
func FillGraphVizGraph() *GraphVizGraph
type GraphVizLogMessage ¶ added in v0.7.6
type GraphVizLogMessages ¶ added in v0.7.6
type GraphVizLogMessages struct { Messages []GraphVizLogMessage TokenCount int }
type GraphVizNode ¶ added in v0.7.6
type GraphVizNode struct { Id string Label string Tooltip string Style string Children []*GraphVizNode }
type GraphVizSubgraph ¶ added in v0.7.6
type GraphVizSubgraph struct { Id string Label string Tooltip string Nodes []*GraphVizNode Edges []*GraphVizEdge SubGraphs []*GraphVizSubgraph }
type Tzap ¶
type Tzap struct { Id int Name string InitialSystemContent string Message types.Message Data types.MappedInterface `json:"-"` C context.Context `json:"-"` TG types.TGenerator `json:"-"` types.ITzap[*Tzap, any] `json:"-"` Parent *Tzap }
Tzap is a structure that holds data and methods related to Tzap objects.
func InjectNew ¶ added in v0.9.0
func InjectNew(tg types.TGenerator, conf config.Configuration) *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 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) AddAssistantMessage ¶
AddAssistantMessage adds an assistant message to the Tzap
func (*Tzap) AddContextChange ¶ added in v0.8.5
AddContextChange replaces the current Tzap's context with the provided context.
func (*Tzap) AddSystemMessage ¶
AddSystemMessage adds a system message to the Tzap
func (*Tzap) AddTzap ¶
AddTzap (mostly internal use) initializes and adds a new Tzap child to the current Tzap object.
func (*Tzap) AddUserMessage ¶
AddUserMessage adds a user message to the Tzap
func (*Tzap) AppendContent ¶
AppendContent appends content to the current message in the Tzap
func (*Tzap) AppendMessage ¶
AppendMessage appends a message to the current message in the Tzap
func (*Tzap) ApplyErrorWorkflow ¶ added in v0.7.14
func (*Tzap) ApplyWorkflow ¶ added in v0.7.14
WARNING: ApplyWorkflow clones messages from previous Tzap instances. This duplicates the message.
func (*Tzap) ApplyWorkflowFN ¶ added in v0.7.14
ApplyWorkflowFN 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) ApplyWorkflowP ¶ added in v0.7.14
ApplyWorkflowP applies a given workflow Tzap instance to the current Tzap instance. Returns the applied workflow with its Parent set to the current Tzap instance.
func (*Tzap) AsAssistantMessage ¶ added in v0.7.19
func (*Tzap) ChangeFilepath ¶
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 ¶
CloneTzap (mostly internal use) clones a Tzap object and assigns values based on the provided Tzap object.
func (*Tzap) CombineMessage ¶
CombineMessage combines two message functions and creates a new message in the Tzap
func (*Tzap) CopyConnection ¶ added in v0.8.7
CopyConnection returns a new Tzap with default values.
func (*Tzap) CountTokens ¶
RequestOpenAIChat initializes the openai chat completion request and creates a new Tzap with the edited content.
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) GetThreadAsJSON ¶ added in v0.8.3
func (*Tzap) HandleShutdown ¶ added in v0.7.15
func (t *Tzap) HandleShutdown()
func (*Tzap) HijackTzap ¶
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) If ¶ added in v0.8.3
WorkTzap executes the provided function and returns the Tzap object.
func (*Tzap) IfFunctionCall ¶ added in v0.9.0
func (*Tzap) IsolatedTzap ¶
IsolatedTzap executes the provided function with a new isolated Tzap object. It does not modify the current Tzap object but returns it.
func (*Tzap) LoadCompletionOrRequestCompletion ¶ added in v0.7.14
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) LoadFileAsCompletion ¶ added in v0.7.16
LoadFileAsCompletion loads a file and returns a Tzap with the file's content
func (*Tzap) LoadFileDir ¶
LoadFileDir exposes an array of Tzaps in the previous elements .Data["children"]. Each child is a .LoadTask(file)
func (*Tzap) LoadFiles ¶
LoadFiles exposes an array of Tzaps in with .Data["children"]. Each child is a .LoadTask(file)
func (*Tzap) LoadThread ¶ added in v0.7.16
func (*Tzap) LoadThreadFile ¶ added in v0.7.20
func (*Tzap) LoadThreadString ¶ added in v0.8.3
func (*Tzap) Map ¶
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) MemorizeReq ¶
MemorizeReq stores the Chat message content under a given key.
func (*Tzap) MutationTzap ¶
MutationTzap applies the provided function to the current Tzap object and returns a new Tzap object.
func (*Tzap) OffsetTokens ¶
RequestOpenAIChat initializes the openai chat completion request and creates a new Tzap with the edited content.
func (*Tzap) PrependContent ¶
PrependContent prepends content to the current message in the Tzap
func (*Tzap) Recursive ¶
Recursive applies the provided function recursively to the Tzap object and its children.
func (*Tzap) RequestChatCompletion ¶ added in v0.7.14
RequestChatCompletion initializes the openai chat completion request and creates a new Tzap with the edited content.
func (*Tzap) RequestFunctionCompletion ¶ added in v0.9.0
func (*Tzap) RequestTextToSpeech ¶
RequestTextToSpeech requests synthesized speech using specific (google voices) language and voice. It returns a pointer to a new Tzap containing the synthesised speech 'audioContent'.