lib

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuditLogs

func AuditLogs(message string, logType string, apiKeyID uuid.UUID, messageType string, productID uuid.UUID, r *http.Request) *models.AuditLogs

func AuthOpenShieldMiddleware

func AuthOpenShieldMiddleware(next http.HandlerFunc) http.HandlerFunc

func DB

func DB() *gorm.DB

func ErrorResponse

func ErrorResponse(w http.ResponseWriter, err error)

func GetCache

func GetCache(key string) ([]byte, bool, error)

func GetContextCache added in v0.3.1

func GetContextCache(prompt string, productID string) (string, error)

func GetModel

func GetModel(model string) (models.AiModels, error)

func HashKey added in v0.3.1

func HashKey(key string) string

func InitRedisClient

func InitRedisClient(config *Configuration)

func KeyByRealIP

func KeyByRealIP(r *http.Request) (string, error)

func LogUsage added in v0.3.1

func LogUsage(modelName string, predictedTokensCount int, promptTokensCount int, completionTokens int, totalTokens int, finishReason string, requestType string, productID uuid.UUID, auditLogID uuid.UUID)

func SetCache

func SetCache(key string, value interface{}) error

func SetConfig

func SetConfig(config Configuration)

func SetContextCache added in v0.3.1

func SetContextCache(prompt, answer, productID string) error

func SetDB

func SetDB(customDB *gorm.DB)

func TokenizerHandler

func TokenizerHandler(c *fiber.Ctx) error

Types

type Action

type Action struct {
	Type ActionType `mapstructure:"type"`
}

Action defines what actions are associated with filters

type ActionType

type ActionType string

ActionType defines the type of action to take

type CacheConfig

type CacheConfig struct {
	Enabled bool   `mapstructure:"enabled,default=false"`
	TTL     int    `mapstructure:"ttl,default=60"`
	Prefix  string `mapstructure:"prefix,default=openshield"`
}

CacheConfig holds configuration for cache settings

type Config

type Config struct {
	PluginName string      `mapstructure:"plugin_name"`
	Relation   string      `mapstructure:"relation,default=>"`
	Threshold  float64     `mapstructure:"threshold,omitempty,default=0.5"`
	Url        string      `mapstructure:"url,omitempty"`
	ApiKey     string      `mapstructure:"api_key,omitempty"`
	PIIService interface{} `mapstructure:"piiservice,omitempty"`
}

Config holds the configuration specifics of a filter

type Configuration

type Configuration struct {
	Settings  Setting   `mapstructure:"settings"`
	Rules     Rules     `mapstructure:"rules"`
	Secrets   Secrets   `mapstructure:"secrets"`
	Providers Providers `mapstructure:"providers"`
}

Configuration Represents the entire YAML configuration

var AppConfig Configuration

AppConfig ActionType constants

func GetConfig

func GetConfig() Configuration

type ContextCache added in v0.3.1

type ContextCache struct {
	Enabled bool   `mapstructure:"enabled,default=false"`
	URL     string `mapstructure:"url,default=http://localhost:8001"`
}

ContextCache holds configuration for the context cache

type Database

type Database struct {
	URL           string
	AutoMigration bool
}

type DatabaseConfig

type DatabaseConfig struct {
	URI           string `mapstructure:"uri"`
	AutoMigration bool   `mapstructure:"auto_migration,default=false"`
}

DatabaseConfig holds configuration for the database

type FeatureToggle

type FeatureToggle struct {
	Enabled bool `mapstructure:"enabled,default=false"`
}

FeatureToggle is used to enable or disable features

type Log

type Log struct {
	DisableColor bool
	AuditLog     bool
	Usage        bool
}

type Network

type Network struct {
	Port int `mapstructure:"port,default=8080"`
}

Network holds configuration for network settings

type OpenAIRoutes

type OpenAIRoutes struct {
	Models          Route
	Model           Route
	ChatCompletions Route
}

type Option

type Option = httprate.Option

func WithKeyByRealIP

func WithKeyByRealIP() Option

type ProviderAnthropic added in v0.3.1

type ProviderAnthropic struct {
	Enabled bool   `mapstructure:"enabled"`
	BaseUrl string `mapstructure:"url"`
}

type ProviderHuggingFace added in v0.3.1

type ProviderHuggingFace struct {
	Enabled bool   `mapstructure:"enabled"`
	BaseUrl string `mapstructure:"url"`
}

type ProviderNvidia added in v0.3.1

type ProviderNvidia struct {
	Enabled bool   `mapstructure:"enabled"`
	BaseUrl string `mapstructure:"url"`
}

type ProviderOpenAI

type ProviderOpenAI struct {
	Enabled bool   `mapstructure:"enabled"`
	BaseUrl string `mapstructure:"url"`
}

type Providers

type Providers struct {
	OpenAI      *ProviderOpenAI      `mapstructure:"openai"`
	Anthropic   *ProviderAnthropic   `mapstructure:"anthropic"`
	Nvidia      *ProviderNvidia      `mapstructure:"nvidia"`
	HuggingFace *ProviderHuggingFace `mapstructure:"huggingface"`
}

type RateLimiting

type RateLimiting struct {
	*FeatureToggle
	Window int `mapstructure:"window"`
	Max    int `mapstructure:"max"`
}

RateLimiting holds configuration for rate limiting settings

type Redis

type Redis struct {
	Options *redis.Options
}

type RedisConfig

type RedisConfig struct {
	URI string `mapstructure:"uri"`
	SSL bool   `mapstructure:"ssl,default=false"`
}

RedisConfig holds configuration for the redis cache

type RedisSettings

type RedisSettings struct {
	URI string
	SSL bool
}

type Route

type Route struct {
	RateLimit RateLimiting
}

type RouteSettings

type RouteSettings struct {
	RateLimit *RateLimiting
	Redis     Redis
}

func GetRouteSettings

func GetRouteSettings() (RouteSettings, error)

type Routes

type Routes struct {
	OpenAI    OpenAIRoutes
	Tokenizer Route
	Storage   *redis.Client
}

type Rule

type Rule struct {
	Enabled     bool   `mapstructure:"enabled,default=false"`
	Name        string `mapstructure:"name"`
	Type        string `mapstructure:"type"`
	Config      Config `mapstructure:"config"`
	Action      Action `mapstructure:"action"`
	OrderNumber int    `mapstructure:"order_number"`
}

Rule defines a rule configuration

type RuleServer

type RuleServer struct {
	Url string `mapstructure:"url,default=http://localhost:8000"`
}

RuleServer holds configuration for the rule server

type Rules

type Rules struct {
	Input  []Rule `mapstructure:"input,default=[]"`
	Output []Rule `mapstructure:"output,default=[]"`
}

Rules section contains input and output rule configurations

type Secrets

type Secrets struct {
	OpenAIApiKey      string `mapstructure:"openai_api_key"`
	HuggingFaceApiKey string `mapstructure:"huggingface_api_key"`
	AnthropicApiKey   string `mapstructure:"anthropic_api_key"`
	NvidiaApiKey      string `mapstructure:"nvidia_api_key"`
}

Secrets section contains all the secrets

type Setting

type Setting struct {
	Redis               *RedisConfig    `mapstructure:"redis"`
	Database            *DatabaseConfig `mapstructure:"database"`
	Cache               *CacheConfig    `mapstructure:"cache"`
	ContextCache        *ContextCache   `mapstructure:"context_cache"`
	AuditLogging        *FeatureToggle  `mapstructure:"audit_logging,default=false"`
	UsageLogging        *FeatureToggle  `mapstructure:"usage_logging,default=false"`
	Network             *Network        `mapstructure:"network"`
	RateLimit           *RateLimiting   `mapstructure:"rate_limiting"`
	RuleServer          *RuleServer     `mapstructure:"rule_server"`
	EnglishDetectionURL string          `mapstructure:"english_detection_url"`
}

Setting can include various configurations like database, cache, and different logging types

type Settings

type Settings struct {
	Log        Log
	OpenAI     openai
	OpenShield openShield
	Routes     Routes
	Database   Database
	Redis      RedisSettings
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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