Documentation ¶
Index ¶
- type ChatMessageContent
- type ContentType
- type Conversation
- type ConversationTree
- func (ct *ConversationTree) AppendMessages(thread Conversation)
- func (ct *ConversationTree) AttachThread(parentID NodeID, thread Conversation)
- func (ct *ConversationTree) FindChildren(id NodeID) []NodeID
- func (ct *ConversationTree) FindSiblings(id NodeID) []NodeID
- func (ct *ConversationTree) GetConversationThread(id NodeID) Conversation
- func (ct *ConversationTree) GetLeftMostThread(id NodeID) Conversation
- func (ct *ConversationTree) GetMessageByID(id NodeID) (*Message, bool)
- func (ct *ConversationTree) InsertMessages(msgs ...*Message)
- func (ct *ConversationTree) LoadFromFile(filename string) error
- func (ct *ConversationTree) PrependThread(thread Conversation)
- func (ct *ConversationTree) SaveToFile(filename string) error
- type ImageContent
- type ImageDetail
- type Manager
- type ManagerImpl
- func (c *ManagerImpl) AppendMessages(messages ...*Message)
- func (c *ManagerImpl) AttachMessages(parentID NodeID, messages ...*Message)
- func (c *ManagerImpl) GetConversation() Conversation
- func (c *ManagerImpl) GetMessage(ID NodeID) (*Message, bool)
- func (c *ManagerImpl) PrependMessages(messages ...*Message)
- func (c *ManagerImpl) SaveToFile(s string) error
- type ManagerOption
- type Message
- type MessageContent
- type MessageOption
- type NodeID
- type Role
- type ToolResultContent
- type ToolUseContent
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChatMessageContent ¶
type ChatMessageContent struct { Role Role `json:"role"` Text string `json:"text"` Images []*ImageContent `json:"images"` }
func (*ChatMessageContent) ContentType ¶
func (c *ChatMessageContent) ContentType() ContentType
func (*ChatMessageContent) String ¶
func (c *ChatMessageContent) String() string
func (*ChatMessageContent) View ¶
func (c *ChatMessageContent) View() string
type ContentType ¶
type ContentType string
const ( ContentTypeChatMessage ContentType = "chat-message" // 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 ContentTypeToolUse ContentType = "tool-use" ContentTypeToolResult ContentType = "tool-result" ContentTypeImage ContentType = "image" )
TODO(manuel, 2024-07-04) Unify this with the events types that we added for the claude API
type Conversation ¶
type Conversation []*Message
func (Conversation) GetSinglePrompt ¶
func (messages Conversation) GetSinglePrompt() string
GetSinglePrompt concatenates all the messages together with a prompt in front. It just concatenates all the messages together with a prompt in front (if there are more than one message).
type ConversationTree ¶
ConversationTree represents a tree-like structure for storing and managing conversation messages.
The tree consists of nodes (messages) connected by parent-child links. These relationships are done through the parent ID field in each message. The root node is the starting point of the conversation, and each node can have multiple children. The tree allows for traversing the conversation in various ways.
Node relationships are stored in the Message datastructure as `Children []*Message`.
Each node has a unique ID, and the tree keeps track of the root node ID and the last inserted node ID.
func NewConversationTree ¶
func NewConversationTree() *ConversationTree
NewConversationTree creates a new conversation tree.
func (*ConversationTree) AppendMessages ¶
func (ct *ConversationTree) AppendMessages(thread Conversation)
AppendMessages appends a conversation thread to the end of the tree. It attaches the thread to the last inserted node in the tree, making it the parent of the thread. The messages in the thread are inserted as nodes, extending the parent-child chain.
func (*ConversationTree) AttachThread ¶
func (ct *ConversationTree) AttachThread(parentID NodeID, thread Conversation)
AttachThread attaches a conversation thread to a specified parent message. It updates the parent IDs of the messages in the thread to link them to the parent message. The last message in the thread becomes the new last inserted node ID.
func (*ConversationTree) FindChildren ¶
func (ct *ConversationTree) FindChildren(id NodeID) []NodeID
FindChildren returns the IDs of all child messages for a given message ID. Child messages are the nodes directly connected to the given message as its children.
func (*ConversationTree) FindSiblings ¶
func (ct *ConversationTree) FindSiblings(id NodeID) []NodeID
FindSiblings returns the IDs of all sibling messages for a given message ID. Sibling messages are the nodes that share the same parent as the given message.
func (*ConversationTree) GetConversationThread ¶
func (ct *ConversationTree) GetConversationThread(id NodeID) Conversation
GetConversationThread returns the linear conversation thread starting from a given message ID. It traverses the tree upwards, following the parent links, to retrieve the complete thread. The returned conversation is a linear sequence of messages from the root to the given message.
func (*ConversationTree) GetLeftMostThread ¶
func (ct *ConversationTree) GetLeftMostThread(id NodeID) Conversation
GetLeftMostThread returns the thread starting from a given message ID by always choosing the first child. It traverses the tree downwards, selecting the leftmost child at each level, until a leaf node is reached. The returned conversation is a linear sequence of messages from the given message to the leftmost leaf.
func (*ConversationTree) GetMessageByID ¶
func (ct *ConversationTree) GetMessageByID(id NodeID) (*Message, bool)
GetMessageByID returns a message by its ID from the conversation tree.
func (*ConversationTree) InsertMessages ¶
func (ct *ConversationTree) InsertMessages(msgs ...*Message)
InsertMessages adds new messages to the conversation tree. It updates the root ID if the tree is empty and sets the last inserted node ID. If a message has a parent ID that exists in the tree, it is added as a child of that parent node.
func (*ConversationTree) LoadFromFile ¶
func (ct *ConversationTree) LoadFromFile(filename string) error
LoadFromFile loads the conversation tree from a JSON file.
func (*ConversationTree) PrependThread ¶
func (ct *ConversationTree) PrependThread(thread Conversation)
PrependThread prepends a conversation thread to the beginning of the tree. It updates the root ID to the first message in the thread and adjusts the parent-child relationships accordingly. The previous root node becomes a child of the new root node.
func (*ConversationTree) SaveToFile ¶
func (ct *ConversationTree) SaveToFile(filename string) error
SaveToFile saves the conversation tree to a JSON file.
type ImageContent ¶ added in v0.0.10
type ImageContent struct { ImageURL string `json:"imageURL"` ImageContent []byte `json:"imageContent"` ImageName string `json:"imageName"` MediaType string `json:"mediaType"` Detail ImageDetail `json:"detail"` }
func NewImageContentFromFile ¶ added in v0.0.10
func NewImageContentFromFile(path string) (*ImageContent, error)
func (*ImageContent) ContentType ¶ added in v0.0.10
func (i *ImageContent) ContentType() ContentType
func (*ImageContent) String ¶ added in v0.0.10
func (i *ImageContent) String() string
func (*ImageContent) View ¶ added in v0.0.10
func (i *ImageContent) View() string
type ImageDetail ¶ added in v0.0.10
type ImageDetail string
const ( ImageDetailLow ImageDetail = "low" ImageDetailHigh ImageDetail = "high" ImageDetailAuto ImageDetail = "auto" )
type ManagerImpl ¶
type ManagerImpl struct { Tree *ConversationTree ConversationID uuid.UUID }
func CreateManager ¶
func CreateManager( systemPrompt string, prompt string, messages []*Message, params interface{}, options ...ManagerOption, ) (*ManagerImpl, error)
CreateManager creates a concrete Manager implementation.
NOTE(manuel, 2024-04-07) This currently seems to only be used by the codegen tests, while the main geppetto command uses NewManager. Unclear if this is just a legacy helper.
The systemPrompt and prompt templates are rendered using the params. Messages are also rendered using the params before being added to the manager.
ManagerOptions can be passed to further customize the manager on creation.
func NewManager ¶
func NewManager(options ...ManagerOption) *ManagerImpl
func (*ManagerImpl) AppendMessages ¶
func (c *ManagerImpl) AppendMessages(messages ...*Message)
func (*ManagerImpl) AttachMessages ¶
func (c *ManagerImpl) AttachMessages(parentID NodeID, messages ...*Message)
func (*ManagerImpl) GetConversation ¶
func (c *ManagerImpl) GetConversation() Conversation
func (*ManagerImpl) GetMessage ¶
func (c *ManagerImpl) GetMessage(ID NodeID) (*Message, bool)
func (*ManagerImpl) PrependMessages ¶
func (c *ManagerImpl) PrependMessages(messages ...*Message)
func (*ManagerImpl) SaveToFile ¶
func (c *ManagerImpl) SaveToFile(s string) error
type ManagerOption ¶
type ManagerOption func(*ManagerImpl)
func WithManagerConversationID ¶
func WithManagerConversationID(conversationID uuid.UUID) ManagerOption
func WithMessages ¶
func WithMessages(messages ...*Message) ManagerOption
type Message ¶
type Message struct { ParentID NodeID `json:"parentID"` ID NodeID `json:"id"` Time time.Time `json:"time"` LastUpdate time.Time `json:"lastUpdate"` Content MessageContent `json:"content"` Metadata map[string]interface{} `json:"metadata"` // Flexible metadata field // TODO(manuel, 2024-04-07) Add Parent and Sibling lists // omit in json Children []*Message `json:"-"` }
Message represents a single message node in the conversation tree.
func LoadFromFile ¶
LoadFromFile loads messages from a json file or yaml file
func NewChatMessage ¶
func NewChatMessage(role Role, text string, options ...MessageOption) *Message
func NewMessage ¶
func NewMessage(content MessageContent, options ...MessageOption) *Message
func (*Message) MarshalJSON ¶
func (*Message) UnmarshalJSON ¶
UnmarshalJSON custom unmarshaler for Message.
type MessageContent ¶
type MessageContent interface { ContentType() ContentType String() string View() string }
MessageContent is an interface for different types of node content.
type MessageOption ¶
type MessageOption func(*Message)
func WithID ¶
func WithID(id NodeID) MessageOption
func WithMetadata ¶
func WithMetadata(metadata map[string]interface{}) MessageOption
func WithParentID ¶
func WithParentID(parentID NodeID) MessageOption
func WithTime ¶
func WithTime(time time.Time) MessageOption
type ToolResultContent ¶ added in v0.0.9
func (*ToolResultContent) ContentType ¶ added in v0.0.9
func (t *ToolResultContent) ContentType() ContentType
func (*ToolResultContent) String ¶ added in v0.0.9
func (t *ToolResultContent) String() string
func (*ToolResultContent) View ¶ added in v0.0.9
func (t *ToolResultContent) View() string
type ToolUseContent ¶ added in v0.0.9
type ToolUseContent struct { ToolID string `json:"toolID"` Name string `json:"name"` Input json.RawMessage `json:"input"` // used by openai currently (only function) Type string `json:"type"` }
func (*ToolUseContent) ContentType ¶ added in v0.0.9
func (t *ToolUseContent) ContentType() ContentType
func (*ToolUseContent) String ¶ added in v0.0.9
func (t *ToolUseContent) String() string
func (*ToolUseContent) View ¶ added in v0.0.9
func (t *ToolUseContent) View() string