api

package
v1.15.0 Latest Latest
Warning

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

Go to latest
Published: May 23, 2023 License: MIT Imports: 38 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func App added in v1.3.0

func App(opts ...AppOption) *fiber.App

func Finetune added in v1.5.0

func Finetune(config Config, input, prediction string) string

func ImageGeneration added in v1.12.0

func ImageGeneration(height, width, mode, step, seed int, positive_prompt, negative_prompt, dst string, loader *model.ModelLoader, c Config) (func() error, error)

func ModelEmbedding added in v1.7.0

func ModelEmbedding(s string, tokens []int, loader *model.ModelLoader, c Config) (func() ([]float32, error), error)

func ModelInference added in v1.4.0

func ModelInference(s string, loader *model.ModelLoader, c Config, tokenCallback func(string) bool) (func() (string, error), error)

Types

type APIError added in v1.3.2

type APIError struct {
	Code    any     `json:"code,omitempty"`
	Message string  `json:"message"`
	Param   *string `json:"param,omitempty"`
	Type    string  `json:"type"`
}

APIError provides error information returned by the OpenAI API.

type AppOption added in v1.14.1

type AppOption func(*Option)

func WithConfigFile added in v1.14.1

func WithConfigFile(configFile string) AppOption

func WithContext added in v1.14.1

func WithContext(ctx context.Context) AppOption

func WithContextSize added in v1.14.1

func WithContextSize(ctxSize int) AppOption

func WithCors added in v1.14.1

func WithCors(b bool) AppOption

func WithCorsAllowOrigins added in v1.14.1

func WithCorsAllowOrigins(b string) AppOption

func WithDebug added in v1.14.1

func WithDebug(debug bool) AppOption

func WithDisableMessage added in v1.14.1

func WithDisableMessage(disableMessage bool) AppOption

func WithF16 added in v1.14.1

func WithF16(f16 bool) AppOption

func WithImageDir added in v1.14.1

func WithImageDir(imageDir string) AppOption

func WithModelLoader added in v1.14.1

func WithModelLoader(loader *model.ModelLoader) AppOption

func WithThreads added in v1.14.1

func WithThreads(threads int) AppOption

func WithUploadLimitMB added in v1.14.1

func WithUploadLimitMB(limit int) AppOption

type ApplyGalleryModelRequest added in v1.13.0

type ApplyGalleryModelRequest struct {
	URL             string                 `json:"url"`
	Name            string                 `json:"name"`
	Overrides       map[string]interface{} `json:"overrides"`
	AdditionalFiles []gallery.File         `json:"files"`
}

func (ApplyGalleryModelRequest) DecodeURL added in v1.14.0

func (request ApplyGalleryModelRequest) DecodeURL() (string, error)

type Choice

type Choice struct {
	Index        int      `json:"index,omitempty"`
	FinishReason string   `json:"finish_reason,omitempty"`
	Message      *Message `json:"message,omitempty"`
	Delta        *Message `json:"delta,omitempty"`
	Text         string   `json:"text,omitempty"`
}

func ComputeChoices added in v1.5.0

func ComputeChoices(predInput string, input *OpenAIRequest, config *Config, loader *model.ModelLoader, cb func(string, *[]Choice), tokenCallback func(string) bool) ([]Choice, error)

type Config added in v1.4.0

type Config struct {
	OpenAIRequest               `yaml:"parameters"`
	Name                        string            `yaml:"name"`
	StopWords                   []string          `yaml:"stopwords"`
	Cutstrings                  []string          `yaml:"cutstrings"`
	TrimSpace                   []string          `yaml:"trimspace"`
	ContextSize                 int               `yaml:"context_size"`
	F16                         bool              `yaml:"f16"`
	Threads                     int               `yaml:"threads"`
	Debug                       bool              `yaml:"debug"`
	Roles                       map[string]string `yaml:"roles"`
	Embeddings                  bool              `yaml:"embeddings"`
	Backend                     string            `yaml:"backend"`
	TemplateConfig              TemplateConfig    `yaml:"template"`
	MirostatETA                 float64           `yaml:"mirostat_eta"`
	MirostatTAU                 float64           `yaml:"mirostat_tau"`
	Mirostat                    int               `yaml:"mirostat"`
	NGPULayers                  int               `yaml:"gpu_layers"`
	ImageGenerationAssets       string            `yaml:"asset_dir"`
	PromptStrings, InputStrings []string
	InputToken                  [][]int
}

func ReadConfig added in v1.4.0

func ReadConfig(file string) (*Config, error)

func ReadConfigFile added in v1.4.0

func ReadConfigFile(file string) ([]*Config, error)

type ConfigMerger added in v1.4.0

type ConfigMerger struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewConfigMerger added in v1.13.0

func NewConfigMerger() *ConfigMerger

func (ConfigMerger) GetConfig added in v1.13.0

func (cm ConfigMerger) GetConfig(m string) (Config, bool)

func (ConfigMerger) ListConfigs added in v1.13.0

func (cm ConfigMerger) ListConfigs() []string

func (ConfigMerger) LoadConfig added in v1.4.0

func (cm ConfigMerger) LoadConfig(file string) error

func (ConfigMerger) LoadConfigFile added in v1.4.0

func (cm ConfigMerger) LoadConfigFile(file string) error

func (ConfigMerger) LoadConfigs added in v1.4.0

func (cm ConfigMerger) LoadConfigs(path string) error

type ErrorResponse added in v1.3.2

type ErrorResponse struct {
	Error *APIError `json:"error,omitempty"`
}

type Item added in v1.7.0

type Item struct {
	Embedding []float32 `json:"embedding"`
	Index     int       `json:"index"`
	Object    string    `json:"object,omitempty"`

	// Images
	URL     string `json:"url,omitempty"`
	B64JSON string `json:"b64_json,omitempty"`
}

type Message

type Message struct {
	Role    string `json:"role,omitempty" yaml:"role"`
	Content string `json:"content,omitempty" yaml:"content"`
}

type OpenAIModel

type OpenAIModel struct {
	ID     string `json:"id"`
	Object string `json:"object"`
}

type OpenAIRequest

type OpenAIRequest struct {
	Model string `json:"model" yaml:"model"`

	// whisper
	File     string `json:"file" validate:"required"`
	Language string `json:"language"`
	//whisper/image
	ResponseFormat string `json:"response_format"`
	// image
	Size string `json:"size"`
	// Prompt is read only by completion/image API calls
	Prompt interface{} `json:"prompt" yaml:"prompt"`

	// Edit endpoint
	Instruction string      `json:"instruction" yaml:"instruction"`
	Input       interface{} `json:"input" yaml:"input"`

	Stop interface{} `json:"stop" yaml:"stop"`

	// Messages is read only by chat/completion API calls
	Messages []Message `json:"messages" yaml:"messages"`

	Stream bool `json:"stream"`
	Echo   bool `json:"echo"`
	// Common options between all the API calls
	TopP        float64 `json:"top_p" yaml:"top_p"`
	TopK        int     `json:"top_k" yaml:"top_k"`
	Temperature float64 `json:"temperature" yaml:"temperature"`
	Maxtokens   int     `json:"max_tokens" yaml:"max_tokens"`

	N int `json:"n"`

	// Custom parameters - not present in the OpenAI API
	Batch         int     `json:"batch" yaml:"batch"`
	F16           bool    `json:"f16" yaml:"f16"`
	IgnoreEOS     bool    `json:"ignore_eos" yaml:"ignore_eos"`
	RepeatPenalty float64 `json:"repeat_penalty" yaml:"repeat_penalty"`
	Keep          int     `json:"n_keep" yaml:"n_keep"`

	MirostatETA float64 `json:"mirostat_eta" yaml:"mirostat_eta"`
	MirostatTAU float64 `json:"mirostat_tau" yaml:"mirostat_tau"`
	Mirostat    int     `json:"mirostat" yaml:"mirostat"`

	Seed int `json:"seed" yaml:"seed"`

	// Image (not supported by OpenAI)
	Mode int `json:"mode"`
	Step int `json:"step"`
}

type OpenAIResponse

type OpenAIResponse struct {
	Created int      `json:"created,omitempty"`
	Object  string   `json:"object,omitempty"`
	ID      string   `json:"id,omitempty"`
	Model   string   `json:"model,omitempty"`
	Choices []Choice `json:"choices,omitempty"`
	Data    []Item   `json:"data,omitempty"`

	Usage OpenAIUsage `json:"usage"`
}

type OpenAIUsage added in v1.6.1

type OpenAIUsage struct {
	PromptTokens     int `json:"prompt_tokens"`
	CompletionTokens int `json:"completion_tokens"`
	TotalTokens      int `json:"total_tokens"`
}

type Option added in v1.14.1

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

type TemplateConfig added in v1.4.0

type TemplateConfig struct {
	Completion string `yaml:"completion"`
	Chat       string `yaml:"chat"`
	Edit       string `yaml:"edit"`
}

Jump to

Keyboard shortcuts

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