# README
Conversation Package
The conversation
package provides a tree-like structure for storing and managing conversation messages in an LLM
chatbot. It allows for traversing the conversation in various ways and supports different types of message content.
Features
- Represents a conversation as a tree of messages
- Supports different types of message content (e.g., chat messages)
- Allows traversing the conversation tree in various ways (e.g., linear thread, leftmost thread)
- Provides methods for inserting, attaching, and prepending messages to the conversation tree
- Supports saving and loading conversation trees to/from JSON files
- Includes a
Manager
interface for high-level management of conversations
Installation
go get github.com/go-go-golems/bobatea/pkg/conversation
Usage
Creating a Conversation Tree
tree := conversation.NewConversationTree()
Inserting Messages
message1 := conversation.NewChatMessage(conversation.RoleUser, "Hello!")
message2 := conversation.NewChatMessage(conversation.RoleAssistant, "Hi there!")
tree.InsertMessages(message1, message2)
Traversing the Conversation Tree
thread := tree.GetConversationThread(message2.ID)
leftmostThread := tree.GetLeftMostThread(tree.RootID)
Saving and Loading Conversation Trees
err := tree.SaveToFile("conversation.json")
if err != nil {
// Handle error
}
loadedTree := conversation.NewConversationTree()
err = loadedTree.LoadFromFile("conversation.json")
if err != nil {
// Handle error
}
Using the Manager
manager, err := conversation.CreateManager(
"System prompt",
"User prompt",
[]*conversation.Message{},
nil,
)
if err != nil {
// Handle error
}
manager.AppendMessages(message1, message2)
conversation := manager.GetConversation()
Message Content Types
The package supports different types of message content. Currently, the following content types are available:
ChatMessageContent
: Represents a chat message with a role (system, assistant, user) and text content.
You can define your own message content types by implementing the MessageContent
interface.
# Functions
CreateManager creates a concrete Manager implementation.
LoadFromFile loads messages from a json file or yaml file.
No description provided by the author
NewConversationTree creates a new conversation tree.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Constants
TODO(manuel, 2024-07-04) Unify this with the events types that we added for the claude API.
TODO(manuel, 2024-07-04) Unify this with the events types that we added for the claude API.
TODO(manuel, 2024-07-04) Unify this with the events types that we added for the claude API.
TODO(manuel, 2024-06-04) This needs to also handle tool call and tool response blocks (tool use block in claude API) See also the comment to refactor this in openai/helpers.go, where tool use information is actually stored in the metadata of the message.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Variables
No description provided by the author
# Structs
No description provided by the author
ConversationTree represents a tree-like structure for storing and managing conversation messages.
No description provided by the author
No description provided by the author
Message represents a single message node in the conversation tree.
No description provided by the author
No description provided by the author
# Interfaces
No description provided by the author
MessageContent is an interface for different types of node content.
# Type aliases
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author