Documentation
¶
Index ¶
- Constants
- Variables
- func IsDropAction(err error) bool
- type ConversionStepDef
- type DeleteRequest
- type DropAction
- type EngineRecommendConfig
- type EngineVersionResponse
- type EventListener
- type EventManager
- func (m *EventManager) AddListener(listener EventListener)
- func (m *EventManager) GetSupportedEventTypes() []string
- func (m *EventManager) Notify(eventType string, data any)
- func (m *EventManager) NotifyHTTPRequest(etype string, method string, url string, header http.Header, body []byte)
- func (m *EventManager) NotifyHTTPResponse(etype string, statusCode int, header http.Header, body []byte)
- func (m *EventManager) RemoveListener(listener EventListener)
- type HTTPContent
- type HTTPErrorResponse
- type HttpRequestEventData
- type HttpResponseEventData
- type ListModelResponse
- type ListResponse
- type Model
- type ModelDetails
- type ProgressResponse
- type PullModelRequest
- type PullProgressFunc
- type RecommendConfig
- type ScheduleDetails
- type Service
- type ServiceProvider
- type ServiceProviderProperties
- type ServiceRequest
- type ServiceResult
- type ServiceResultType
- type ServiceTarget
- type StreamMode
- type StreamModeType
- type VersionUpdateRecord
Constants ¶
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 ¶
var ( SupportService = []string{ServiceEmbed, ServiceModels, ServiceChat, ServiceGenerate, ServiceTextToImage} SupportHybridPolicy = []string{HybridPolicyDefault, HybridPolicyLocal, HybridPolicyRemote} SupportAuthType = []string{AuthTypeNone, AuthTypeApiKey, AuthTypeToken} SupportFlavor = []string{FlavorDeepSeek, FlavorOpenAI, FlavorTencent, FlavorOllama, FlavorBaidu, FlavorAliYun, FlavorOpenvino} SupportModelEngine = []string{FlavorOpenvino, FlavorOllama} SupportImageType = []string{ImageTypeUrl, ImageTypeBase64, ImageTypePath} )
Functions ¶
func IsDropAction ¶
Types ¶
type ConversionStepDef ¶
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 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 (*EventManager) NotifyHTTPResponse ¶
func (*EventManager) RemoveListener ¶
func (m *EventManager) RemoveListener(listener EventListener)
type HTTPContent ¶
func (HTTPContent) String ¶
func (hc HTTPContent) String() string
type HTTPErrorResponse ¶
func (*HTTPErrorResponse) Error ¶
func (hc *HTTPErrorResponse) Error() string
type HttpRequestEventData ¶
type HttpResponseEventData ¶
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) PrimaryKey ¶
func (*Model) SetCreateTime ¶
func (*Model) SetUpdateTime ¶
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 ScheduleDetails ¶
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) PrimaryKey ¶
func (*Service) SetCreateTime ¶
func (*Service) SetUpdateTime ¶
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 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