Documentation ¶
Index ¶
- Constants
- Variables
- func MatchSha1(s string) bool
- func NewConversationID() string
- func RegisterConversationStore(factory Factory)
- type CacheDetailsMsg
- type ChatMessageHistory
- type ContentType
- type Conversation
- type Factory
- type LoadContext
- type LoadContextStore
- type SimpleChatHistoryStore
- func (h *SimpleChatHistoryStore) AddAIMessage(ctx context.Context, convoID, message string) error
- func (h *SimpleChatHistoryStore) AddMessage(_ context.Context, convoID string, message llms.ChatMessage) error
- func (h *SimpleChatHistoryStore) AddUserMessage(ctx context.Context, convoID, message string) error
- func (h *SimpleChatHistoryStore) InvalidateMessages(_ context.Context, convoID string) error
- func (h *SimpleChatHistoryStore) Messages(_ context.Context, convoID string) ([]llms.ChatMessage, error)
- func (h *SimpleChatHistoryStore) PersistentMessages(_ context.Context, convoID string) error
- func (h *SimpleChatHistoryStore) SetMessages(ctx context.Context, convoID string, messages []llms.ChatMessage) error
- type Store
Constants ¶
const ( Sha1short = 7 Sha1minLen = 4 Sha1ReadBlockSize = 4096 )
Variables ¶
var Sha1reg = regexp.MustCompile(`\b[0-9a-f]{40}\b`)
Functions ¶
func NewConversationID ¶
func NewConversationID() string
func RegisterConversationStore ¶
func RegisterConversationStore(factory Factory)
Types ¶
type CacheDetailsMsg ¶ added in v0.13.0
type CacheDetailsMsg struct { WriteID string // ID to write cache to ReadID string // ID to read cache from Title string // Title of the conversation Model string // Model used for the conversation }
CacheDetailsMsg contains details about a cached conversation
func GetCurrentConversationID ¶ added in v0.13.0
func GetCurrentConversationID(ctx context.Context, cfg *options.Config, store Store) (CacheDetailsMsg, error)
GetCurrentConversationID handles the logic for determining the current conversation ID based on config parameters and existing conversations
type ChatMessageHistory ¶
type ChatMessageHistory interface { // AddAIMessage is a convenience method for adding an AI message string to // the store. AddAIMessage(ctx context.Context, convoID, message string) error // AddUserMessage is a convenience method for adding a human message string // to the store. AddUserMessage(ctx context.Context, convoID, message string) error // AddMessage adds a message to the store. AddMessage(ctx context.Context, convoID string, message llms.ChatMessage) error // SetMessages replaces existing messages in the store SetMessages(ctx context.Context, convoID string, messages []llms.ChatMessage) error // Messages retrieves all messages from the store Messages(ctx context.Context, convoID string) ([]llms.ChatMessage, error) // PersistentMessages saves messages to persistent storage PersistentMessages(ctx context.Context, convoID string) error // InvalidateMessages removes messages from persistent storage InvalidateMessages(ctx context.Context, convoID string) error }
type ContentType ¶
type ContentType string
ContentType defines the type of content being loaded into the convo. It can be one of: file, URL, or plain text.
const ( // ContentTypeFile represents content loaded from a local file ContentTypeFile ContentType = "file" // ContentTypeURL represents content loaded from a remote URL ContentTypeURL ContentType = "url" // ContentTypeText represents direct text content ContentTypeText ContentType = "text" )
type Conversation ¶
type Conversation struct { // ID is the unique identifier for the convo ID string `db:"id" json:"id"` // Title is a human-readable name for the convo Title string `db:"title" json:"title"` // UpdatedAt tracks the last modification time of the convo UpdatedAt time.Time `db:"updated_at" json:"updatedAt"` // Model optionally specifies the AI model used in the convo Model *string `db:"model" json:"model"` }
Conversation represents a chat convo with metadata and convo. It tracks the convo ID, title, last update time, and optional model info.
type LoadContext ¶
type LoadContext struct { // ID is the auto-increment primary key ID uint64 `db:"id" json:"id"` // Type indicates the content source type (file, URL, or text) Type ContentType `db:"type" json:"type"` // URL contains the source URL if loading from a remote resource URL string `db:"url" json:"url"` // FilePath contains the local file path if loading from a file FilePath string `db:"file_path" json:"filePath"` // Content contains the actual loaded content as a string Content string `db:"content" json:"content"` // Name is a human-readable identifier for the content Name string `db:"name" json:"name"` // ConversationID associates the content with a specific convo ConversationID string `db:"conversation_id" json:"conversationId"` // UpdatedAt tracks the last modification time of the convo UpdatedAt time.Time `db:"updated_at" json:"updatedAt"` }
LoadContext contains metadata and content information for loaded resources. It tracks the source, type, convo association, and additional metadata about the content being used in conversations.
type LoadContextStore ¶
type LoadContextStore interface { // SaveContext saves a load context SaveContext(ctx context.Context, lc *LoadContext) error // GetContext retrieves a load context by ID GetContext(ctx context.Context, id uint64) (*LoadContext, error) // ListContextsByteConvoID retrieves all load contexts for a convo ListContextsByteConvoID(ctx context.Context, conversationID string) ([]LoadContext, error) // DeleteContexts removes a load context DeleteContexts(ctx context.Context, id uint64) error // CleanContexts removes all load contexts for a convo and returns the count deleted CleanContexts(ctx context.Context, conversationID string) (int64, error) }
LoadContextStore manages loaded content contexts
type SimpleChatHistoryStore ¶
type SimpleChatHistoryStore struct {
// contains filtered or unexported fields
}
func NewSimpleChatHistoryStore ¶
func NewSimpleChatHistoryStore(dir string) *SimpleChatHistoryStore
func (*SimpleChatHistoryStore) AddAIMessage ¶
func (h *SimpleChatHistoryStore) AddAIMessage(ctx context.Context, convoID, message string) error
AddAIMessage adds an AIMessage to the chat message convo.
func (*SimpleChatHistoryStore) AddMessage ¶
func (h *SimpleChatHistoryStore) AddMessage(_ context.Context, convoID string, message llms.ChatMessage) error
func (*SimpleChatHistoryStore) AddUserMessage ¶
func (h *SimpleChatHistoryStore) AddUserMessage(ctx context.Context, convoID, message string) error
AddUserMessage adds a user to the chat message convo.
func (*SimpleChatHistoryStore) InvalidateMessages ¶
func (h *SimpleChatHistoryStore) InvalidateMessages(_ context.Context, convoID string) error
func (*SimpleChatHistoryStore) Messages ¶
func (h *SimpleChatHistoryStore) Messages(_ context.Context, convoID string) ([]llms.ChatMessage, error)
func (*SimpleChatHistoryStore) PersistentMessages ¶
func (h *SimpleChatHistoryStore) PersistentMessages(_ context.Context, convoID string) error
func (*SimpleChatHistoryStore) SetMessages ¶
func (h *SimpleChatHistoryStore) SetMessages(ctx context.Context, convoID string, messages []llms.ChatMessage) error
type Store ¶
type Store interface { ChatMessageHistory LoadContextStore // LatestConversation returns the last message in the chat convo. LatestConversation(ctx context.Context) (*Conversation, error) // GetConversation retrieves a convo from the store GetConversation(ctx context.Context, convoID string) (*Conversation, error) // ListConversations retrieves all convo id from the store ListConversations(ctx context.Context) ([]Conversation, error) // ListConversationsOlderThan retrieves all convo id from the store that are older than the given time. ListConversationsOlderThan(ctx context.Context, t time.Duration) ([]Conversation, error) // SaveConversation saves a convo to the store SaveConversation(ctx context.Context, id, title, model string) error // DeleteConversation removes a convo from the store DeleteConversation(ctx context.Context, convoID string) error // ClearConversations removes all convo from the store. ClearConversations(ctx context.Context) error // ConversationExists checks if the given chat convo exists. ConversationExists(ctx context.Context, sessionID string) (bool, error) }
Store is the interface for chat convo convo store.