types

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2025 License: Apache-2.0 Imports: 14 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"
)
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"
	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"
	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"
)
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

Variables

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

type DataMigrateVersion struct {
	ID        int       `gorm:"primaryKey;column:id;autoIncrement" json:"id"`
	Version   string    `gorm:"column:version;not null" json:"version"`
	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 (*DataMigrateVersion) Index

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

func (*DataMigrateVersion) PrimaryKey

func (t *DataMigrateVersion) PrimaryKey() string

func (*DataMigrateVersion) SetCreateTime

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

func (*DataMigrateVersion) SetUpdateTime

func (t *DataMigrateVersion) SetUpdateTime(time 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"`
}

type EngineVersionResponse

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

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

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"`
	CanInstall     int       `gorm:"column:can_install;not null;default:0" json:"can_install"`
	Avatar         string    `gorm:"column:avatar;not null;default:''" json:"avatar"`
	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:"-"`
	WebSocketConnID       string        `json:"-"` // WebSocket connection ID, used to associate multiple messages on the same connection
}

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     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"`
	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(time time.Time)

func (*SupportModel) SetUpdateTime

func (s *SupportModel) SetUpdateTime(time 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    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

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