Documentation ¶
Overview ¶
Package sqlite3 adds support for chat message history using sqlite3.
Index ¶
- Constants
- type SqliteChatMessageHistory
- func (h *SqliteChatMessageHistory) AddAIMessage(ctx context.Context, text string) error
- func (h *SqliteChatMessageHistory) AddMessage(ctx context.Context, message llms.ChatMessage) error
- func (h *SqliteChatMessageHistory) AddUserMessage(ctx context.Context, text string) error
- func (h *SqliteChatMessageHistory) Clear(ctx context.Context) error
- func (h *SqliteChatMessageHistory) Messages(ctx context.Context) ([]llms.ChatMessage, error)
- func (h *SqliteChatMessageHistory) SetMessages(ctx context.Context, messages []llms.ChatMessage) error
- type SqliteChatMessageHistoryOption
- func WithContext(ctx context.Context) SqliteChatMessageHistoryOption
- func WithDB(db *sql.DB) SqliteChatMessageHistoryOption
- func WithDBAddress(addr string) SqliteChatMessageHistoryOption
- func WithLimit(limit int) SqliteChatMessageHistoryOption
- func WithOverwrite() SqliteChatMessageHistoryOption
- func WithSchema(schema []byte) SqliteChatMessageHistoryOption
- func WithSession(session string) SqliteChatMessageHistoryOption
- func WithTableName(name string) SqliteChatMessageHistoryOption
Constants ¶
const DefaultLimit = 1000
DefaultLimit sets a default limit for select queries.
const DefaultSchema = `` /* 317-byte string literal not displayed */
DefaultSchema sets a default schema to be run after connecting.
const DefaultTableName = "langchaingo_messages"
DefaultTableName sets a default table name.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type SqliteChatMessageHistory ¶
type SqliteChatMessageHistory struct { // DB is the database connection. DB *sql.DB // Ctx is a context that can be used for the schema exec. //nolint:containedctx // This is used only when execing schema. Ctx context.Context // DBAddress is the address or file path for connecting the db. DBAddress string // TableName is the name of the messages table. TableName string // Limit is the max number of records per select. Limit int // Session defines a session name or id for a conversation. Session string // Schema defines a initial schema to be run. Schema []byte // Overwrite is a safety flag used for SetMessages and Clear functions. Overwrite bool }
SqliteChatMessageHistory is a struct that stores chat messages.
func NewSqliteChatMessageHistory ¶
func NewSqliteChatMessageHistory(options ...SqliteChatMessageHistoryOption) *SqliteChatMessageHistory
NewSqliteChatMessageHistory creates a new SqliteChatMessageHistory using chat message options.
func (*SqliteChatMessageHistory) AddAIMessage ¶
func (h *SqliteChatMessageHistory) AddAIMessage(ctx context.Context, text string) error
AddAIMessage adds an AIMessage to the chat message history.
func (*SqliteChatMessageHistory) AddMessage ¶
func (h *SqliteChatMessageHistory) AddMessage(ctx context.Context, message llms.ChatMessage) error
AddMessage adds a message to the chat message history.
func (*SqliteChatMessageHistory) AddUserMessage ¶
func (h *SqliteChatMessageHistory) AddUserMessage(ctx context.Context, text string) error
AddUserMessage adds a user to the chat message history.
func (*SqliteChatMessageHistory) Clear ¶
func (h *SqliteChatMessageHistory) Clear(ctx context.Context) error
Clear resets messages.
func (*SqliteChatMessageHistory) Messages ¶
func (h *SqliteChatMessageHistory) Messages(ctx context.Context) ([]llms.ChatMessage, error)
Messages returns all messages stored.
func (*SqliteChatMessageHistory) SetMessages ¶
func (h *SqliteChatMessageHistory) SetMessages(ctx context.Context, messages []llms.ChatMessage) error
SetMessages resets chat history and bulk insert new messages into it.
type SqliteChatMessageHistoryOption ¶
type SqliteChatMessageHistoryOption func(m *SqliteChatMessageHistory)
SqliteChatMessageHistoryOption is a function for creating new chat message history with other than the default values.
func WithContext ¶
func WithContext(ctx context.Context) SqliteChatMessageHistoryOption
WithContext is an option for NewSqliteChatMessageHistory to use a context internally when running Schema.
func WithDB ¶
func WithDB(db *sql.DB) SqliteChatMessageHistoryOption
WithDB is an option for NewSqliteChatMessageHistory for adding a database connection.
func WithDBAddress ¶
func WithDBAddress(addr string) SqliteChatMessageHistoryOption
WithDBAddress is an option for NewSqliteChatMessageHistory for specifying an address or file path for when connecting the db.
func WithLimit ¶
func WithLimit(limit int) SqliteChatMessageHistoryOption
WithLimit is an option for NewSqliteChatMessageHistory for defining a limit number for select queries.
func WithOverwrite ¶
func WithOverwrite() SqliteChatMessageHistoryOption
WithOverwrite is an option for NewSqliteChatMessageHistory for allowing dangerous operations like SetMessages or Clear.
func WithSchema ¶
func WithSchema(schema []byte) SqliteChatMessageHistoryOption
WithSchema is an option for NewSqliteChatMessageHistory for running a schema when connected. Useful for migrations for example.
func WithSession ¶
func WithSession(session string) SqliteChatMessageHistoryOption
WithSession is an option for NewSqliteChatMessageHistory for setting a session name or id for the history.
func WithTableName ¶
func WithTableName(name string) SqliteChatMessageHistoryOption
WithTableName is an option for NewSqliteChatMessageHistory for running a schema when connected. Useful for migrations for example.