storage

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConversationNotFound = errors.New("conversation is not found")
)

Functions

This section is empty.

Types

type Conversation

type Conversation struct {
	ID           string         `gorm:"column:id;primaryKey;type:uuid;comment:conversation id" json:"id" example:"5a41f3ca-763b-41ec-91c3-4bbbb00736d0"`
	AppName      string         `gorm:"column:app_name;type:string;comment:app name" json:"app_name" example:"chat-with-llm"`
	AppNamespace string         `gorm:"column:app_namespace;type:string;comment:app namespace" json:"app_namespace" example:"arcadia"`
	StartedAt    time.Time      `` /* 158-byte string literal not displayed */
	UpdatedAt    time.Time      `` /* 158-byte string literal not displayed */
	Messages     []Message      `gorm:"foreignKey:ConversationID" json:"messages"`
	User         string         `gorm:"column:user;type:string;comment:the conversation chat user" json:"-"`
	Debug        bool           `gorm:"column:debug;type:bool;comment:debug mode" json:"-"`
	DeletedAt    gorm.DeletedAt `gorm:"column:deleted_at;type:time;comment:the time the conversation deleted at" json:"-"`
	// icon only valid in conversation list api
	Icon string `gorm:"-" json:"icon"`
}

Conversation represent a conversation in storage

func (Conversation) TableName

func (Conversation) TableName() string

type ConversationStorage

type ConversationStorage interface {
	// FindExistingConversation searches for an existing conversation by ConversationID.
	//
	// ConversationID string, opts ...SearchOption
	// *Conversation, error
	FindExistingConversation(ID string, opts ...SearchOption) (*Conversation, error)
	// Delete deletes a conversation with the given options.
	//
	// It takes variadic SearchOption parameter(s) and returns an error.
	// **not** return error if the conversation is not found
	Delete(opts ...SearchOption) error
	// UpdateConversation updates the Conversation.
	//
	// It takes a pointer to a Conversation and returns an error.
	UpdateConversation(*Conversation) error
	// ListConversations returns a list of conversations based on the provided options.
	//
	// It accepts SearchOption(s) and returns a slice of Conversation and an error.
	ListConversations(opts ...SearchOption) ([]Conversation, error)
}

ConversationStorage interface

type Document

type Document struct {
	ID             string `gorm:"column:id;primaryKey;type:uuid;comment:document id" json:"id" example:"4f3546dd-5404-4bf8-a3bc-4fa3f9a7ba24"`
	Name           string `gorm:"column:name;type:string;comment:document name" json:"name" example:"kaoqin.pdf"`
	Object         string `` /* 126-byte string literal not displayed */
	ConversationID string `gorm:"column:conversation_id;type:uuid;comment:conversation id" json:"-"`
	MessageID      string `gorm:"column:message_id;type:uuid;comment:message id" json:"-"`
	Summary        string `gorm:"column:summary;type:string;comment:document summary" json:"summary" example:"kaoqin.pdf"`
}

func (Document) TableName

func (Document) TableName() string

type DocumentStorage

type DocumentStorage interface {
}

type MemoryStorage

type MemoryStorage struct {
	// contains filtered or unexported fields
}

func NewMemoryStorage

func NewMemoryStorage() *MemoryStorage

NewMemoryStorage creates a new MemoryStorage instance.

No parameters. Returns a pointer to MemoryStorage.

func (*MemoryStorage) CountMessages

func (m *MemoryStorage) CountMessages(appName, appNamespace string) (res int64, err error)

func (*MemoryStorage) Delete

func (m *MemoryStorage) Delete(opts ...SearchOption) (err error)

Delete deletes a conversation from MemoryStorage based on the provided options.

Parameter(s): opts ...SearchOption Return type(s): error

func (*MemoryStorage) FindExistingConversation

func (m *MemoryStorage) FindExistingConversation(conversationID string, opt ...SearchOption) (*Conversation, error)

FindExistingConversation searches for an existing conversation in MemoryStorage.

ConversationID string, opt ...SearchOption. Returns *Conversation, error.

func (*MemoryStorage) FindExistingDocument

func (m *MemoryStorage) FindExistingDocument(conversationID string, messageID string, documentID string, opts ...SearchOption) (*Document, error)

func (*MemoryStorage) FindExistingMessage

func (m *MemoryStorage) FindExistingMessage(conversationID string, messageID string, opts ...SearchOption) (*Message, error)

func (*MemoryStorage) ListConversations

func (m *MemoryStorage) ListConversations(opts ...SearchOption) (conversations []Conversation, err error)

ListConversations retrieves conversations from MemoryStorage based on the provided options. It takes in optional SearchOption(s) and returns a slice of Conversation and an error.

func (*MemoryStorage) UpdateConversation

func (m *MemoryStorage) UpdateConversation(conversation *Conversation) error

UpdateConversation updates a conversation in the MemoryStorage.

It takes a pointer to a Conversation as a parameter and returns an error.

type Message

type Message struct {
	ID             string `gorm:"column:id;primaryKey;type:uuid;comment:message id" json:"id" example:"4f3546dd-5404-4bf8-a3bc-4fa3f9a7ba24"`
	ConversationID string `gorm:"column:conversation_id;type:uuid;comment:conversation id" json:"-"`
	Latency        int64  `gorm:"column:latency;type:int;comment:request latency, in ms" json:"latency" example:"1000"`

	// Action indicates what is this message for
	// Chat(by default),UPLOAD,etc...
	Action string `gorm:"column:action;type:string;comment:user action" json:"action" example:"UPLOAD"`

	// For Action Chat
	Query string `gorm:"column:query;type:string;comment:user input" json:"query" example:"旷工最小计算单位为多少天?"`
	// Files that shall be used in this Chat
	Files      []string   `gorm:"-" json:"files"`
	RawFiles   string     `gorm:"column:files;type:string;comment:input files" json:"-"`
	Answer     string     `gorm:"column:answer;type:string;comment:ai response" json:"answer" example:"旷工最小计算单位为0.5天。"`
	References References `gorm:"column:references;type:json;comment:references" json:"references,omitempty"`

	// For Action Upload
	Documents []Document `gorm:"foreignKey:MessageID" json:"documents"`
}

Message represent a message in storage

func (*Message) AfterFind added in v0.2.1

func (m *Message) AfterFind(tx *gorm.DB) error

func (Message) TableName

func (Message) TableName() string

type MessageStorage

type MessageStorage interface {
	// FindExistingMessage finds a message in the conversation.
	//
	// It takes conversationID, messageID string parameters and returns *Message, error.
	FindExistingMessage(conversationID, messageID string, opts ...SearchOption) (*Message, error)
	// CountMessages count how many messages is about this app
	CountMessages(appName, appNamespace string) (int64, error)
}

type PostgreSQLStorage

type PostgreSQLStorage struct {
	// contains filtered or unexported fields
}

func NewPostgreSQLStorage

func NewPostgreSQLStorage(conn *pgx.Conn) (*PostgreSQLStorage, error)

func (*PostgreSQLStorage) CountMessages

func (p *PostgreSQLStorage) CountMessages(appName, appNamespace string) (int64, error)

func (*PostgreSQLStorage) Delete

func (p *PostgreSQLStorage) Delete(opts ...SearchOption) error

func (*PostgreSQLStorage) FindExistingConversation

func (p *PostgreSQLStorage) FindExistingConversation(conversationID string, opts ...SearchOption) (*Conversation, error)

func (*PostgreSQLStorage) FindExistingDocument

func (p *PostgreSQLStorage) FindExistingDocument(conversationID, messageID string, documentID string, opts ...SearchOption) (*Document, error)

func (*PostgreSQLStorage) FindExistingMessage

func (p *PostgreSQLStorage) FindExistingMessage(conversationID string, messageID string, opts ...SearchOption) (*Message, error)

func (*PostgreSQLStorage) ListConversations

func (p *PostgreSQLStorage) ListConversations(opts ...SearchOption) ([]Conversation, error)

func (*PostgreSQLStorage) UpdateConversation

func (p *PostgreSQLStorage) UpdateConversation(conversation *Conversation) error

type References

type References []retriever.Reference

func (*References) Scan

func (r *References) Scan(value interface{}) error

func (References) Value

func (r References) Value() (driver.Value, error)
type Search struct {
	ConversationID *string
	MessageID      *string
	AppName        *string
	AppNamespace   *string
	User           *string
	Debug          *bool
}

func NewSearchOptions

func NewSearchOptions(conversationID *string) *Search

type SearchOption

type SearchOption func(options *Search)

func WithAppName

func WithAppName(name string) SearchOption

WithAppName returns a Search for setting the AppName.

func WithAppNamespace

func WithAppNamespace(name string) SearchOption

WithAppNamespace returns a Search for setting the AppNamespace.

func WithConversationID

func WithConversationID(id string) SearchOption

WithConversationID returns a Search for setting the ConversationID.

func WithDebug

func WithDebug(debug bool) SearchOption

WithDebug returns a Search for setting the Debug.

func WithMessageID

func WithMessageID(id string) SearchOption

WithMessageID returns a Search for setting the MessageID.

func WithUser

func WithUser(name string) SearchOption

WithUser returns a Search for setting the User.

type Storage

Jump to

Keyboard shortcuts

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