Documentation
¶
Index ¶
- Variables
- type Client
- func (c *Client) Do(ctx context.Context, method, path string, reqData, respData any) error
- func (c *Client) Stream(ctx context.Context, method, path string, data any, fn func([]byte) error) error
- func (c *Client) StreamResponse(ctx context.Context, method, path string, reqData any, ...) (chan []byte, chan error)
- type GRPCClient
- func (c *GRPCClient) Close() error
- func (c *GRPCClient) ModelMetadata(modelName string, modelVersion string) (*grpc_client.ModelMetadataResponse, error)
- func (c *GRPCClient) ServerLive() (*grpc_client.ServerLiveResponse, error)
- func (c *GRPCClient) ServerReady() (*grpc_client.ServerReadyResponse, error)
- type GRPCStreamManager
- func (m *GRPCStreamManager) CloseAllSessions()
- func (m *GRPCStreamManager) CloseSessionByWSConnID(wsConnID string)
- func (m *GRPCStreamManager) CreateSession(wsConnID string, client grpc_client.GRPCInferenceServiceClient, ...) *GRPCStreamSession
- func (m *GRPCStreamManager) GetActiveSessionCount() int
- func (m *GRPCStreamManager) GetSessionByWSConnID(wsConnID string) *GRPCStreamSession
- type GRPCStreamSession
- type TaskInfo
- type WebSocketConnection
- func (c *WebSocketConnection) AddActiveTask(taskID uint64)
- func (c *WebSocketConnection) ClearActiveTasks()
- func (c *WebSocketConnection) Close()
- func (c *WebSocketConnection) GetActiveTaskCount() int
- func (c *WebSocketConnection) GetSTTParams() *types.SpeechToTextParams
- func (c *WebSocketConnection) GetTaskTimes(taskID uint64) (startTime, endTime int64)
- func (c *WebSocketConnection) GetTaskType(taskID uint64) string
- func (c *WebSocketConnection) HasActiveTasks() bool
- func (c *WebSocketConnection) IsTaskStarted(taskID uint64) bool
- func (c *WebSocketConnection) RemoveActiveTask(taskID uint64)
- func (c *WebSocketConnection) SetConnectionTaskFinished()
- func (c *WebSocketConnection) SetConnectionTaskStatus(started bool, timestamp int64)
- func (c *WebSocketConnection) SetTaskFinished(taskID uint64)
- func (c *WebSocketConnection) SetTaskStatus(taskID uint64, started bool, timestamp int64)
- func (c *WebSocketConnection) SetTaskType(taskID uint64, taskType string)
- func (c *WebSocketConnection) WriteJSON(v interface{}) error
- func (c *WebSocketConnection) WriteMessage(messageType int, data []byte) error
- type WebSocketManager
- func (m *WebSocketManager) CloseAllConnections()
- func (m *WebSocketManager) GetActiveConnectionCount() int
- func (m *WebSocketManager) GetAllConnections() []*WebSocketConnection
- func (m *WebSocketManager) GetConnection(connID string) (*WebSocketConnection, bool)
- func (m *WebSocketManager) RegisterConnection(conn *websocket.Conn, taskID uint64, flavor, service string) *WebSocketConnection
- func (m *WebSocketManager) UnregisterConnection(connID string)
- type WebSocketSessionData
Constants ¶
This section is empty.
Variables ¶
var ModelClientMap = make(map[string][]context.CancelFunc)
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
type GRPCClient ¶
type GRPCClient struct {
// contains filtered or unexported fields
}
func NewGRPCClient ¶
func NewGRPCClient(target string) (*GRPCClient, error)
func (*GRPCClient) Close ¶
func (c *GRPCClient) Close() error
func (*GRPCClient) ModelMetadata ¶
func (c *GRPCClient) ModelMetadata(modelName string, modelVersion string) (*grpc_client.ModelMetadataResponse, error)
func (*GRPCClient) ServerLive ¶
func (c *GRPCClient) ServerLive() (*grpc_client.ServerLiveResponse, error)
func (*GRPCClient) ServerReady ¶
func (c *GRPCClient) ServerReady() (*grpc_client.ServerReadyResponse, error)
type GRPCStreamManager ¶
type GRPCStreamManager struct {
// contains filtered or unexported fields
}
GRPCStreamManager 管理所有活跃的GRPC流会话
func GetGlobalGRPCStreamManager ¶
func GetGlobalGRPCStreamManager() *GRPCStreamManager
GetGlobalGRPCStreamManager 获取全局GRPC流管理器实例
func (*GRPCStreamManager) CloseAllSessions ¶
func (m *GRPCStreamManager) CloseAllSessions()
CloseAllSessions 关闭所有会话
func (*GRPCStreamManager) CloseSessionByWSConnID ¶
func (m *GRPCStreamManager) CloseSessionByWSConnID(wsConnID string)
CloseSessionByWSConnID 关闭并删除指定WebSocket连接ID的会话
func (*GRPCStreamManager) CreateSession ¶
func (m *GRPCStreamManager) CreateSession( wsConnID string, client grpc_client.GRPCInferenceServiceClient, stream grpc_client.GRPCInferenceService_ModelStreamInferClient, ctx context.Context, cancelFunc context.CancelFunc, service string, model string, ) *GRPCStreamSession
CreateSession 创建新的GRPC流会话
func (*GRPCStreamManager) GetActiveSessionCount ¶
func (m *GRPCStreamManager) GetActiveSessionCount() int
GetActiveSessionCount 获取活跃会话数
func (*GRPCStreamManager) GetSessionByWSConnID ¶
func (m *GRPCStreamManager) GetSessionByWSConnID(wsConnID string) *GRPCStreamSession
GetSessionByWSConnID 通过WebSocket连接ID获取会话
type GRPCStreamSession ¶
type GRPCStreamSession struct {
WSConnID string // 关联的WebSocket连接ID
Client grpc_client.GRPCInferenceServiceClient // GRPC客户端
Stream grpc_client.GRPCInferenceService_ModelStreamInferClient // 双向流
Context context.Context // 流的上下文
CancelFunc context.CancelFunc // 取消函数
ResponseChannel chan interface{}
Done chan struct{} // 结束信号
Active bool // 会话是否活跃
Service string // 服务名称
Model string // 模型名称
CreatedAt int64 // 创建时间戳
// contains filtered or unexported fields
}
GRPCStreamSession 表示单个GRPC流会话
type TaskInfo ¶
type TaskInfo struct {
TaskType string // 任务类型
TaskStarted bool // 任务是否已启动
StartTime int64 // 任务开始时间
EndTime int64 // 任务结束时间
}
TaskInfo 存储每个任务的基本信息
type WebSocketConnection ¶
type WebSocketConnection struct {
ID string
Conn *websocket.Conn
TaskID uint64
Service string
Flavor string
CreatedAt time.Time
// 最后处理的任务ID
LastTaskID uint64
// 活跃的任务ID列表,用于跟踪未完成的任务
ActiveTasks map[uint64]bool
// 会话数据
SessionData *WebSocketSessionData
// contains filtered or unexported fields
}
WebSocketConnection 表示单个WebSocket连接
func NewWebSocketConnection ¶
func NewWebSocketConnection(conn *websocket.Conn, taskID uint64, flavor, service string) *WebSocketConnection
NewWebSocketConnection 创建新的WebSocket连接
func (*WebSocketConnection) AddActiveTask ¶
func (c *WebSocketConnection) AddActiveTask(taskID uint64)
AddActiveTask 添加一个活跃任务到跟踪列表
func (*WebSocketConnection) ClearActiveTasks ¶
func (c *WebSocketConnection) ClearActiveTasks()
ClearActiveTasks 清除所有活跃任务
func (*WebSocketConnection) GetActiveTaskCount ¶
func (c *WebSocketConnection) GetActiveTaskCount() int
GetActiveTaskCount 获取当前活跃任务数量
func (*WebSocketConnection) GetSTTParams ¶
func (c *WebSocketConnection) GetSTTParams() *types.SpeechToTextParams
GetSTTParams 获取语音识别参数
func (*WebSocketConnection) GetTaskTimes ¶
func (c *WebSocketConnection) GetTaskTimes(taskID uint64) (startTime, endTime int64)
GetTaskTimes 获取指定taskID的任务开始和结束时间
func (*WebSocketConnection) GetTaskType ¶
func (c *WebSocketConnection) GetTaskType(taskID uint64) string
GetTaskType 获取指定taskID的任务类型
func (*WebSocketConnection) HasActiveTasks ¶
func (c *WebSocketConnection) HasActiveTasks() bool
HasActiveTasks 检查是否有任何活跃的任务
func (*WebSocketConnection) IsTaskStarted ¶
func (c *WebSocketConnection) IsTaskStarted(taskID uint64) bool
IsTaskStarted 检查指定taskID的任务是否已启动
func (*WebSocketConnection) RemoveActiveTask ¶
func (c *WebSocketConnection) RemoveActiveTask(taskID uint64)
RemoveActiveTask 从跟踪列表中移除一个活跃任务
func (*WebSocketConnection) SetConnectionTaskFinished ¶
func (c *WebSocketConnection) SetConnectionTaskFinished()
SetConnectionTaskFinished 设置连接基础任务完成状态
func (*WebSocketConnection) SetConnectionTaskStatus ¶
func (c *WebSocketConnection) SetConnectionTaskStatus(started bool, timestamp int64)
SetConnectionTaskStatus 设置连接基础任务状态
func (*WebSocketConnection) SetTaskFinished ¶
func (c *WebSocketConnection) SetTaskFinished(taskID uint64)
SetTaskFinished 设置指定taskID的任务完成状态
func (*WebSocketConnection) SetTaskStatus ¶
func (c *WebSocketConnection) SetTaskStatus(taskID uint64, started bool, timestamp int64)
SetTaskStatus 设置指定taskID的任务状态(启动/结束)
func (*WebSocketConnection) SetTaskType ¶
func (c *WebSocketConnection) SetTaskType(taskID uint64, taskType string)
SetTaskType 设置指定taskID的任务类型
func (*WebSocketConnection) WriteJSON ¶
func (c *WebSocketConnection) WriteJSON(v interface{}) error
WriteJSON 安全地向连接写入JSON数据
func (*WebSocketConnection) WriteMessage ¶
func (c *WebSocketConnection) WriteMessage(messageType int, data []byte) error
WriteMessage 安全地向连接写入消息
type WebSocketManager ¶
type WebSocketManager struct {
// contains filtered or unexported fields
}
WebSocketManager 管理所有活跃的WebSocket连接
func GetGlobalWebSocketManager ¶
func GetGlobalWebSocketManager() *WebSocketManager
GetGlobalWebSocketManager 获取全局WebSocket管理器实例
func (*WebSocketManager) CloseAllConnections ¶
func (m *WebSocketManager) CloseAllConnections()
CloseAllConnections 关闭所有连接
func (*WebSocketManager) GetActiveConnectionCount ¶
func (m *WebSocketManager) GetActiveConnectionCount() int
GetActiveConnectionCount 获取活跃连接数
func (*WebSocketManager) GetAllConnections ¶
func (m *WebSocketManager) GetAllConnections() []*WebSocketConnection
GetAllConnections 获取所有活跃连接
func (*WebSocketManager) GetConnection ¶
func (m *WebSocketManager) GetConnection(connID string) (*WebSocketConnection, bool)
GetConnection 获取指定ID的连接
func (*WebSocketManager) RegisterConnection ¶
func (m *WebSocketManager) RegisterConnection(conn *websocket.Conn, taskID uint64, flavor, service string) *WebSocketConnection
RegisterConnection 注册一个新的WebSocket连接
func (*WebSocketManager) UnregisterConnection ¶
func (m *WebSocketManager) UnregisterConnection(connID string)
UnregisterConnection 注销一个WebSocket连接
type WebSocketSessionData ¶
type WebSocketSessionData struct {
// 任务映射,key为msgTaskID,value为任务信息
Tasks map[uint64]*TaskInfo
// 服务特定数据
STTParams *types.SpeechToTextParams // 语音识别参数
}
WebSocketSessionData 存储WebSocket会话数据