types

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Database table names
	TableService            = "aog_service"
	TableServiceProvider    = "aog_service_provider"
	TableModel              = "aog_model"
	TableVersionUpdate      = "aog_version_update_record"
	TableDataMigrateVersion = "aog_data_migration_version"
	// RAG tables
	TableRagFile   = "aog_rag_file"
	TableRagChunk  = "aog_rag_chunk"
	TableRagVector = "aog_rag_vector"
)
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"
	AuthTypeSign   = "sign"

	ServiceChat           = "chat"
	ServiceModels         = "models"
	ServiceGenerate       = "generate"
	ServiceEmbed          = "embed"
	ServiceRerank         = "rerank"
	ServiceTextToImage    = "text-to-image"
	ServiceTextToSpeech   = "text-to-speech"
	ServiceSpeechToText   = "speech-to-text"
	ServiceTextToVideo    = "text-to-video"
	ServiceImageToVideo   = "image-to-video"
	ServiceImageToImage   = "image-to-image"
	ServiceSpeechToTextWS = "speech-to-text-ws"

	ServiceChatAvatar           = constants.BaseDownloadURL + constants.URLDirPathIcon + "/chat.svg"
	ServiceTextToImageAvatar    = constants.BaseDownloadURL + constants.URLDirPathIcon + "/text-to-image.svg"
	ServiceEmbedAvatar          = constants.BaseDownloadURL + constants.URLDirPathIcon + "/Embed.svg"
	ServiceGenerateAvatar       = constants.BaseDownloadURL + constants.URLDirPathIcon + "/Generate.svg"
	ServiceRerankAvatar         = constants.BaseDownloadURL + constants.URLDirPathIcon + "/Rerank.svg"
	ServiceSpeechToTextAvatar   = constants.BaseDownloadURL + constants.URLDirPathIcon + "/Speech-to-text.svg"
	ServiceTextToSpeechAvatar   = constants.BaseDownloadURL + constants.URLDirPathIcon + "/Text-to-speech.svg"
	ServiceImageToVideoAvatar   = constants.BaseDownloadURL + constants.URLDirPathIcon + "/Image-to-video.svg"
	ServiceImageToImageAvatar   = constants.BaseDownloadURL + constants.URLDirPathIcon + "/Image-to-image.svg"
	ServiceSpeechToTextWSAvatar = constants.BaseDownloadURL + constants.URLDirPathIcon + "/Speech-to-text-ws.svg"

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

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

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

	ExposeProtocolHTTP      = "HTTP"
	ExposeProtocolWEBSOCKET = "WEBSOCKET"

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

	EngineStartModeDaemon   = "daemon"
	EngineStartModeStandard = "standard"

	VersionRecordStatusInstalled = 1
	VersionRecordStatusUpdated   = 2

	WSTaskTypeAudio = "audio"

	AudioWav  = "wav"
	AudioMp3  = "mp3"
	AudioM4a  = "m4a"
	AudioOgg  = "ogg"
	AudioFlac = "flac"
	AudioAac  = "aac"
	AudioMp4  = "mp4"

	VoiceMale   = "male"
	VoiceFemale = "female"
	VoiceGirl   = "girl"
	VoiceBaby   = "baby"

	GPUTypeNvidia    = "Nvidia"
	GPUTypeAmd       = "AMD"
	GPUTypeIntelArc  = "Intel Arc"
	GPUTypeIntelCore = "Intel Core"
	GPUTypeNone      = "None"

	LanguageZh = "zh"
	LanguageEn = "en"

	RagServiceFileTypeTXT  = ".txt"
	RagServiceFileTypeMD   = ".md"
	RagServiceFileTypePDF  = ".pdf"
	RagServiceFileTypeHTML = ".html"
	RagServiceFileTypeDOCX = ".docx"
	RagServiceFileTypeXLSX = ".xlsx"

	RagServiceFileSize = 10 * 1024 * 1024
)
View Source
const (
	// Client Action types
	WSActionRunTask    = "run-task"
	WSActionFinishTask = "finish-task"

	WSSTTTaskTypeUnknown    = "unknown"
	WSSTTTaskTypeRunTask    = WSActionRunTask    // Start recognition task
	WSSTTTaskTypeAudio      = "audio"            // Audio data
	WSSTTTaskTypeFinishTask = WSActionFinishTask // End recognition task

	// Server Event types
	WSEventTaskStarted        = "task-started"
	WSEventTaskFinished       = "task-finished"
	WSEventResultGenerated    = "result-generated"
	WSEventTaskFailed         = "task-failed"
	WSEventTaskResultGenerate = "result-generated"

	// Error codes
	WSErrorCodeClientError = "CLIENT_ERROR"
	WSErrorCodeServerError = "SERVER_ERROR"
	WSErrorCodeModelError  = "MODEL_ERROR"
)

WebSocket message constants

View Source
const (
	TimeFormat = "2006-01-02 15:04:05"
)

Variables

View Source
var (
	SupportService           = []string{ServiceEmbed, ServiceModels, ServiceChat, ServiceGenerate, ServiceRerank, ServiceTextToImage, ServiceSpeechToText, ServiceSpeechToTextWS, ServiceTextToSpeech, ServiceImageToVideo, ServiceImageToImage}
	SupportHybridPolicy      = []string{HybridPolicyDefault, HybridPolicyLocal, HybridPolicyRemote}
	SupportAuthType          = []string{AuthTypeNone, AuthTypeApiKey, AuthTypeSign, AuthTypeToken}
	SupportFlavor            = []string{FlavorDeepSeek, FlavorOpenAI, FlavorTencent, FlavorOllama, FlavorBaidu, FlavorAliYun, FlavorOpenvino}
	SupportModelEngine       = []string{FlavorOpenvino, FlavorOllama}
	SupportImageType         = []string{ImageTypeUrl, ImageTypeBase64, ImageTypePath}
	SupportAudioType         = []string{AudioWav, AudioMp3}
	SupportVoiceType         = []string{VoiceMale, VoiceFemale, VoiceGirl, VoiceBaby}
	SupportOnlyRemoteService = []string{ServiceImageToVideo, ServiceImageToImage}
	SupportServiceAvatar     = map[string]string{
		ServiceChat:           ServiceChatAvatar,
		ServiceEmbed:          ServiceEmbedAvatar,
		ServiceGenerate:       ServiceGenerateAvatar,
		ServiceRerank:         ServiceRerankAvatar,
		ServiceTextToImage:    ServiceTextToImageAvatar,
		ServiceTextToSpeech:   ServiceTextToSpeechAvatar,
		ServiceSpeechToText:   ServiceSpeechToTextAvatar,
		ServiceSpeechToTextWS: ServiceSpeechToTextWSAvatar,
		ServiceImageToVideo:   ServiceImageToVideoAvatar,
		ServiceImageToImage:   ServiceImageToImageAvatar,
	}
	SupportRagServiceFileType = []string{RagServiceFileTypeTXT, RagServiceFileTypeMD, RagServiceFileTypePDF, RagServiceFileTypeHTML, RagServiceFileTypeDOCX, RagServiceFileTypeXLSX}
)
View Source
var (
	WSRemoteLocalMap = make(map[string]*websocket.Conn)
)

Functions

func GetWSRemoteConnection

func GetWSRemoteConnection(connID string) (*websocket.Conn, bool)

GetWSRemoteConnection 线程安全地获取WebSocket连接

func IsDropAction

func IsDropAction(err error) bool

func RemoveWSRemoteConnection

func RemoveWSRemoteConnection(connID string)

RemoveWSRemoteConnection 线程安全地移除WebSocket连接

func SetWSRemoteConnection

func SetWSRemoteConnection(connID string, conn *websocket.Conn)

SetWSRemoteConnection 线程安全地设置WebSocket连接

Types

type ConversionStepDef

type ConversionStepDef struct {
	Converter string `yaml:"converter" json:"converter"`
	Config    any    `yaml:"config" json:"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 DataMigrateVersion

type DataMigrateVersion struct {
	ID        int       `gorm:"primaryKey;column:id;autoIncrement" json:"id"`
	Version   string    `gorm:"column:version;not null" json:"version"`
	CreatedAt LocalTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP" json:"created_at"`
	UpdatedAt LocalTime `gorm:"column:updated_at;default:CURRENT_TIMESTAMP" json:"updated_at"`
}

VersionUpdateRecord table structure

func (*DataMigrateVersion) Index

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

func (*DataMigrateVersion) PrimaryKey

func (t *DataMigrateVersion) PrimaryKey() string

func (*DataMigrateVersion) SetCreateTime

func (t *DataMigrateVersion) SetCreateTime(tm time.Time)

func (*DataMigrateVersion) SetUpdateTime

func (t *DataMigrateVersion) SetUpdateTime(tm time.Time)

func (*DataMigrateVersion) TableName

func (t *DataMigrateVersion) TableName() string

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"`
	DeviceType     string `json:"device_type"`
}

type EngineVersionResponse

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

type FlavorConversionDef added in v0.7.0

type FlavorConversionDef struct {
	Prologue   []string            `yaml:"prologue,omitempty" json:"prologue,omitempty"`
	Epilogue   []string            `yaml:"epilogue,omitempty" json:"epilogue,omitempty"`
	Conversion []ConversionStepDef `yaml:"conversion,omitempty" json:"conversion,omitempty"`
}

FlavorConversionDef defines conversion rules for protocol transformation

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

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

type LocalTime added in v0.7.0

type LocalTime time.Time

LocalTime is a custom time type with fixed format "2006-01-02 15:04:05" in CST (UTC+8)

func Now added in v0.7.0

func Now() LocalTime

func (LocalTime) After added in v0.7.0

func (t LocalTime) After(u LocalTime) bool

func (LocalTime) Before added in v0.7.0

func (t LocalTime) Before(u LocalTime) bool

func (LocalTime) Format added in v0.7.0

func (t LocalTime) Format(layout string) string

Format formats the LocalTime using the given layout

func (LocalTime) IsZero added in v0.7.0

func (t LocalTime) IsZero() bool

func (LocalTime) MarshalJSON added in v0.7.0

func (t LocalTime) MarshalJSON() ([]byte, error)

func (*LocalTime) Scan added in v0.7.0

func (t *LocalTime) Scan(v interface{}) error

func (LocalTime) ToTime added in v0.7.0

func (t LocalTime) ToTime() time.Time

func (*LocalTime) UnmarshalJSON added in v0.7.0

func (t *LocalTime) UnmarshalJSON(data []byte) error

func (LocalTime) Value added in v0.7.0

func (t LocalTime) Value() (driver.Value, error)

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"`
	ServiceName   string    `gorm:"column:service_name" json:"service_name"`
	ServiceSource string    `gorm:"column:service_source" json:"service_source"`
	IsDefault     bool      `gorm:"column:is_default" json:"is_default"`
	CreatedAt     LocalTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP" json:"created_at"`
	UpdatedAt     LocalTime `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(tm time.Time)

func (*Model) SetUpdateTime

func (t *Model) SetUpdateTime(tm 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 OllamaLoadModelRequest

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

type OllamaUnloadModelRequest

type OllamaUnloadModelRequest struct {
	Model     string `json:"model"`
	KeepAlive int64  `json:"keep_alive"`
}

type PathDiskSizeInfo

type PathDiskSizeInfo struct {
	FreeSize  int `json:"free_size"`
	TotalSize int `json:"total_size"`
	UsageSize int `json:"usage_size"`
}

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

PullProgressFunc is a function that [Client.Pull] invokes every time there is progress with a "pull" request sent to the service. If this function returns an error, [Client.Pull] will stop the process and return this error.

type RagChunk added in v0.6.0

type RagChunk struct {
	ID         string                `json:"id"`
	FileID     string                `json:"file_id"`
	Content    string                `json:"content"`
	ChunkIndex int                   `json:"index"`
	Embedding  datastore.Float32List `json:"embedding"`
	CreatedAt  LocalTime             `json:"created_at"`
	UpdatedAt  LocalTime             `json:"updated_at"`
}

RagChunk represents a text chunk of a RagFile

func (*RagChunk) Index added in v0.6.0

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

func (*RagChunk) PrimaryKey added in v0.6.0

func (t *RagChunk) PrimaryKey() string

func (*RagChunk) SetCreateTime added in v0.6.0

func (t *RagChunk) SetCreateTime(tm time.Time)

func (*RagChunk) SetUpdateTime added in v0.6.0

func (t *RagChunk) SetUpdateTime(tm time.Time)

func (*RagChunk) TableName added in v0.6.0

func (t *RagChunk) TableName() string

type RagFile added in v0.6.0

type RagFile struct {
	ID         int       `gorm:"primaryKey;column:id;autoIncrement" json:"id"`
	FileName   string    `gorm:"column:file_name" json:"file_name"`
	FileID     string    `gorm:"column:file_id" json:"file_id"`
	FileType   string    `gorm:"column:file_type" json:"file_type"`
	FilePath   string    `gorm:"column:file_path" json:"file_path"`
	Status     int       `gorm:"column:status" json:"status"` // 1-processing | 2-done | 3-failed
	EmbedModel string    `gorm:"column:embed_model" json:"embed_model"`
	CreatedAt  LocalTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP" json:"created_at"`
	UpdatedAt  LocalTime `gorm:"column:updated_at;default:CURRENT_TIMESTAMP" json:"updated_at"`
}

RagFile represents an uploaded document for RAG

func (*RagFile) Index added in v0.6.0

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

func (*RagFile) PrimaryKey added in v0.6.0

func (t *RagFile) PrimaryKey() string

func (*RagFile) SetCreateTime added in v0.6.0

func (t *RagFile) SetCreateTime(tm time.Time)

func (*RagFile) SetUpdateTime added in v0.6.0

func (t *RagFile) SetUpdateTime(tm time.Time)

func (*RagFile) TableName added in v0.6.0

func (t *RagFile) TableName() string

type RagServiceConfig added in v0.6.0

type RagServiceConfig struct {
	ChunkSize            int     `json:"chunk_size"`
	ChunkOverlap         int     `json:"chunk_overlap"`
	EmbeddingDim         int     `json:"embedding_dim"`
	TopK                 int     `json:"top_k"`
	ScoreThreshold       float64 `json:"score_threshold"`
	EmbedModel           string  `json:"embed_model"`
	DuplicationThreshold float64 `json:"duplication_threshold"`
}

type RecommendConfig

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

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"` // v0.6 deprecated
	LocalProvider  string    `gorm:"column:local_provider;not null;default:''" json:"local_provider"`   // v0.6 deprecated
	Status         int       `gorm:"column:status;not null;default:1" json:"status"`
	CanInstall     int       `gorm:"column:can_install;not null;default:0" json:"can_install"`
	Avatar         string    `gorm:"column:avatar;not null;default:''" json:"avatar"`
	CreatedAt      LocalTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP" json:"created_at"`
	UpdatedAt      LocalTime `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(tm time.Time)

func (*Service) SetUpdateTime

func (t *Service) SetUpdateTime(tm 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"`
	Protocol      string    `gorm:"column:protocol;default:HTTP" json:"protocol"`
	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"`
	Scope         string    `gorm:"column:scope;default:system" json:"scope"` // 'system' or 'custom'
	CreatedAt     LocalTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP" json:"created_at"`
	UpdatedAt     LocalTime `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(tm time.Time)

func (*ServiceProvider) SetUpdateTime

func (t *ServiceProvider) SetUpdateTime(tm 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:"-"`
	WebSocketConnID       string        `json:"-"` // WebSocket connection ID, used to associate multiple messages on the same connection
	Think                 bool          `json:"think"`
}

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
	Protocol        string // Service protocol type, such as GRPC_STREAM
	ExposeProtocol  string
	ServiceProvider *ServiceProvider
}

func (*ServiceTarget) String

func (sr *ServiceTarget) String() string

type SpeechToTextParams

type SpeechToTextParams struct {
	// 基本参数
	TaskID      string `json:"task_id,omitempty"` // 任务ID
	Service     string `json:"service,omitempty"`
	Model       string `json:"model,omitempty"`        // 模型名称
	Language    string `json:"language,omitempty"`     // 语言,如"zh"、"en"
	AudioFormat string `json:"audio_format,omitempty"` // 音频格式
	SampleRate  int    `json:"sample_rate,omitempty"`  // 采样率

	// 高级参数
	UseVAD       bool   `json:"use_vad,omitempty"`       // 是否使用VAD
	ReturnFormat string `json:"return_format,omitempty"` // 返回格式
	MaxDuration  int    `json:"max_duration,omitempty"`  // 最大处理时长(秒)

	// 状态参数
	Action          string `json:"action,omitempty"`            // 当前任务状态 run-task  finish-task
	TotalAudioBytes int    `json:"total_audio_bytes,omitempty"` // 总音频字节数
	LastAudioTime   int64  `json:"last_audio_time,omitempty"`   // 最后一次接收音频的时间
}

SpeechToTextParams 语音识别详细参数结构

func NewSpeechToTextParams

func NewSpeechToTextParams() *SpeechToTextParams

NewSpeechToTextParams 创建语音识别参数对象,设置默认值

func (*SpeechToTextParams) FromJSON

func (p *SpeechToTextParams) FromJSON(data []byte) error

FromJSON 从JSON字符串解析参数

func (*SpeechToTextParams) ToJSON

func (p *SpeechToTextParams) ToJSON() ([]byte, error)

ToJSON 将参数转换为JSON字符串

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 SupportModel

type SupportModel struct {
	Id            string    `json:"id"`
	OllamaId      string    `json:"Ollama_id"`
	Name          string    `json:"name"`
	Avatar        string    `json:"avatar"`
	Description   string    `json:"description"`
	Class         []string  `json:"class"`
	Flavor        string    `json:"flavor"`
	ApiFlavor     string    `json:"api_flavor"`
	Size          string    `json:"size"`
	ParamSize     float32   `json:"params_size"`
	MaxInput      int       `json:"max_input"`
	MaxOutput     int       `json:"max_output"`
	InputLength   int       `json:"input_length"`
	OutputLength  int       `json:"output_length"`
	ServiceSource string    `json:"service_source"`
	ServiceName   string    `json:"service_name"`
	CreatedAt     LocalTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP" json:"created_at"`
	UpdatedAt     LocalTime `gorm:"column:updated_at;default:CURRENT_TIMESTAMP" json:"updated_at"`
	Think         bool      `json:"think"`
	ThinkSwitch   bool      `json:"think_switch"`
	Tools         bool      `json:"tools"` // 是否支持工具调用
	Context       float32   `json:"context"`
}

SupportModel table structure

func (*SupportModel) Index

func (s *SupportModel) Index() map[string]interface{}

func (*SupportModel) PrimaryKey

func (s *SupportModel) PrimaryKey() string

func (*SupportModel) SetCreateTime

func (s *SupportModel) SetCreateTime(tm time.Time)

func (*SupportModel) SetUpdateTime

func (s *SupportModel) SetUpdateTime(tm time.Time)

func (*SupportModel) TableName

func (s *SupportModel) TableName() string

type TextToSpeechRequest

type TextToSpeechRequest struct {
	Text   string `json:"text"`
	Voice  string `json:"voice"`
	Params string `json:"params"`
}

type UnloadModelRequest

type UnloadModelRequest struct {
	Models []string `json:"model"`
}

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    LocalTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP" json:"created_at"`
	UpdatedAt    LocalTime `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(tm time.Time)

func (*VersionUpdateRecord) SetUpdateTime

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

func (*VersionUpdateRecord) TableName

func (t *VersionUpdateRecord) TableName() string

type WebSocketActionMessage

type WebSocketActionMessage struct {
	Task       string               `json:"task"`                 // 任务类型,如"speech-to-text-ws"
	Action     string               `json:"action"`               // 动作类型,如"run-task"或"finish-task"
	TaskID     string               `json:"task_id,omitempty"`    // 任务ID,由服务端生成并返回,用于后续消息关联
	Model      string               `json:"model,omitempty"`      // 模型名称
	Parameters *WebSocketParameters `json:"parameters,omitempty"` // 可选参数
}

WebSocketActionMessage 客户端发送到服务端的基础消息结构

type WebSocketEventHeader

type WebSocketEventHeader struct {
	Action       string `json:"action"`
	Streaming    string `json:"streaming"`
	TaskID       string `json:"task_id"`                 // 任务ID
	Event        string `json:"event"`                   // 事件类型
	ErrorCode    string `json:"error_code,omitempty"`    // 错误码,仅在task-failed事件中出现
	ErrorMessage string `json:"error_message,omitempty"` // 错误信息,仅在task-failed事件中出现
}

WebSocketEventHeader 所有服务端事件的通用头部

type WebSocketEventMessage

type WebSocketEventMessage struct {
	Header  WebSocketEventHeader `json:"header"`            // 事件头部
	Payload interface{}          `json:"payload,omitempty"` // 根据事件类型不同,包含不同的数据
}

WebSocketEventMessage 服务端发送到客户端的基础消息结构

func NewTaskFailedEvent

func NewTaskFailedEvent(taskID, errorCode, errorMessage string) WebSocketEventMessage

NewTaskFailedEvent 创建任务失败事件

func NewTaskFinishedEvent

func NewTaskFinishedEvent(taskID string) WebSocketEventMessage

NewTaskFinishedEvent 创建任务完成事件

func NewTaskStartedEvent

func NewTaskStartedEvent(taskID string) WebSocketEventMessage

NewTaskStartedEvent 创建任务开始事件

type WebSocketFinishTaskAction

type WebSocketFinishTaskAction struct {
	WebSocketActionMessage
}

WebSocketFinishTaskAction 结束任务的消息

func NewFinishTaskAction

func NewFinishTaskAction(taskID, model string) WebSocketFinishTaskAction

NewFinishTaskAction 创建结束任务的消息

type WebSocketParameters

type WebSocketParameters struct {
	Service      string `json:"service,omitempty"`       // 服务名称,如: "speech-to-text" "speech-to-text-ws"
	Format       string `json:"format,omitempty"`        // 音频格式: pcm/wav/mp3
	SampleRate   int    `json:"sample_rate,omitempty"`   // 采样率,通常为16000
	Language     string `json:"language,omitempty"`      // 语言,如"zh"、"en"
	UseVAD       bool   `json:"use_vad,omitempty"`       // 是否使用VAD
	ReturnFormat string `json:"return_format,omitempty"` // 返回格式,如"text"、"json"、"srt"
}

WebSocketParameters 通用参数结构

type WebSocketRecognitionOutput

type WebSocketRecognitionOutput struct {
	Sentence WebSocketSentence `json:"sentence"` // 识别的句子
}

WebSocketRecognitionOutput 语音识别输出结构

type WebSocketResultEvent

type WebSocketResultEvent struct {
	Header  WebSocketEventHeader   `json:"header"`
	Payload WebSocketResultPayload `json:"payload"`
}

WebSocketResultEvent 识别结果事件

func NewResultGeneratedEvent

func NewResultGeneratedEvent(taskID string, beginTime *int, endTime *int, text string) WebSocketResultEvent

NewResultGeneratedEvent 创建识别结果事件

type WebSocketResultPayload

type WebSocketResultPayload struct {
	Output WebSocketRecognitionOutput `json:"output"` // 识别输出
}

WebSocketResultPayload 识别结果的有效载荷

type WebSocketRunTaskAction

type WebSocketRunTaskAction struct {
	WebSocketActionMessage
}

WebSocketRunTaskAction 开始任务的消息

func NewRunTaskAction

func NewRunTaskAction(model string, parameters *WebSocketParameters) WebSocketRunTaskAction

NewRunTaskAction 创建开始任务的消息

type WebSocketSentence

type WebSocketSentence struct {
	BeginTime *int   `json:"begin_time"` // 开始时间,毫秒
	EndTime   *int   `json:"end_time"`   // 结束时间,毫秒,可能为null
	Text      string `json:"text"`       // 识别的文本
}

WebSocketSentence 识别结果中的句子结构

Jump to

Keyboard shortcuts

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