datastore

package
v0.0.0-...-5e664b8 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2024 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProgramStatusActive                           = 1
	ProgramStatusArchived                         = 2
	ProgramBusinessFunctionCustomerDocumentReview = 1
	ProgramBusinessFunctionAdmintorDocumentReview = 2
)
View Source
const (
	OrderAscending  = 1
	OrderDescending = -1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Program

type Program struct {
	// The name of the assistant to be available to administators in-app and on OpenAI dashboard.
	Name string `bson:"name" json:"name"`
	// Description to include for this assistant, used only by app
	Description string `bson:"description" json:"description"`
	// The OpenAI prompt to utilize for this assistant.
	Instructions string `bson:"instructions" json:"instructions"`
	// Model holds the OpenAI completion model to utilize, to see list then visit: https://github.com/sashabaranov/go-openai/blob/eff8dc1118ea82a1b50ee316608e24d83df74d6b/completion.go
	Model string `bson:"model" json:"model"`
	// Variable controls how this assistant is running in-app.
	Status int8 `bson:"status" json:"status"`
	// The unique identifier used in-app powered by MongoDB.
	SortNumber int8 `bson:"sort_number" json:"sort_number"`
	// The type of program being employed.
	BusinessFunction      int8                  `bson:"business_function" json:"business_function"`
	Directories           []*UploadFolderOption `bson:"directories" json:"directories,omitempty"`
	OpenAIAssistantID     string                `bson:"openai_assistant_id" json:"openai_assistant_id"` // https://platform.openai.com/docs/assistants/tools/supported-files
	ID                    primitive.ObjectID    `bson:"_id" json:"id"`
	TenantID              primitive.ObjectID    `bson:"tenant_id" json:"tenant_id"`
	PublicID              uint64                `bson:"public_id" json:"public_id"`
	CreatedAt             time.Time             `bson:"created_at" json:"created_at"`
	CreatedByUserID       primitive.ObjectID    `bson:"created_by_user_id" json:"created_by_user_id,omitempty"`
	CreatedByUserName     string                `bson:"created_by_user_name" json:"created_by_user_name"`
	CreatedFromIPAddress  string                `bson:"created_from_ip_address" json:"created_from_ip_address"`
	ModifiedAt            time.Time             `bson:"modified_at" json:"modified_at"`
	ModifiedByUserID      primitive.ObjectID    `bson:"modified_by_user_id" json:"modified_by_user_id,omitempty"`
	ModifiedByUserName    string                `bson:"modified_by_user_name" json:"modified_by_user_name"`
	ModifiedFromIPAddress string                `bson:"modified_from_ip_address" json:"modified_from_ip_address"`
}

func (*Program) GetOpenAIFileIDs

func (p *Program) GetOpenAIFileIDs() []string

GetOpenAIFileIDs function will iterate through all the assistant files and return the OpenAI file ID values.

func (*Program) GetUploadDirectoryIDs

func (p *Program) GetUploadDirectoryIDs() []primitive.ObjectID

type ProgramAsSelectOption

type ProgramAsSelectOption struct {
	Value primitive.ObjectID `bson:"_id" json:"value"` // Extract from the database `_id` field and output through API as `value`.
	Label string             `bson:"text" json:"label"`
}

type ProgramListResult

type ProgramListResult struct {
	Results     []*Program         `json:"results"`
	NextCursor  primitive.ObjectID `json:"next_cursor"`
	HasNextPage bool               `json:"has_next_page"`
}

type ProgramPaginationListFilter

type ProgramPaginationListFilter struct {
	// Pagination related.
	Cursor    string
	PageSize  int64
	SortField string
	SortOrder int8 // 1=ascending | -1=descending

	// Filter related.
	TenantID   primitive.ObjectID
	Status     int8
	SearchText string
}

type ProgramPaginationListResult

type ProgramPaginationListResult struct {
	Results     []*Program `json:"results"`
	NextCursor  string     `json:"next_cursor"`
	HasNextPage bool       `json:"has_next_page"`
}

ProgramPaginationListResult represents the paginated list results for the associate records.

type ProgramStorer

type ProgramStorer interface {
	Create(ctx context.Context, m *Program) error
	CreateOrGetByID(ctx context.Context, hh *Program) (*Program, error)
	GetByID(ctx context.Context, id primitive.ObjectID) (*Program, error)
	GetByPublicID(ctx context.Context, oldID uint64) (*Program, error)
	GetByText(ctx context.Context, text string) (*Program, error)
	GetLatestByTenantID(ctx context.Context, tenantID primitive.ObjectID) (*Program, error)
	CheckIfExistsByEmail(ctx context.Context, email string) (bool, error)
	UpdateByID(ctx context.Context, m *Program) error
	ListByFilter(ctx context.Context, f *ProgramPaginationListFilter) (*ProgramPaginationListResult, error)
	ListAsSelectOptionByFilter(ctx context.Context, f *ProgramPaginationListFilter) ([]*ProgramAsSelectOption, error)
	ListByTenantID(ctx context.Context, tid primitive.ObjectID) (*ProgramPaginationListResult, error)
	DeleteByID(ctx context.Context, id primitive.ObjectID) error
}

ProgramStorer Interface for user.

func NewDatastore

func NewDatastore(appCfg *c.Conf, loggerp *slog.Logger, client *mongo.Client) ProgramStorer

type ProgramStorerImpl

type ProgramStorerImpl struct {
	Logger     *slog.Logger
	DbClient   *mongo.Client
	Collection *mongo.Collection
}

func (ProgramStorerImpl) CheckIfExistsByEmail

func (impl ProgramStorerImpl) CheckIfExistsByEmail(ctx context.Context, email string) (bool, error)

func (ProgramStorerImpl) Create

func (impl ProgramStorerImpl) Create(ctx context.Context, u *Program) error

func (ProgramStorerImpl) CreateOrGetByID

func (impl ProgramStorerImpl) CreateOrGetByID(ctx context.Context, hh *Program) (*Program, error)

func (ProgramStorerImpl) DeleteByID

func (impl ProgramStorerImpl) DeleteByID(ctx context.Context, id primitive.ObjectID) error

func (ProgramStorerImpl) GetByID

func (impl ProgramStorerImpl) GetByID(ctx context.Context, id primitive.ObjectID) (*Program, error)

func (ProgramStorerImpl) GetByPublicID

func (impl ProgramStorerImpl) GetByPublicID(ctx context.Context, oldID uint64) (*Program, error)

func (ProgramStorerImpl) GetByText

func (impl ProgramStorerImpl) GetByText(ctx context.Context, text string) (*Program, error)

func (ProgramStorerImpl) GetLatestByTenantID

func (impl ProgramStorerImpl) GetLatestByTenantID(ctx context.Context, tenantID primitive.ObjectID) (*Program, error)

func (ProgramStorerImpl) ListAsSelectOptionByFilter

func (impl ProgramStorerImpl) ListAsSelectOptionByFilter(ctx context.Context, f *ProgramPaginationListFilter) ([]*ProgramAsSelectOption, error)

func (ProgramStorerImpl) ListByFilter

func (ProgramStorerImpl) ListByTenantID

func (ProgramStorerImpl) UpdateByID

func (impl ProgramStorerImpl) UpdateByID(ctx context.Context, m *Program) error

type UploadFileOption

type UploadFileOption struct {
	ID           primitive.ObjectID `bson:"_id" json:"id"`
	Name         string             `bson:"name" json:"name"`
	Description  string             `bson:"description" json:"description"`
	OpenAIFileID string             `bson:"openai_file_id" json:"openai_file_id"` // https://platform.openai.com/docs/assistants/tools/supported-files
	Status       int8               `bson:"status" json:"status"`
}

type UploadFolderOption

type UploadFolderOption struct {
	ID          primitive.ObjectID  `bson:"_id" json:"id"`
	Name        string              `bson:"name" json:"name"`
	Description string              `bson:"description" json:"description"`
	Status      int8                `bson:"status" json:"status"`
	Files       []*UploadFileOption `bson:"files" json:"files,omitempty"`
}

Jump to

Keyboard shortcuts

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