table

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2025 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CREATE_TABLE_TEMPERATURE  = 0.1
	CREATE_TABLE_MAX_TOKENS   = 3000
	GENERATE_DATA_TEMPERATURE = 0.6
	GENERATE_DATA_MAX_TOKENS  = 6000
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AIRowsGenerator

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

func NewRowsGenerator

func NewRowsGenerator(ctx context.Context, params GenerateRowsRequest, db *ent.Client, ai ai.AiService, logger *zap.SugaredLogger) (*AIRowsGenerator, error)

func (*AIRowsGenerator) Next

func (g *AIRowsGenerator) Next(ctx context.Context) ([]map[string]*schema.CellValue, error)

func (*AIRowsGenerator) Table

func (g *AIRowsGenerator) Table() *ent.TableMeta

type AutofillRequest added in v0.0.6

type AutofillRequest struct {
	Enable         bool     `json:"enable"`
	Offset         int      `json:"offset"`
	Columns        []string `json:"columns"`
	ContextColumns []string `json:"context_columns"`
}

type ColumnSchema

type ColumnSchema struct {
	Id       string `json:"id"`
	Name     string `json:"name"`
	Type     string `json:"type"`
	LinkedTo string `json:"linked_to"`
	Mode     string `json:"mode"`
}

type CreateRowsRequest added in v0.0.7

type CreateRowsRequest struct {
	Rows []map[string]any `json:"rows"`
}

type GenerateRowsRequest added in v0.0.2

type GenerateRowsRequest struct {
	Table       string  `json:"table"`
	SaveTo      string  `json:"save_to"`
	Count       int     `json:"count"`
	Batch       int     `json:"batch"`
	Temperature float64 `json:"temperature"`
	Model       string  `json:"model"`
	// used `json:""` in API only to send streaming results
	Stream bool `json:"stream"`

	Autofill AutofillRequest `json:"autofill"`
}

type ListTablesResponse

type ListTablesResponse struct {
	Total  int         `json:"total"`
	Tables []TableInfo `json:"tables"`
}

type Rows

type Rows struct {
	Columns []*ent.TableColumn `json:"columns"`
	Rows    []*ent.TableRow    `json:"rows"`
}

type RowsGenerator

type RowsGenerator interface {
	Next(ctx context.Context) ([]map[string]*schema.CellValue, error)
	Table() *ent.TableMeta
}

type RowsGeneratorMock

type RowsGeneratorMock struct {
	// NextFunc mocks the Next method.
	NextFunc func(ctx context.Context) ([]map[string]*schema.CellValue, error)

	// TableFunc mocks the Table method.
	TableFunc func() *ent.TableMeta
	// contains filtered or unexported fields
}

RowsGeneratorMock is a mock implementation of RowsGenerator.

func TestSomethingThatUsesRowsGenerator(t *testing.T) {

	// make and configure a mocked RowsGenerator
	mockedRowsGenerator := &RowsGeneratorMock{
		NextFunc: func(ctx context.Context) ([]map[string]*schema.CellValue, error) {
			panic("mock out the Next method")
		},
		TableFunc: func() *ent.TableMeta {
			panic("mock out the Table method")
		},
	}

	// use mockedRowsGenerator in code that requires RowsGenerator
	// and then make assertions.

}

func (*RowsGeneratorMock) Next

func (mock *RowsGeneratorMock) Next(ctx context.Context) ([]map[string]*schema.CellValue, error)

Next calls NextFunc.

func (*RowsGeneratorMock) NextCalls

func (mock *RowsGeneratorMock) NextCalls() []struct {
	Ctx context.Context
}

NextCalls gets all the calls that were made to Next. Check the length with:

len(mockedRowsGenerator.NextCalls())

func (*RowsGeneratorMock) Table

func (mock *RowsGeneratorMock) Table() *ent.TableMeta

Table calls TableFunc.

func (*RowsGeneratorMock) TableCalls

func (mock *RowsGeneratorMock) TableCalls() []struct {
}

TableCalls gets all the calls that were made to Table. Check the length with:

len(mockedRowsGenerator.TableCalls())

type TableColumnInfo

type TableColumnInfo struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Type        string `json:"type"`
	FillMode    string `json:"fill_mode"`
}

type TableGenColumn

type TableGenColumn struct {
	Name          string `json:"name"`
	Description   string `json:"description"`
	Type          string `json:"type"`
	FillMode      string `json:"fill_mode"`
	Source        string `json:"source"`
	Repeat        int    `json:"repeat"`
	ContextLength int    `json:"context_length"`
}

type TableGenColumnSchema

type TableGenColumnSchema struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	Type        string `json:"type"`
}

type TableGenRequest

type TableGenRequest struct {
	Name        string            `json:"name"`
	Model       string            `json:"model"`
	Description string            `json:"description"`
	Columns     []TableGenColumn  `json:"columns"`
	Sources     []json.RawMessage `json:"sources"`
}

type TableInfo added in v0.0.3

type TableInfo struct {
	ID          string            `json:"id"`
	Name        string            `json:"name"`
	Description string            `json:"description"`
	Model       string            `json:"model"`
	Columns     []TableColumnInfo `json:"columns"`
}

type TableService

type TableService interface {
	CreateTable(ctx context.Context, req *TableGenRequest) (string, error)
	ListTables(ctx context.Context) (*ListTablesResponse, error)
	GetTableDetail(ctx context.Context, table string) (*TableInfo, error)
	Genetate(ctx context.Context, params GenerateRowsRequest) (RowsGenerator, error)
	Rows(ctx context.Context, table string) (*Rows, error)
	Truncate(ctx context.Context, table string) (int, error)
	Delete(ctx context.Context, table string) (int, error)
	Import(ctx context.Context, table string, reader io.Reader) (string, error)
	CreateRows(ctx context.Context, table string, rows []map[string]any) error
}

type TableServiceImpl

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

func NewTableService

func NewTableService(config *config.Config, db *ent.Client, ai ai.AiService, logger *zap.SugaredLogger) *TableServiceImpl

func (*TableServiceImpl) CreateRows added in v0.0.7

func (t *TableServiceImpl) CreateRows(ctx context.Context, table string, rows []map[string]any) error

func (*TableServiceImpl) CreateTable

func (t *TableServiceImpl) CreateTable(ctx context.Context, req *TableGenRequest) (string, error)

func (*TableServiceImpl) Delete

func (t *TableServiceImpl) Delete(ctx context.Context, table string) (int, error)

func (*TableServiceImpl) Genetate

func (*TableServiceImpl) GetTableDetail added in v0.0.3

func (t *TableServiceImpl) GetTableDetail(ctx context.Context, table string) (*TableInfo, error)

func (*TableServiceImpl) Import

func (t *TableServiceImpl) Import(ctx context.Context, table string, reader io.Reader) (string, error)

func (*TableServiceImpl) ListTables

func (t *TableServiceImpl) ListTables(ctx context.Context) (*ListTablesResponse, error)

func (*TableServiceImpl) Rows

func (t *TableServiceImpl) Rows(ctx context.Context, table string) (*Rows, error)

func (*TableServiceImpl) Truncate

func (t *TableServiceImpl) Truncate(ctx context.Context, table string) (int, error)

type TableServiceMock

type TableServiceMock struct {
	// CreateRowsFunc mocks the CreateRows method.
	CreateRowsFunc func(ctx context.Context, table string, rows []map[string]any) error

	// CreateTableFunc mocks the CreateTable method.
	CreateTableFunc func(ctx context.Context, req *TableGenRequest) (string, error)

	// DeleteFunc mocks the Delete method.
	DeleteFunc func(ctx context.Context, table string) (int, error)

	// GenetateFunc mocks the Genetate method.
	GenetateFunc func(ctx context.Context, params GenerateRowsRequest) (RowsGenerator, error)

	// GetTableDetailFunc mocks the GetTableDetail method.
	GetTableDetailFunc func(ctx context.Context, table string) (*TableInfo, error)

	// ImportFunc mocks the Import method.
	ImportFunc func(ctx context.Context, table string, reader io.Reader) (string, error)

	// ListTablesFunc mocks the ListTables method.
	ListTablesFunc func(ctx context.Context) (*ListTablesResponse, error)

	// RowsFunc mocks the Rows method.
	RowsFunc func(ctx context.Context, table string) (*Rows, error)

	// TruncateFunc mocks the Truncate method.
	TruncateFunc func(ctx context.Context, table string) (int, error)
	// contains filtered or unexported fields
}

TableServiceMock is a mock implementation of TableService.

func TestSomethingThatUsesTableService(t *testing.T) {

	// make and configure a mocked TableService
	mockedTableService := &TableServiceMock{
		CreateRowsFunc: func(ctx context.Context, table string, rows []map[string]any) error {
			panic("mock out the CreateRows method")
		},
		CreateTableFunc: func(ctx context.Context, req *TableGenRequest) (string, error) {
			panic("mock out the CreateTable method")
		},
		DeleteFunc: func(ctx context.Context, table string) (int, error) {
			panic("mock out the Delete method")
		},
		GenetateFunc: func(ctx context.Context, params GenerateRowsRequest) (RowsGenerator, error) {
			panic("mock out the Genetate method")
		},
		GetTableDetailFunc: func(ctx context.Context, table string) (*TableInfo, error) {
			panic("mock out the GetTableDetail method")
		},
		ImportFunc: func(ctx context.Context, table string, reader io.Reader) (string, error) {
			panic("mock out the Import method")
		},
		ListTablesFunc: func(ctx context.Context) (*ListTablesResponse, error) {
			panic("mock out the ListTables method")
		},
		RowsFunc: func(ctx context.Context, table string) (*Rows, error) {
			panic("mock out the Rows method")
		},
		TruncateFunc: func(ctx context.Context, table string) (int, error) {
			panic("mock out the Truncate method")
		},
	}

	// use mockedTableService in code that requires TableService
	// and then make assertions.

}

func (*TableServiceMock) CreateRows added in v0.0.7

func (mock *TableServiceMock) CreateRows(ctx context.Context, table string, rows []map[string]any) error

CreateRows calls CreateRowsFunc.

func (*TableServiceMock) CreateRowsCalls added in v0.0.7

func (mock *TableServiceMock) CreateRowsCalls() []struct {
	Ctx   context.Context
	Table string
	Rows  []map[string]any
}

CreateRowsCalls gets all the calls that were made to CreateRows. Check the length with:

len(mockedTableService.CreateRowsCalls())

func (*TableServiceMock) CreateTable

func (mock *TableServiceMock) CreateTable(ctx context.Context, req *TableGenRequest) (string, error)

CreateTable calls CreateTableFunc.

func (*TableServiceMock) CreateTableCalls

func (mock *TableServiceMock) CreateTableCalls() []struct {
	Ctx context.Context
	Req *TableGenRequest
}

CreateTableCalls gets all the calls that were made to CreateTable. Check the length with:

len(mockedTableService.CreateTableCalls())

func (*TableServiceMock) Delete

func (mock *TableServiceMock) Delete(ctx context.Context, table string) (int, error)

Delete calls DeleteFunc.

func (*TableServiceMock) DeleteCalls

func (mock *TableServiceMock) DeleteCalls() []struct {
	Ctx   context.Context
	Table string
}

DeleteCalls gets all the calls that were made to Delete. Check the length with:

len(mockedTableService.DeleteCalls())

func (*TableServiceMock) Genetate

func (mock *TableServiceMock) Genetate(ctx context.Context, params GenerateRowsRequest) (RowsGenerator, error)

Genetate calls GenetateFunc.

func (*TableServiceMock) GenetateCalls

func (mock *TableServiceMock) GenetateCalls() []struct {
	Ctx    context.Context
	Params GenerateRowsRequest
}

GenetateCalls gets all the calls that were made to Genetate. Check the length with:

len(mockedTableService.GenetateCalls())

func (*TableServiceMock) GetTableDetail added in v0.0.3

func (mock *TableServiceMock) GetTableDetail(ctx context.Context, table string) (*TableInfo, error)

GetTableDetail calls GetTableDetailFunc.

func (*TableServiceMock) GetTableDetailCalls added in v0.0.3

func (mock *TableServiceMock) GetTableDetailCalls() []struct {
	Ctx   context.Context
	Table string
}

GetTableDetailCalls gets all the calls that were made to GetTableDetail. Check the length with:

len(mockedTableService.GetTableDetailCalls())

func (*TableServiceMock) Import

func (mock *TableServiceMock) Import(ctx context.Context, table string, reader io.Reader) (string, error)

Import calls ImportFunc.

func (*TableServiceMock) ImportCalls

func (mock *TableServiceMock) ImportCalls() []struct {
	Ctx    context.Context
	Table  string
	Reader io.Reader
}

ImportCalls gets all the calls that were made to Import. Check the length with:

len(mockedTableService.ImportCalls())

func (*TableServiceMock) ListTables

func (mock *TableServiceMock) ListTables(ctx context.Context) (*ListTablesResponse, error)

ListTables calls ListTablesFunc.

func (*TableServiceMock) ListTablesCalls

func (mock *TableServiceMock) ListTablesCalls() []struct {
	Ctx context.Context
}

ListTablesCalls gets all the calls that were made to ListTables. Check the length with:

len(mockedTableService.ListTablesCalls())

func (*TableServiceMock) Rows

func (mock *TableServiceMock) Rows(ctx context.Context, table string) (*Rows, error)

Rows calls RowsFunc.

func (*TableServiceMock) RowsCalls

func (mock *TableServiceMock) RowsCalls() []struct {
	Ctx   context.Context
	Table string
}

RowsCalls gets all the calls that were made to Rows. Check the length with:

len(mockedTableService.RowsCalls())

func (*TableServiceMock) Truncate

func (mock *TableServiceMock) Truncate(ctx context.Context, table string) (int, error)

Truncate calls TruncateFunc.

func (*TableServiceMock) TruncateCalls

func (mock *TableServiceMock) TruncateCalls() []struct {
	Ctx   context.Context
	Table string
}

TruncateCalls gets all the calls that were made to Truncate. Check the length with:

len(mockedTableService.TruncateCalls())

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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