diagram

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateRequestsQuotaUsage added in v0.0.5

func ValidateRequestsQuotaUsage(ctx context.Context, clientRepository RepositoryPrediction, user *User) (
	throttling bool, quotaExceeded bool, err error,
)

ValidateRequestsQuotaUsage checks if the requests' quota was exceeded.

Types

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient client to communicate over http.

type HTTPHandler added in v0.0.5

type HTTPHandler func(ctx context.Context, input Input) (Output, error)

HTTPHandler handler to generate a diagram given the input.

type Input

type Input interface {
	Validate() error
	GetUser() *User
	GetPrompt() string
	GetRequestID() string
}

Input defines the entrypoint interface.

func NewInput added in v0.0.5

func NewInput(prompt string, user *User) (Input, error)

NewInput initialises the `Input` object.

type MockHTTPClient

type MockHTTPClient struct {
	V   *http.Response
	Err error
}

func (MockHTTPClient) Do

type MockInput

type MockInput struct {
	Err       error
	Prompt    string
	RequestID string
	User      *User
}

func (MockInput) GetPrompt

func (v MockInput) GetPrompt() string

func (MockInput) GetRequestID

func (v MockInput) GetRequestID() string

func (MockInput) GetUser

func (v MockInput) GetUser() *User

func (MockInput) Validate

func (v MockInput) Validate() error

type MockModelInference

type MockModelInference struct {
	V               []byte
	UsagePrompt     uint16
	UsageCompletion uint16
	Err             error
}

func (MockModelInference) Do

type MockOutput

type MockOutput struct {
	V   []byte
	Err error
}

func (MockOutput) Serialize

func (m MockOutput) Serialize() ([]byte, error)

type MockRepositoryPrediction

type MockRepositoryPrediction struct {
	Timestamps []time.Time
	Err        error
}

func (MockRepositoryPrediction) Close

func (MockRepositoryPrediction) GetDailySuccessfulResultsTimestampsByUserID added in v0.0.5

func (m MockRepositoryPrediction) GetDailySuccessfulResultsTimestampsByUserID(_ context.Context, _ string) (
	[]time.Time, error,
)

func (MockRepositoryPrediction) WriteInputPrompt

func (m MockRepositoryPrediction) WriteInputPrompt(_ context.Context, _, _, _ string) error

func (MockRepositoryPrediction) WriteModelResult

func (m MockRepositoryPrediction) WriteModelResult(_ context.Context, _, _, _, _, _ string, _, _ uint16) error

func (MockRepositoryPrediction) WriteSuccessFlag added in v0.0.5

func (m MockRepositoryPrediction) WriteSuccessFlag(_ context.Context, _, _, _ string) error

type MockRepositorySecretsVault

type MockRepositorySecretsVault struct {
	V   []byte
	Err error
}

func (MockRepositorySecretsVault) ReadLastVersion

func (m MockRepositorySecretsVault) ReadLastVersion(_ context.Context, _ string, o interface{}) error

type MockRepositoryToken added in v0.0.5

type MockRepositoryToken struct {
	V   string
	Err error
}

func (MockRepositoryToken) GetActiveUserIDByActiveTokenID added in v0.0.5

func (m MockRepositoryToken) GetActiveUserIDByActiveTokenID(_ context.Context, _ string) (string, error)

type ModelInference

type ModelInference interface {
	Do(ctx context.Context, userPrompt string, systemContent string, model string) (
		predictionRaw string, prediction []byte, usageTokensPrompt uint16, usageTokensCompletions uint16, err error,
	)
}

ModelInference interface to communicate with the model.

type Output

type Output interface {
	Serialize() ([]byte, error)
}

Output defines the exit point's interface.

func NewResultSVG

func NewResultSVG(v []byte) (Output, error)

NewResultSVG create a response object with the SVG diagram.

type QuotaRequestsConsumption added in v0.0.5

type QuotaRequestsConsumption struct {
	Limit int   `json:"limit"`
	Used  int   `json:"used"`
	Reset int64 `json:"reset"`
}

type QuotasUsage added in v0.0.5

type QuotasUsage struct {
	PromptLengthMax int                      `json:"prompt_length_max"`
	RateMinute      QuotaRequestsConsumption `json:"rate_minute"`
	RateDay         QuotaRequestsConsumption `json:"rate_day"`
}

func GetQuotaUsage added in v0.0.5

func GetQuotaUsage(ctx context.Context, clientRepository RepositoryPrediction, user *User) (QuotasUsage, error)

GetQuotaUsage read current usage of the quota.

type RepositoryPrediction

type RepositoryPrediction interface {
	// WriteInputPrompt records user's input prompt.
	WriteInputPrompt(ctx context.Context, requestID, userID, prompt string) error

	// WriteModelResult records the model's prediction result and the associated costs in tokens.
	WriteModelResult(
		ctx context.Context, requestID, userID, predictionRaw, prediction, model string,
		usageTokensPrompt, usageTokensCompletions uint16,
	) error

	// WriteSuccessFlag records the instance of a successful diagram generation
	// based on the model's prediction result.
	WriteSuccessFlag(ctx context.Context, requestID, userID, token string) error

	// GetDailySuccessfulResultsTimestampsByUserID reads the timestamps of all user's successful requests
	// which led to successful diagrams generation over the last 24 hours / day.
	GetDailySuccessfulResultsTimestampsByUserID(ctx context.Context, userID string) ([]time.Time, error)

	// Close closes connection to persistence service.
	Close(ctx context.Context) error
}

RepositoryPrediction defines the interface to store prediction input (prompt) and model result.

type RepositorySecretsVault

type RepositorySecretsVault interface {
	ReadLastVersion(ctx context.Context, uri string, output interface{}) error
}

RepositorySecretsVault defines the interface to read secrets from the vault.

type RepositoryToken added in v0.0.5

type RepositoryToken interface {
	// GetActiveUserIDByActiveTokenID reads userID from the repository given the tokenID.
	// It returns a non-empty value if and only if the token and user are active.
	GetActiveUserIDByActiveTokenID(ctx context.Context, id string) (string, error)
}

RepositoryToken defines the communication port to persistence layer hosting API access tokens.

type User

type User struct {
	ID           string
	APIToken     string
	IsRegistered bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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