Documentation
¶
Index ¶
- Constants
- func MapTree(node Node) map[string]Node
- func PrettyPrint(node Node, indent string, isLastChild bool) string
- func PrintTree(node Node) string
- type Artifact
- type ArtifactType
- type ContextSettings
- type ContextType
- type Conversation
- type Core
- func (c *Core) AddProvider(name string, p Provider) error
- func (c *Core) AddToChatStore(filename string, content string) error
- func (c *Core) AddToContextStore(filename string, content string) error
- func (c *Core) AddToDataStore(filename string, content string) error
- func (c *Core) EndSession(sessionId string) error
- func (c *Core) ExecuteStatement(sessionId string, stmt *Statement) error
- func (c *Core) GetActiveChat(name string) (*chatInstance, error)
- func (c *Core) Install() error
- func (c *Core) IsInstalled() bool
- func (c *Core) ListContexts() []string
- func (c *Core) LoadContexts() error
- func (c *Core) LoadFromChatStore(filename string) (string, error)
- func (c *Core) LoadFromContextStore(filename string) (string, error)
- func (c *Core) LoadFromDataStore(filename string) (string, error)
- func (c *Core) LoadProviders() error
- func (c *Core) NewChat(name string, providerName string) error
- func (c *Core) SaveActiveChat(sessionName string) error
- func (c *Core) SessionList() []string
- func (c *Core) SetAvailableProviders(providers map[string]Provider)
- type CoreChatStartHandler
- type CoreDescription
- type CoreInfo
- type CoreOpts
- type FileArtifact
- type InformationCallback
- type MessageCreator
- type MessageData
- type MessagePairNode
- type Node
- type NodeTyppe
- type NonFileArtifact
- type OperationalCallback
- type Provider
- type ProviderSettings
- type RootNode
- type RootOpt
- type Snapshot
- type Statement
Constants ¶
const ( TokenTypeNewProviderCmd tokenType = iota TokenTypeNewChatCmd TokenTypeChatCmd TokenTypeNewContextCmd TokenTypePropertyTag TokenTypeString TokenTypeInteger TokenTypeReal TokenTypeDelChatCmd TokenTypeDelContextCmd TokenTypeListContextCmd TokenTypeListChatCmd TokenTypeDescribeContextCmd TokenTypeDescribeChatCmd TokenTypeListProviderCmd TokenTypeDelProviderCmd )
const ( PropertyTypeString propertyType = iota PropertyTypeInteger PropertyTypeReal )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Artifact ¶
type Artifact interface {
Type() ArtifactType
Write(dir string, name string) error
}
An artifact is some data that was generated by the provider and encoded as some understandable format. Whenever "code blocks" are present in the provider's response we encode them as artifacts and save them to disk. We also save non-code block artifacts to ensure that every individual piece of information within the message is saved for finer grain contextual analysis
func ParseArtifactsFrom ¶
func ParseArtifactsFrom(msg *MessageData) ([]Artifact, error)
ParseArtifactsFrom takes a message and parses it for artifacts This is done by looking for code blocks in the message and then parsing them into artifacts if any exist
type ArtifactType ¶
type ArtifactType int
const ( ArtifactTypeFile ArtifactType = iota ArtifactTypeNonFile )
type ContextSettings ¶
type ContextSettings struct {
Name string `json:"name"`
Type ContextType `json:"type"`
Value string `json:"value"`
}
type ContextType ¶
type ContextType string
A context type is a type of knowledge that can be attached to a conversation This could be a directory, a database, a web page, etc. HOW the knowledge is incorperated into the conversation is up to the provider and if the provider doesn't support knowledge contexts, this should return an error
const ( ContextTypeDirectory ContextType = "directory" ContextTypeDatabase ContextType = "database" ContextTypeWeb ContextType = "web" )
type Conversation ¶
type Conversation interface {
// Print the entire tree of the conversation, which includes all branches
PrintTree() string
// Print the history of the conversation, on the current branch back to the root
PrintHistory() string
// Queue images to be sent to the provider
QueueImages(paths []string) error
// Snapshot the current state of the conversation
Snapshot() (*Snapshot, error)
// Get the artifacts from the current node (not the entire conversation)
Artifacts() []Artifact
// Attach a context to the conversation that the chat provider _may_ use
// within the conversation that is ongoing
CreateContext(ctx *ContextSettings) error
// Attach an existing context to the conversation
AttachContext(ctxName string) error
// Goto a specific node in the conversation via hash (use PrintTree of History to see hashes)
Goto(nodeHash string) error
// Navigate to the parent node of the current node
Parent() error
// Navigate to the nth child of the current node
Child(idx int) error
// Navigate to the root node of the conversation
Root() error
// List the children of the current node
ListChildren() []string
// Check if the current node has a parent
HasParent() bool
// Toggle the chat on or off (soft disable)
ToggleChat(enabled bool)
// Get info about the current state of the chat
Info() string
// Get the current node of the conversation
CurrentNode() Node
// Submit a message to the chat provider
SubmitMessage(message string) (string, error)
// List the knowledge contexts that are attached to the conversation
ListKnowledgeContexts() []string
}
The panel is an interface for the user of brunch to interact with our chat instance in a way that is easy to understand and use
type Core ¶
type Core struct {
// contains filtered or unexported fields
}
The brunch core handles the installes of and managment of chats and their related llm provider info. The core is what executes the statements and is used to load/store branchable chats
func NewCore ¶
Create a new core instance with a set of providers that can be selected from. We are attempting to be entirely removed from the actual "chat" that the external user is doing, and instead we are just providing a way to manage instances of them, and add composability to the system through branching and traversal of a session forest
func (*Core) AddProvider ¶
Here we clone the provider handed to us and store in the provider map under a new name given to us by the user so they can reference that particular incarnation of the provider in their chat sessions (host: is the base provider like "anthropic" or "openai" etc whatever is setup by hand from config oin core init)
func (*Core) AddToContextStore ¶
func (*Core) EndSession ¶
func (*Core) ExecuteStatement ¶
func (*Core) GetActiveChat ¶
func (*Core) Install ¶
Sets up the core into the given install directory. It can be called multiple times and it wont overwrite the existing data store or chat store. It just makes sure that the directories exist that we rely on
func (*Core) IsInstalled ¶
func (*Core) ListContexts ¶
func (*Core) LoadContexts ¶
func (*Core) LoadFromContextStore ¶
func (*Core) LoadProviders ¶
Load all available providers from the provider store directory
func (*Core) NewChat ¶
This creates a chat instance, but it does not load it. It defines it so that the user can load it later (think of it like making a db table)
func (*Core) SaveActiveChat ¶
func (*Core) SessionList ¶
Retrive a list of all sessions This locks the session map and returns a list of all session ids, so best not call this in a hot spot
func (*Core) SetAvailableProviders ¶
type CoreChatStartHandler ¶
type CoreChatStartHandler func(req Conversation) error
type CoreDescription ¶
type CoreOpts ¶
type CoreOpts struct {
InstallDirectory string
BaseProviders map[string]Provider
ChatStartHandler CoreChatStartHandler
InfoHandler InformationCallback
}
type FileArtifact ¶
A FileArtifact is a code block that was encoded as a file If a code block is returned without the standard "```language:name.ext ... ```" format then we use a hash of the contents to name the file
func (*FileArtifact) Type ¶
func (a *FileArtifact) Type() ArtifactType
type InformationCallback ¶
type InformationCallback struct {
OnListChats func(chats []string)
OnListProviders func(providers []string)
OnListContexts func(contexts []string)
OnDescribeContext func(data string)
OnDescribeChat func(data string)
}
Informational callbacks are given to the core so that the user of the core can institute the display of information requested from a query regardless if the implementation is one of a CLI app, server, etc. This way the "backend" doesn't make any assumptions about how the hell the information is supposed to get out
type MessageCreator ¶
type MessageCreator func(userMessage string) (*MessagePairNode, error)
Provider must create a function that the user can call to create a new message pair node
type MessageData ¶
type MessageData struct {
Role string `json:"role"`
B64EncodedContent string `json:"-"`
RawContent string `json:"content"`
Images []string `json:"images,omitempty"`
}
func NewMessageData ¶
func NewMessageData(role string, unencodedContent string) *MessageData
NewMessageData creates a new message data object and ensures that the content is base64 encoded as when we save things we don't want messages to bonk our json, and it helps keep the data clean
func (*MessageData) MarshalJSON ¶
func (m *MessageData) MarshalJSON() ([]byte, error)
func (*MessageData) UnencodedContent ¶
func (m *MessageData) UnencodedContent() string
UnencodedContent returns the raw content of the message if the message is not base64 encoded, it will return the base64 encoded content
func (*MessageData) UnmarshalJSON ¶
func (m *MessageData) UnmarshalJSON(data []byte) error
type MessagePairNode ¶
type MessagePairNode struct {
Assistant *MessageData `json:"assistant"`
User *MessageData `json:"user"`
Time time.Time `json:"time"`
// contains filtered or unexported fields
}
func NewMessagePairNode ¶
func NewMessagePairNode(parent Node) *MessagePairNode
func (*MessagePairNode) Hash ¶
func (m *MessagePairNode) Hash() string
func (*MessagePairNode) Type ¶
func (m *MessagePairNode) Type() NodeTyppe
type Node ¶
type Node interface {
Type() NodeTyppe
Hash() string
ToString() string
History() []string
ToMap() map[string]Node
}
A Node is either a root, or a PAIR of messages (user and provider) We seperate into pairs of messages to constrain the conversation as a request->generation || failure
type NonFileArtifact ¶
type NonFileArtifact struct {
Data string
}
A NonFileArtifact is a piece of information that was not encoded as a file but rather as a string. This could be a table, a list, a markdown block, etc. These are always stored as a hash of the contents (name)
func (*NonFileArtifact) Type ¶
func (a *NonFileArtifact) Type() ArtifactType
type OperationalCallback ¶
type OperationalCallback struct {
OnLoadChat func(name string, hash *string) error
OnNewChat func(name string, provider string) error
OnNewProvider func(name string, host string, baseUrl string, maxTokens int, temperature float64, systemPrompt string) error
OnNewContext func(name string, dir *string, database *string, web *string) error
OnDeleteChat func(name string) error
OnDeleteContext func(name string) error
OnDeleteProvider func(name string) error
// These operational callbacks may be user to get information and forward to the InformationCallback,
// BUT not NECESARILY. The InformationCallback is offered as a means to pipe informational data to a user
// regardless of their connection to the server. However its not mandatory for the implementation to do so
OnListChats func() error
OnListProviders func() error
OnListContexts func() error
OnDescribeContext func(name string) error
OnDescribeChat func(name string) error
}
An operational callback is used when a session with a user (pre-chat interface) is in process. When they submit a commmand via the core, it will use these callbacks to receive instructions based on the command when `execucte` is called (below)
type Provider ¶
type Provider interface {
// NewConversationRoot creates a new root node for a new conversation
// from which all messages will be derived
NewConversationRoot() RootNode
// ExtendFrom takes a node and returns a function that can be used to create a new message pair node
// This means that this is the function we call in order to get a function to send a message,
// and then receive a response
ExtendFrom(Node) MessageCreator
// GetRoot takes a node and returns the root node
GetRoot(Node) RootNode
// GetHistory takes a node and returns the history of the conversation
GetHistory(Node) []map[string]string
// QueueImages takes a list of image urls and queues them for attachment to the next message
// In this way we can ask about images in the conversation and do analysis on them
// If the provider doesn't support images, this should return an error
QueueImages([]string) error
// Settings returns the settings for the provider
Settings() ProviderSettings
// CloneWithSettings returns a new provider with the given settings
// This is so we can derive providers from existing providers at runtime
// and have them be available to the user
CloneWithSettings(ProviderSettings) Provider
// AttachKnowledgeContext attaches a knowledge context to the provider
// A knowledge context could be a directory, a database, a web page, etc.
// HOW the knowledge is incorperated into the conversation is up to the provider
// and if the provider doesn't support knowledge contexts, this should return an error
AttachKnowledgeContext(ContextSettings) error
}
A provider is an abstraction of some (presumably LLM) message generation service though it could be anything that generates messages i guess
type ProviderSettings ¶
type RootNode ¶
type RootNode struct {
Provider string `json:"provider"`
Model string `json:"model"`
Prompt string `json:"prompt"`
Temperature float64 `json:"temperature"`
MaxTokens int `json:"max_tokens"`
// contains filtered or unexported fields
}
func NewRootNode ¶
type Snapshot ¶
type Snapshot struct {
ProviderName string `json:"provider_name"`
ActiveBranch string `json:"active_branch"`
Contents []byte `json:"contents"`
Contexts []string `json:"contexts"`
}
The snapshot is a hollistic snapshot of the current state of the chat It includes the provider name, the active branch, the contents of the conversation, and the contexts that are attached to the conversation. If a chat is saved with contexts then then all of the contextual configuration information MUST be available at the time of load. Snapshots save references to internal brunch resources on disk so they must be persisent and available at the time of load.
func SnapshotFromJSON ¶
type Statement ¶
type Statement struct {
// contains filtered or unexported fields
}