api

package
v1.11.1 Latest Latest
Warning

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

Go to latest
Published: May 14, 2023 License: MIT Imports: 31 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(configFile string, loader *model.ModelLoader, uploadLimitMB, threads, ctxSize int, f16 bool, debug, disableMessage bool) *fiber.App

func Finetune added in v1.5.0

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

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 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"`

	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 map[string]Config

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"`
}

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"`
	ResponseFormat string `json:"response_format"`
	Language       string `json:"language"`

	// Prompt is read only by completion 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"`
}

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 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