sqlite3

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package sqlite3 adds support for chat message history using sqlite3.

Index

Constants

View Source
const DefaultLimit = 1000

DefaultLimit sets a default limit for select queries.

View Source
const DefaultSchema = `` /* 317-byte string literal not displayed */

DefaultSchema sets a default schema to be run after connecting.

View Source
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

Clear resets messages.

func (*SqliteChatMessageHistory) Messages

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

WithContext is an option for NewSqliteChatMessageHistory to use a context internally when running Schema.

func WithDB

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL