types

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ServiceSourceLocal  = "local"
	ServiceSourceRemote = "remote"

	FlavorAOG      = "aog"
	FlavorTencent  = "tencent"
	FlavorDeepSeek = "deepseek"
	FlavorOpenAI   = "openai"
	FlavorOllama   = "ollama"
	FlavorBaidu    = "baidu"
	FlavorAliYun   = "aliyun"
	FlavorOpenvino = "openvino"

	AuthTypeNone   = "none"
	AuthTypeApiKey = "apikey"
	AuthTypeToken  = "token"

	ServiceChat        = "chat"
	ServiceModels      = "models"
	ServiceGenerate    = "generate"
	ServiceEmbed       = "embed"
	ServiceTextToImage = "text-to-image"

	ImageTypeUrl    = "url"
	ImageTypePath   = "path"
	ImageTypeBase64 = "base64"

	HybridPolicyDefault = "default"
	HybridPolicyLocal   = "always_local"
	HybridPolicyRemote  = "always_remote"

	ProtocolHTTP  = "HTTP"
	ProtocolHTTPS = "HTTPS"
	ProtocolGRPC  = "GRPC"

	LogLevelDebug = "debug"
	LogLevelInfo  = "info"
	LogLevelWarn  = "warn"
	LogLevelError = "error"

	EngineStartModeDaemon   = "daemon"
	EngineStartModeStandard = "standard"

	VersionRecordStatusInstalled = 1
	VersionRecordStatusUpdated   = 2
)

Variables

Functions

func IsDropAction

func IsDropAction(err error) bool

Types

type ConversionStepDef

type ConversionStepDef struct {
	Converter string `yaml:"converter"`
	Config    any    `yaml:"config"`
}

ConversionStepDef NOTE: we use YAML instead of JSON here because it's easier to read and write In particular, it supports multiline strings which greatly help write jsonata templates

type DeleteRequest

type DeleteRequest struct {
	Model string `json:"model"`
}

DeleteRequest is the request passed to [Client.Delete].

type DropAction

type DropAction struct{}

func (*DropAction) Error

func (d *DropAction) Error() string

type EngineRecommendConfig

type EngineRecommendConfig struct {
	Host           string `json:"host"`
	Origin         string `json:"origin"`
	Scheme         string `json:"scheme"`
	RecommendModel string `json:"recommend_model"`
	DownloadUrl    string `json:"download_url"`
	DownloadPath   string `json:"download_path"`
	EnginePath     string `json:"engine_path"`
	ExecPath       string `json:"exec_path"`
	ExecFile       string `json:"exec_file"`
}

type EngineVersionResponse

type EngineVersionResponse struct {
	Version string `json:"version"`
}

type EventListener

type EventListener func(string, any)

type EventManager

type EventManager struct {
	SupportedEventTypes []string
	Listensers          []EventListener
}

func (*EventManager) AddListener

func (m *EventManager) AddListener(listener EventListener)

func (*EventManager) GetSupportedEventTypes

func (m *EventManager) GetSupportedEventTypes() []string

func (*EventManager) Notify

func (m *EventManager) Notify(eventType string, data any)

func (*EventManager) NotifyHTTPRequest

func (m *EventManager) NotifyHTTPRequest(etype string, method string, url string, header http.Header, body []byte)

func (*EventManager) NotifyHTTPResponse

func (m *EventManager) NotifyHTTPResponse(etype string, statusCode int, header http.Header, body []byte)

func (*EventManager) RemoveListener

func (m *EventManager) RemoveListener(listener EventListener)

type HTTPContent

type HTTPContent struct {
	Body   []byte
	Header http.Header
}

func (HTTPContent) String

func (hc HTTPContent) String() string

type HTTPErrorResponse

type HTTPErrorResponse struct {
	StatusCode int
	Header     http.Header
	Body       []byte
}

func (*HTTPErrorResponse) Error

func (hc *HTTPErrorResponse) Error() string

type HttpRequestEventData

type HttpRequestEventData struct {
	Method string
	Url    string
	Header http.Header
	Body   []byte
}

type HttpResponseEventData

type HttpResponseEventData struct {
	StatusCode int
	Header     http.Header
	Body       []byte
}

type ListModelResponse

type ListModelResponse struct {
	Name       string       `json:"name"`
	Model      string       `json:"model"`
	ModifiedAt time.Time    `json:"modified_at"`
	Size       int64        `json:"size"`
	Digest     string       `json:"digest"`
	Details    ModelDetails `json:"details,omitempty"`
}

ListModelResponse is a single model description in ListResponse.

type ListResponse

type ListResponse struct {
	Models []ListModelResponse `json:"models"`
}

ListResponse is the response from [Client.List].

type Model

type Model struct {
	ID           int       `gorm:"primaryKey;column:id;autoIncrement" json:"id"`
	ModelName    string    `gorm:"column:model_name;not null" json:"model_name"`
	ProviderName string    `gorm:"column:provider_name" json:"provider_name"`
	Status       string    `gorm:"column:status;not null" json:"status"`
	CreatedAt    time.Time `gorm:"column:created_at;default:CURRENT_TIMESTAMP" json:"created_at"`
	UpdatedAt    time.Time `gorm:"column:updated_at;default:CURRENT_TIMESTAMP" json:"updated_at"`
}

Model table structure

func (*Model) Index

func (t *Model) Index() map[string]interface{}

func (*Model) PrimaryKey

func (t *Model) PrimaryKey() string

func (*Model) SetCreateTime

func (t *Model) SetCreateTime(time time.Time)

func (*Model) SetUpdateTime

func (t *Model) SetUpdateTime(time time.Time)

func (*Model) TableName

func (t *Model) TableName() string

type ModelDetails

type ModelDetails struct {
	ParentModel       string   `json:"parent_model"`
	Format            string   `json:"format"`
	Family            string   `json:"family"`
	Families          []string `json:"families"`
	ParameterSize     string   `json:"parameter_size"`
	QuantizationLevel string   `json:"quantization_level"`
}

ModelDetails provides details about a model.

type ProgressResponse

type ProgressResponse struct {
	Status    string `json:"status"`
	Digest    string `json:"digest,omitempty"`
	Total     int64  `json:"total,omitempty"`
	Completed int64  `json:"completed,omitempty"`
}

PullProgressFunc and [PushProgressFunc].

type PullModelRequest

type PullModelRequest struct {
	Model     string `json:"model"`
	Insecure  bool   `json:"insecure,omitempty"`
	Username  string `json:"username"`
	Password  string `json:"password"`
	Stream    *bool  `json:"stream,omitempty"`
	ModelType string `json:"model_type,omitempty"`

	// Deprecated: set the model name with Model instead
	Name string `json:"name"`
}

PullModelRequest is the request passed to [Client.Pull].

type PullProgressFunc

type PullProgressFunc func(ProgressResponse) error

type RecommendConfig

type RecommendConfig struct {
	ModelEngine       string `json:"model_engine"`
	ModelName         string `json:"model_name"`
	EngineDownloadUrl string `json:"engine_download_url"`
}

type ScheduleDetails

type ScheduleDetails struct {
	Id           uint64
	IsRunning    bool
	ListMark     *list.Element
	TimeEnqueue  time.Time
	TimeRun      time.Time
	TimeComplete time.Time
}

type Service

type Service struct {
	Name           string    `gorm:"primaryKey;column:name" json:"name"`
	HybridPolicy   string    `gorm:"column:hybrid_policy;not null;default:default" json:"hybrid_policy"`
	RemoteProvider string    `gorm:"column:remote_provider;not null;default:''" json:"remote_provider"`
	LocalProvider  string    `gorm:"column:local_provider;not null;default:''" json:"local_provider"`
	Status         int       `gorm:"column:status;not null;default:1" json:"status"`
	CreatedAt      time.Time `gorm:"column:created_at;default:CURRENT_TIMESTAMP" json:"created_at"`
	UpdatedAt      time.Time `gorm:"column:updated_at;default:CURRENT_TIMESTAMP" json:"updated_at"`
}

Service table structure

func (*Service) Index

func (t *Service) Index() map[string]interface{}

func (*Service) PrimaryKey

func (t *Service) PrimaryKey() string

func (*Service) SetCreateTime

func (t *Service) SetCreateTime(time time.Time)

func (*Service) SetUpdateTime

func (t *Service) SetUpdateTime(time time.Time)

func (*Service) TableName

func (t *Service) TableName() string

type ServiceProvider

type ServiceProvider struct {
	ID            int       `gorm:"primaryKey;autoIncrement" json:"id"`
	ProviderName  string    `gorm:"column:provider_name" json:"provider_name"`
	ServiceName   string    `gorm:"column:service_name" json:"service_name"`
	ServiceSource string    `gorm:"column:service_source;default:local" json:"service_source"`
	Desc          string    `gorm:"column:desc" json:"desc"`
	Method        string    `gorm:"column:method" json:"method"`
	URL           string    `gorm:"column:url" json:"url"`
	AuthType      string    `gorm:"column:auth_type" json:"auth_type"`
	AuthKey       string    `gorm:"column:auth_key" json:"auth_key"`
	Flavor        string    `gorm:"column:flavor" json:"flavor"`
	ExtraHeaders  string    `gorm:"column:extra_headers;default:'{}'" json:"extra_headers"`
	ExtraJSONBody string    `gorm:"column:extra_json_body;default:'{}'" json:"extra_json_body"`
	Properties    string    `gorm:"column:properties;default:'{}'" json:"properties"`
	Status        int       `gorm:"column:status;not null;default:0" json:"status"`
	CreatedAt     time.Time `gorm:"column:created_at;default:CURRENT_TIMESTAMP" json:"created_at"`
	UpdatedAt     time.Time `gorm:"column:updated_at;default:CURRENT_TIMESTAMP" json:"updated_at"`
}

ServiceProvider Service provider table structure

func (*ServiceProvider) Index

func (t *ServiceProvider) Index() map[string]interface{}

func (*ServiceProvider) PrimaryKey

func (t *ServiceProvider) PrimaryKey() string

func (*ServiceProvider) SetCreateTime

func (t *ServiceProvider) SetCreateTime(time time.Time)

func (*ServiceProvider) SetUpdateTime

func (t *ServiceProvider) SetUpdateTime(time time.Time)

func (*ServiceProvider) TableName

func (t *ServiceProvider) TableName() string

type ServiceProviderProperties

type ServiceProviderProperties struct {
	MaxInputTokens        int      `json:"max_input_tokens"`
	SupportedResponseMode []string `json:"supported_response_mode"`
	ModeIsChangeable      bool     `json:"mode_is_changeable"`
	Models                []string `json:"models"`
	XPU                   []string `json:"xpu"`
}

type ServiceRequest

type ServiceRequest struct {
	AskStreamMode         bool          `json:"stream"`
	Model                 string        `json:"model"`
	HybridPolicy          string        `json:"hybrid_policy"`
	RemoteServiceProvider string        `json:"remote_service_provider"`
	FromFlavor            string        `json:"-"`
	Service               string        `json:"-"`
	Priority              int           `json:"-"`
	RequestSegments       int           `json:"request_segments"`
	RequestExtraUrl       string        `json:"extra_url"`
	HTTP                  HTTPContent   `json:"-"`
	OriginalRequest       *http.Request `json:"-"`
}

ServiceRequest The body of the OriginalRequest has been read out so need to placed here

func (*ServiceRequest) String

func (sr *ServiceRequest) String() string

type ServiceResult

type ServiceResult struct {
	Type       ServiceResultType
	TaskId     uint64
	Error      error
	StatusCode int
	HTTP       HTTPContent
}

func (*ServiceResult) String

func (sr *ServiceResult) String() string

func (*ServiceResult) WriteBack

func (sr *ServiceResult) WriteBack(w http.ResponseWriter)

type ServiceResultType

type ServiceResultType int
const (
	ServiceResultDone ServiceResultType = iota
	ServiceResultFailed
	ServiceResultChunk
)

type ServiceTarget

type ServiceTarget struct {
	Location        string
	Stream          bool
	Model           string
	ToFavor         string
	XPU             string
	ServiceProvider *ServiceProvider
}

func (*ServiceTarget) String

func (sr *ServiceTarget) String() string

type StreamMode

type StreamMode struct {
	Mode   StreamModeType
	Header http.Header
}

func (*StreamMode) IsStream

func (sm *StreamMode) IsStream() bool

func (*StreamMode) ReadChunk

func (sm *StreamMode) ReadChunk(reader *bufio.Reader) ([]byte, error)

ReadChunk the chunks of the stream is delimited by "\n\n" for event-stream, and "\n" or "\r\n" for x=ndjson so only need to read to '\n'. However, reader can only stop at one character, so we need to handle it by ourselves for "\n\n" case

func (*StreamMode) UnwrapChunk

func (sm *StreamMode) UnwrapChunk(chunk []byte) []byte

UnwrapChunk Get real data event-stream is started with "data: " which need to be removed TODO: event-stream may contain multiple fields, and we only need to pick the data: fields. Need to handle it in the future. Currently we assume there is only a data: field.

func (*StreamMode) WrapChunk

func (sm *StreamMode) WrapChunk(chunk []byte) []byte

type StreamModeType

type StreamModeType int
const (
	StreamModeNonStream StreamModeType = iota
	StreamModeEventStream
	StreamModeNDJson
)

func (StreamModeType) String

func (st StreamModeType) String() string

type VersionUpdateRecord

type VersionUpdateRecord struct {
	ID           int       `gorm:"primaryKey;column:id;autoIncrement" json:"id"`
	Version      string    `gorm:"column:version;not null" json:"version"`
	ReleaseNotes string    `gorm:"column:release_notes;not null" json:"release_notes"`
	Status       int       `gorm:"column:status;not null" json:"status"`
	CreatedAt    time.Time `gorm:"column:created_at;default:CURRENT_TIMESTAMP" json:"created_at"`
	UpdatedAt    time.Time `gorm:"column:updated_at;default:CURRENT_TIMESTAMP" json:"updated_at"`
}

VersionUpdateRecord table structure

func (*VersionUpdateRecord) Index

func (t *VersionUpdateRecord) Index() map[string]interface{}

func (*VersionUpdateRecord) PrimaryKey

func (t *VersionUpdateRecord) PrimaryKey() string

func (*VersionUpdateRecord) SetCreateTime

func (t *VersionUpdateRecord) SetCreateTime(time time.Time)

func (*VersionUpdateRecord) SetUpdateTime

func (t *VersionUpdateRecord) SetUpdateTime(time time.Time)

func (*VersionUpdateRecord) TableName

func (t *VersionUpdateRecord) TableName() string

Jump to

Keyboard shortcuts

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