computing

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: MIT Imports: 76 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PingMsg    = "ping"
	PingPeriod = 3 * time.Second
)
View Source
const (
	TransferInterval = 10000
)

Variables

View Source
var (
	ErrGlobalConcurrencyLimit = errors.New("global concurrency limit reached")
	ErrModelConcurrencyLimit  = errors.New("model concurrency limit reached")
)

Concurrency errors

View Source
var (
	ErrQueueFull        = errors.New("queue is full")
	ErrModelQueueFull   = errors.New("model queue is full")
	ErrQueueStopped     = errors.New("queue is stopped")
	ErrQueueShutdown    = errors.New("queue is shutting down")
	ErrRequestTimeout   = errors.New("request timed out")
	ErrRequestCancelled = errors.New("request was cancelled")
)

Queue errors

View Source
var (
	ErrModelNotFound = &ModelError{Message: "model not found"}
)

Custom errors

View Source
var (
	ErrRateLimitExceeded = errors.New("rate limit exceeded")
)

Rate limiter errors

View Source
var (
	ErrServiceNotFound = &SupervisorError{Message: "service not found"}
)

Errors

View Source
var NetworkPolicyFlag bool
View Source
var TaskMap sync.Map

Functions

func BytesToHumanReadable

func BytesToHumanReadable(bytes int64) string

func CheckWalletBlackListForEcp

func CheckWalletBlackListForEcp(walletAddress string) bool

func CheckWalletWhiteListForEcp

func CheckWalletWhiteListForEcp(walletAddress string) bool

func CronTaskForEcp

func CronTaskForEcp()

func DoUbiTaskForDocker

func DoUbiTaskForDocker(c *gin.Context)

func DoZkTask

func DoZkTask(c *gin.Context)

func ExtractExposedPort

func ExtractExposedPort(dockerfilePath string) (string, error)

func GenerateNodeID

func GenerateNodeID(cpRepoPath string) (string, string, string)

func GeneratePriceConfig

func GeneratePriceConfig() error

func GetAggregatedTaskInfo

func GetAggregatedTaskInfo(taskContract string) (string, error)

func GetCpBalance

func GetCpBalance()

func GetCpResource

func GetCpResource(c *gin.Context)

func GetNodeId

func GetNodeId(cpRepoPath string) string

func GetOwnerAddressAndWorkerAddress

func GetOwnerAddressAndWorkerAddress() (string, string, error)

func GetPrice

func GetPrice(c *gin.Context)

GetPrice is a HTTP handler that returns the current pricing configuration

func GetTaskInfoOnChain

func GetTaskInfoOnChain(taskContract string) (models.EcpTaskInfo, error)

func GetToken

func GetToken() (string, error)

func GetUbiResourceExporterMetrics

func GetUbiResourceExporterMetrics(c *gin.Context)

func ImportImageToContainerd

func ImportImageToContainerd(tarFile string) error

func InitComputingProvider

func InitComputingProvider(cpRepoPath string) string

func ReceiveUbiProof

func ReceiveUbiProof(c *gin.Context)

func RestartResourceExporter

func RestartResourceExporter() error

func RestartTraefikService

func RestartTraefikService() error

func RetryFn

func RetryFn(fn func() error, maxRetries int, delay time.Duration) error

func SyncCpAccountInfo

func SyncCpAccountInfo() (*models.Account, error)

func ValidateName

func ValidateName(name string) error

Types

type AckPayload

type AckPayload struct {
	RequestID string `json:"request_id"`
	Success   bool   `json:"success"`
	Message   string `json:"message,omitempty"`
}

AckPayload for acknowledgments

type AdaptiveTokenBucket

type AdaptiveTokenBucket struct {
	*TokenBucket
	// contains filtered or unexported fields
}

AdaptiveTokenBucket extends TokenBucket with adaptive rate based on feedback

func NewAdaptiveTokenBucket

func NewAdaptiveTokenBucket(initialRate float64, burstSize int, targetLatency time.Duration) *AdaptiveTokenBucket

NewAdaptiveTokenBucket creates an adaptive token bucket

func (*AdaptiveTokenBucket) RecordLatency

func (atb *AdaptiveTokenBucket) RecordLatency(latency time.Duration)

RecordLatency records a request latency and adjusts rate accordingly

type BackoffCalculator

type BackoffCalculator struct {
	// contains filtered or unexported fields
}

BackoffCalculator provides various backoff strategies

func NewBackoffCalculator

func NewBackoffCalculator(strategy BackoffStrategy, initialDelay, maxDelay time.Duration) *BackoffCalculator

NewBackoffCalculator creates a new backoff calculator

func (*BackoffCalculator) Calculate

func (bc *BackoffCalculator) Calculate(attempt int) time.Duration

Calculate returns the delay for a given attempt

func (*BackoffCalculator) SetJitter

func (bc *BackoffCalculator) SetJitter(j float64) *BackoffCalculator

SetJitter sets the jitter factor

func (*BackoffCalculator) SetMultiplier

func (bc *BackoffCalculator) SetMultiplier(m float64) *BackoffCalculator

SetMultiplier sets the backoff multiplier (for exponential)

type BackoffStrategy

type BackoffStrategy int

BackoffStrategy defines the backoff calculation method

const (
	BackoffExponential BackoffStrategy = iota
	BackoffLinear
	BackoffConstant
	BackoffFibonacci
)

type CircuitBreaker

type CircuitBreaker struct {
	// contains filtered or unexported fields
}

CircuitBreaker implements the circuit breaker pattern

func NewCircuitBreaker

func NewCircuitBreaker(failureThreshold, successThreshold int, timeout time.Duration) *CircuitBreaker

NewCircuitBreaker creates a new circuit breaker

func (*CircuitBreaker) Allow

func (cb *CircuitBreaker) Allow() bool

Allow checks if a request should be allowed

func (*CircuitBreaker) GetState

func (cb *CircuitBreaker) GetState() CircuitState

GetState returns the current circuit state

func (*CircuitBreaker) RecordFailure

func (cb *CircuitBreaker) RecordFailure()

RecordFailure records a failed operation

func (*CircuitBreaker) RecordSuccess

func (cb *CircuitBreaker) RecordSuccess()

RecordSuccess records a successful operation

func (*CircuitBreaker) Reset

func (cb *CircuitBreaker) Reset()

Reset resets the circuit breaker to closed state

func (*CircuitBreaker) SetStateChangeCallback

func (cb *CircuitBreaker) SetStateChangeCallback(callback func(from, to CircuitState))

SetStateChangeCallback sets a callback for state changes

type CircuitState

type CircuitState int

CircuitState represents the state of a circuit breaker

const (
	CircuitClosed CircuitState = iota
	CircuitOpen
	CircuitHalfOpen
)

func (CircuitState) String

func (s CircuitState) String() string

type ConcurrencyConfig

type ConcurrencyConfig struct {
	GlobalMaxConcurrent int           // Maximum concurrent requests globally
	DefaultModelMax     int           // Default max concurrent per model
	AcquireTimeout      time.Duration // Timeout for acquiring a slot
	EnableGPUAwareness  bool          // Adjust limits based on GPU memory
	GPUMemoryBufferMB   int           // Buffer to keep free in GPU memory
}

ConcurrencyConfig configures the concurrency limiter

func DefaultConcurrencyConfig

func DefaultConcurrencyConfig() ConcurrencyConfig

DefaultConcurrencyConfig returns sensible defaults

type ConcurrencyLimiter

type ConcurrencyLimiter struct {
	// contains filtered or unexported fields
}

ConcurrencyLimiter manages concurrent request limits

func NewConcurrencyLimiter

func NewConcurrencyLimiter(config ConcurrencyConfig, gpuCollector *GPUMetricsCollector) *ConcurrencyLimiter

NewConcurrencyLimiter creates a new concurrency limiter

func (*ConcurrencyLimiter) Acquire

func (cl *ConcurrencyLimiter) Acquire(ctx context.Context, modelID string) (*ConcurrencyToken, error)

Acquire acquires slots for a request (both global and model-specific)

func (*ConcurrencyLimiter) GetMetrics

func (cl *ConcurrencyLimiter) GetMetrics() ConcurrencyMetrics

GetMetrics returns concurrency metrics

func (*ConcurrencyLimiter) GetModelConcurrency

func (cl *ConcurrencyLimiter) GetModelConcurrency(modelID string) (current, max int)

GetModelConcurrency returns current and max concurrency for a model

func (*ConcurrencyLimiter) RegisterModel

func (cl *ConcurrencyLimiter) RegisterModel(modelID string, maxConcurrent int, gpuMemoryMB int)

RegisterModel sets up concurrency limits for a model

func (*ConcurrencyLimiter) SetGlobalMax

func (cl *ConcurrencyLimiter) SetGlobalMax(max int)

SetGlobalMax updates the global maximum concurrent requests

func (*ConcurrencyLimiter) SetModelMax

func (cl *ConcurrencyLimiter) SetModelMax(modelID string, max int)

SetModelMax updates the maximum concurrent requests for a model

func (*ConcurrencyLimiter) Start

func (cl *ConcurrencyLimiter) Start()

Start begins the concurrency limiter

func (*ConcurrencyLimiter) Stop

func (cl *ConcurrencyLimiter) Stop()

Stop stops the concurrency limiter

func (*ConcurrencyLimiter) TryAcquire

func (cl *ConcurrencyLimiter) TryAcquire(modelID string) (*ConcurrencyToken, error)

TryAcquire attempts to acquire without blocking

func (*ConcurrencyLimiter) UnregisterModel

func (cl *ConcurrencyLimiter) UnregisterModel(modelID string)

UnregisterModel removes concurrency limits for a model

type ConcurrencyMetrics

type ConcurrencyMetrics struct {
	GlobalActive   int64            `json:"global_active"`
	GlobalMax      int              `json:"global_max"`
	TotalAcquired  int64            `json:"total_acquired"`
	TotalReleased  int64            `json:"total_released"`
	TotalRejected  int64            `json:"total_rejected"`
	TotalTimeouts  int64            `json:"total_timeouts"`
	PerModelActive map[string]int64 `json:"per_model_active"`
	PerModelMax    map[string]int   `json:"per_model_max"`
	AvgHoldTimeMs  float64          `json:"avg_hold_time_ms"`
}

ConcurrencyMetrics tracks concurrency statistics

type ConcurrencyToken

type ConcurrencyToken struct {
	// contains filtered or unexported fields
}

ConcurrencyToken represents an acquired concurrency slot

func (*ConcurrencyToken) Release

func (ct *ConcurrencyToken) Release()

Release releases the concurrency slots

type Config

type Config struct {
	Resources map[string]string `toml:"-"`
}

type CpBalanceService

type CpBalanceService struct {
	*gorm.DB
}

func NewCpBalanceService

func NewCpBalanceService() CpBalanceService

func (CpBalanceService) GetCpBalance

func (cpServ CpBalanceService) GetCpBalance(cpAccount string) (*models.CpBalanceEntity, error)

func (CpBalanceService) SaveCpBalance

func (cpServ CpBalanceService) SaveCpBalance(cpBalance models.CpBalanceEntity) (err error)

func (CpBalanceService) UpdateCpBalance

func (cpServ CpBalanceService) UpdateCpBalance(cpBalance models.CpBalanceEntity) error

type CpInfoService

type CpInfoService struct {
	*gorm.DB
}

func NewCpInfoService

func NewCpInfoService() CpInfoService

func (CpInfoService) GetCpInfoEntityByAccountAddress

func (cpServ CpInfoService) GetCpInfoEntityByAccountAddress(accountAddress string) (*models.CpInfoEntity, error)

func (CpInfoService) SaveCpInfoEntity

func (cpServ CpInfoService) SaveCpInfoEntity(cp *models.CpInfoEntity) (err error)

func (CpInfoService) UpdateCpInfoByNodeId

func (cpServ CpInfoService) UpdateCpInfoByNodeId(cp *models.CpInfoEntity) (err error)

type CronTask

type CronTask struct {
	// contains filtered or unexported fields
}

func NewCronTask

func NewCronTask(nodeId string) *CronTask

func (*CronTask) CheckCpBalance

func (task *CronTask) CheckCpBalance()

func (*CronTask) DeleteSpaceLog

func (task *CronTask) DeleteSpaceLog()

func (*CronTask) RunTask

func (task *CronTask) RunTask()

type DeterministicChallengeData

type DeterministicChallengeData struct {
	Prompt    string `json:"prompt"`
	Seed      int    `json:"seed"`
	MaxTokens int    `json:"max_tokens"`
}

DeterministicChallengeData represents a deterministic inference challenge from the server

type DeterministicResponseData

type DeterministicResponseData struct {
	Tokens []string `json:"tokens"`
	Text   string   `json:"text"`
}

DeterministicResponseData is the response sent back for a deterministic challenge

type DockerService

type DockerService struct {
	// contains filtered or unexported fields
}

func NewDockerService

func NewDockerService() *DockerService

func (*DockerService) BuildImage

func (ds *DockerService) BuildImage(jobUuid, buildPath, imageName string) error

func (*DockerService) CheckRunningContainer

func (ds *DockerService) CheckRunningContainer(containerName string) (bool, string, error)

func (*DockerService) CleanResourceForDocker

func (ds *DockerService) CleanResourceForDocker(onlyClearContainer bool)

func (*DockerService) ContainerCreateAndStart

func (ds *DockerService) ContainerCreateAndStart(config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, containerName string) error

func (*DockerService) ContainerExec

func (ds *DockerService) ContainerExec(containerID string, cmd []string) (string, error)

func (*DockerService) ContainerLogs

func (ds *DockerService) ContainerLogs(containerName string) (string, error)

func (*DockerService) CreateNetwork

func (ds *DockerService) CreateNetwork(networkName string) error

func (*DockerService) GetContainerLogStream

func (ds *DockerService) GetContainerLogStream(ctx context.Context, containerName string) (io.ReadCloser, error)

func (*DockerService) GetContainerStatus

func (ds *DockerService) GetContainerStatus() (map[string]string, error)

func (*DockerService) IsExistContainer

func (ds *DockerService) IsExistContainer(containerName string) bool

func (*DockerService) PullImage

func (ds *DockerService) PullImage(imageName string) error

func (*DockerService) PushImage

func (ds *DockerService) PushImage(imagesName string) error

func (*DockerService) RemoveContainerByName

func (ds *DockerService) RemoveContainerByName(containerName string) error

func (*DockerService) RemoveImage

func (ds *DockerService) RemoveImage(imageId string) error

func (*DockerService) SaveDockerImage

func (ds *DockerService) SaveDockerImage(imageName string) (string, error)

type EcpJobService

type EcpJobService struct {
	*gorm.DB
}

func NewEcpJobService

func NewEcpJobService() EcpJobService

func (EcpJobService) DeleteContainerByUuid

func (cpServ EcpJobService) DeleteContainerByUuid(uuid string) (err error)

func (EcpJobService) GetEcpJobByUuid

func (cpServ EcpJobService) GetEcpJobByUuid(uuid string) (*models.EcpJobEntity, error)

func (EcpJobService) GetEcpJobList

func (cpServ EcpJobService) GetEcpJobList(status []string) ([]models.EcpJobEntity, error)

func (EcpJobService) GetEcpJobs

func (cpServ EcpJobService) GetEcpJobs(jobUuid string) ([]models.EcpJobEntity, error)

func (EcpJobService) GetEcpJobsByLimit

func (cpServ EcpJobService) GetEcpJobsByLimit(tailNum int) ([]models.EcpJobEntity, error)

func (EcpJobService) SaveEcpJobEntity

func (cpServ EcpJobService) SaveEcpJobEntity(job *models.EcpJobEntity) (err error)

func (EcpJobService) UpdateEcpJobEntity

func (cpServ EcpJobService) UpdateEcpJobEntity(jobUuid, status string) (err error)

func (EcpJobService) UpdateEcpJobEntityContainerName

func (cpServ EcpJobService) UpdateEcpJobEntityContainerName(jobUuid string, containerName string) (err error)

func (EcpJobService) UpdateEcpJobEntityMessage

func (cpServ EcpJobService) UpdateEcpJobEntityMessage(jobUuid string, message string) (err error)

func (EcpJobService) UpdateEcpJobEntityPortsAndServiceUrl

func (cpServ EcpJobService) UpdateEcpJobEntityPortsAndServiceUrl(jobUuid, portMap, serviceUrl string) (err error)

func (EcpJobService) UpdateEcpJobEntityRewardAndBlock

func (cpServ EcpJobService) UpdateEcpJobEntityRewardAndBlock(jobUuid string, blockNumber int64, reward float64) (err error)

type ErrorLine

type ErrorLine struct {
	Error       string `json:"error"`
	ErrorDetail struct {
		Message string `json:"message"`
	} `json:"errorDetail"`
}

type ErrorPayload

type ErrorPayload struct {
	RequestID string `json:"request_id,omitempty"`
	Code      int    `json:"code"`
	Message   string `json:"message"`
}

ErrorPayload for error responses

type FingerprintChallengeData

type FingerprintChallengeData struct {
	Files []FingerprintChallengeFile `json:"files"`
}

FingerprintChallengeData represents the fingerprint challenge from the server

type FingerprintChallengeFile

type FingerprintChallengeFile struct {
	Filename     string `json:"filename"`
	ExpectedHash string `json:"expected_hash"`
}

FingerprintChallengeFile is a single file in a fingerprint challenge

type FingerprintResponseData

type FingerprintResponseData struct {
	Files []FingerprintResponseFile `json:"files"`
}

FingerprintResponseData is the response sent back for a fingerprint challenge

type FingerprintResponseFile

type FingerprintResponseFile struct {
	Filename string `json:"filename"`
	Hash     string `json:"hash"`
	Status   string `json:"status"` // "pass", "fail", "missing"
}

FingerprintResponseFile is a single file result in a fingerprint response

type GPUInfo

type GPUInfo struct {
	Name      string
	Total     int
	Used      int
	Available int
	FreeIndex []string
}

type GPUManager

type GPUManager struct {
	// contains filtered or unexported fields
}

func NewGpuManager

func NewGpuManager() *GPUManager

func (*GPUManager) AllocateGPU

func (gm *GPUManager) AllocateGPU(key string, count int) ([]string, error)

func (*GPUManager) CheckAvailableGPU

func (gm *GPUManager) CheckAvailableGPU() (string, bool)

func (*GPUManager) GetGPU

func (gm *GPUManager) GetGPU(key string) (GPUInfo, bool)

func (*GPUManager) ReleaseGPU

func (gm *GPUManager) ReleaseGPU(key string, count int, indexs []string) error

func (*GPUManager) UpdateGPU

func (gm *GPUManager) UpdateGPU(key string, gpuInfo GPUInfo)

type GPUMetrics

type GPUMetrics struct {
	Index            int     `json:"index"`
	Name             string  `json:"name"`
	UUID             string  `json:"uuid,omitempty"`
	UtilizationPct   float64 `json:"utilization_percent"`
	MemoryUsedMB     float64 `json:"memory_used_mb"`
	MemoryTotalMB    float64 `json:"memory_total_mb"`
	MemoryUsagePct   float64 `json:"memory_usage_percent"`
	TemperatureC     float64 `json:"temperature_c"`
	PowerDrawW       float64 `json:"power_draw_w"`
	PowerLimitW      float64 `json:"power_limit_w"`
	FanSpeedPct      float64 `json:"fan_speed_percent,omitempty"`
	ComputeProcesses int     `json:"compute_processes"`
}

GPUMetrics tracks metrics for a single GPU

type GPUMetricsCollector

type GPUMetricsCollector struct{}

GPUMetricsCollector collects real-time GPU metrics using nvidia-smi

func NewGPUMetricsCollector

func NewGPUMetricsCollector() *GPUMetricsCollector

NewGPUMetricsCollector creates a new GPU metrics collector

func (*GPUMetricsCollector) CollectGPUMetrics

func (c *GPUMetricsCollector) CollectGPUMetrics() []GPUMetrics

CollectGPUMetrics collects real-time metrics from all available GPUs

func (*GPUMetricsCollector) GetAggregatedGPUMetrics

func (c *GPUMetricsCollector) GetAggregatedGPUMetrics() (avgUtilization, avgMemoryUsage float64)

GetAggregatedGPUMetrics returns aggregated metrics across all GPUs

func (*GPUMetricsCollector) IsGPUAvailable

func (c *GPUMetricsCollector) IsGPUAvailable() bool

IsGPUAvailable checks if any GPU is available

type HardwareField

type HardwareField struct {
	TagValue int
	Name     string
	Value    string
}

func GetStructByTag

func GetStructByTag(v interface{}) ([]HardwareField, error)

type HardwareInfo

type HardwareInfo struct {
	GPUType           string `json:"gpu_type"`
	GPUModel          string `json:"gpu_model"`
	VRAMGB            int    `json:"vram_gb"`
	GPUCount          int    `json:"gpu_count"`
	ComputeCapability string `json:"compute_capability"`
	DriverVersion     string `json:"driver_version"`
	CUDAVersion       string `json:"cuda_version"`
	ServingEngine     string `json:"serving_engine,omitempty"` // "vllm", "sglang", "llamacpp", "ollama", "tgi", "unknown"
}

HardwareInfo contains GPU hardware specifications

func DetectGPUHardware

func DetectGPUHardware() *HardwareInfo

DetectGPUHardware detects GPU hardware information

type HardwarePrice

type HardwarePrice struct {
	TARGET_CPU          string `toml:"TARGET_CPU" tag:"1"`
	TARGET_MEMORY       string `toml:"TARGET_MEMORY" tag:"2"`
	TARGET_HD_EPHEMERAL string `toml:"TARGET_HD_EPHEMERAL" tag:"3"`
	TARGET_GPU_DEFAULT  string `toml:"TARGET_GPU_DEFAULT" tag:"4"`
	GpusPrice           map[string]string
}

func ReadPriceConfig

func ReadPriceConfig() (HardwarePrice, error)

type HealthCheckConfig

type HealthCheckConfig struct {
	Interval           time.Duration // How often to check health
	Timeout            time.Duration // Timeout for each health check
	UnhealthyThreshold int           // Consecutive failures before marking unhealthy
	HealthyThreshold   int           // Consecutive successes to recover from unhealthy
	CircuitOpenTime    time.Duration // How long to keep circuit open before retrying
}

HealthCheckConfig configures the health checker behavior

func DefaultHealthCheckConfig

func DefaultHealthCheckConfig() HealthCheckConfig

DefaultHealthCheckConfig returns default health check configuration

type HeartbeatPayload

type HeartbeatPayload struct {
	NodeID      string             `json:"node_id"`               // Local node ID (not the DB provider ID)
	ProviderID  string             `json:"provider_id,omitempty"` // Deprecated: use NodeID
	Timestamp   int64              `json:"timestamp"`
	Metrics     map[string]float64 `json:"metrics,omitempty"`
	Models      []string           `json:"models,omitempty"`       // Current model list (allows dynamic model updates without reconnect)
	ModelHealth map[string]string  `json:"model_health,omitempty"` // modelID -> health status (backup for health updates)
	Hardware    *HardwareInfo      `json:"hardware,omitempty"`     // GPU hardware info (periodically updated)
}

HeartbeatPayload for liveness checks

type HistoricalDataPoint

type HistoricalDataPoint struct {
	Timestamp         time.Time `json:"timestamp"`
	TotalRequests     int64     `json:"total_requests"`
	SuccessRate       float64   `json:"success_rate"`
	AvgLatencyMs      float64   `json:"avg_latency_ms"`
	P99LatencyMs      float64   `json:"p99_latency_ms"`
	TokensPerSecond   float64   `json:"tokens_per_second"`
	RequestsPerMinute float64   `json:"requests_per_minute"`
}

HistoricalDataPoint represents an aggregated data point for API responses

type HttpClient

type HttpClient struct {
	// contains filtered or unexported fields
}

func NewHttpClient

func NewHttpClient(host string, header http.Header) *HttpClient

func (*HttpClient) Get

func (c *HttpClient) Get(api string, queries url.Values, dest any) error

func (*HttpClient) PostForm

func (c *HttpClient) PostForm(api string, data url.Values, dest any) error

func (*HttpClient) PostJSON

func (c *HttpClient) PostJSON(api string, data any, dest any) error

func (*HttpClient) Request

func (c *HttpClient) Request(method string, api string, body io.Reader, dest any, contentType ...string) (err error)

type ImageJobService

type ImageJobService struct {
}

func NewImageJobService

func NewImageJobService() *ImageJobService

func (*ImageJobService) CheckJobCondition

func (*ImageJobService) CheckJobCondition(c *gin.Context)

func (*ImageJobService) DeleteJob

func (*ImageJobService) DeleteJob(c *gin.Context)

func (*ImageJobService) DeployInference

func (*ImageJobService) DeployInference(c *gin.Context, deployJob models.DeployJobParam, totalCost float64, logUrl string)

func (*ImageJobService) DeployJob

func (imageJob *ImageJobService) DeployJob(c *gin.Context)

func (*ImageJobService) DeployMining

func (*ImageJobService) DeployMining(c *gin.Context, deployJob models.DeployJobParam, totalCost float64, logUrl string, price string)

func (*ImageJobService) DockerLogsHandler

func (*ImageJobService) DockerLogsHandler(c *gin.Context)

func (*ImageJobService) GetJobStatus

func (*ImageJobService) GetJobStatus(c *gin.Context)

type InferenceClient

type InferenceClient struct {
	// contains filtered or unexported fields
}

InferenceClient manages WebSocket connection to Swan Inference service

func NewInferenceClient

func NewInferenceClient(nodeID, workerAddr, ownerAddr string) *InferenceClient

NewInferenceClient creates a new Inference client

func (*InferenceClient) GetMetrics

func (c *InferenceClient) GetMetrics() InferenceMetrics

GetMetrics returns a snapshot of the current metrics

func (*InferenceClient) GetMetricsPrometheus

func (c *InferenceClient) GetMetricsPrometheus() string

GetMetricsPrometheus returns metrics in Prometheus text format

func (*InferenceClient) GetNodeID

func (c *InferenceClient) GetNodeID() string

GetNodeID returns the local node ID

func (*InferenceClient) IsConnected

func (c *InferenceClient) IsConnected() bool

IsConnected returns whether the client is connected, registered, and healthy. A connection is considered unhealthy if 3+ consecutive heartbeats went unacknowledged.

func (*InferenceClient) SendModelHealthUpdate

func (c *InferenceClient) SendModelHealthUpdate(modelHealth map[string]string)

SendModelHealthUpdate sends a model health update to Swan Inference This is called when model health status changes (healthy/degraded/unhealthy)

func (*InferenceClient) SetInferenceHandler

func (c *InferenceClient) SetInferenceHandler(handler InferenceHandler)

SetInferenceHandler sets the handler for non-streaming inference requests

func (*InferenceClient) SetModelHealthProvider

func (c *InferenceClient) SetModelHealthProvider(provider func() map[string]string)

SetModelHealthProvider sets the function that provides current model health for heartbeats

func (*InferenceClient) SetModelMappingsProvider

func (c *InferenceClient) SetModelMappingsProvider(provider func() map[string]ModelMapping)

SetModelMappingsProvider sets the function that returns model mappings for format/quantization

func (*InferenceClient) SetStreamingInferenceHandler

func (c *InferenceClient) SetStreamingInferenceHandler(handler StreamingInferenceHandler)

SetStreamingInferenceHandler sets the handler for streaming inference requests

func (*InferenceClient) SetWarmupHandler

func (c *InferenceClient) SetWarmupHandler(handler WarmupHandler)

SetWarmupHandler sets the handler for model warmup requests

func (*InferenceClient) Start

func (c *InferenceClient) Start() error

Start connects to Swan Inference and starts the client

func (*InferenceClient) Stop

func (c *InferenceClient) Stop()

Stop gracefully shuts down the client

type InferenceHandler

type InferenceHandler func(payload InferencePayload) (*InferenceResponse, error)

InferenceHandler handles non-streaming inference requests from Inference service

type InferenceMetrics

type InferenceMetrics struct {

	// Connection metrics
	ConnectionState    string    `json:"connection_state"`
	LastConnectedAt    time.Time `json:"last_connected_at,omitempty"`
	LastDisconnectedAt time.Time `json:"last_disconnected_at,omitempty"`
	ReconnectCount     int64     `json:"reconnect_count"`

	// Request metrics (aggregated)
	TotalRequests     int64   `json:"total_requests"`
	SuccessfulReqs    int64   `json:"successful_requests"`
	FailedReqs        int64   `json:"failed_requests"`
	StreamingReqs     int64   `json:"streaming_requests"`
	AvgLatencyMs      float64 `json:"avg_latency_ms"`
	P50LatencyMs      float64 `json:"p50_latency_ms"`
	P95LatencyMs      float64 `json:"p95_latency_ms"`
	P99LatencyMs      float64 `json:"p99_latency_ms"`
	TotalTokensIn     int64   `json:"total_tokens_in"`
	TotalTokensOut    int64   `json:"total_tokens_out"`
	TokensPerSecond   float64 `json:"tokens_per_second"`
	ActiveRequests    int64   `json:"active_requests"`
	RequestsPerMinute float64 `json:"requests_per_minute"`

	// Per-model metrics
	ModelMetrics map[string]*ModelMetrics `json:"model_metrics"`

	// GPU metrics
	GPUMetrics []GPUMetrics `json:"gpu_metrics"`

	// System metrics
	CPUUsagePercent    float64 `json:"cpu_usage_percent"`
	MemoryUsagePercent float64 `json:"memory_usage_percent"`
	MemoryUsedGB       float64 `json:"memory_used_gb"`
	MemoryTotalGB      float64 `json:"memory_total_gb"`
	// contains filtered or unexported fields
}

InferenceMetrics tracks metrics for the inference service

func NewInferenceMetrics

func NewInferenceMetrics() *InferenceMetrics

NewInferenceMetrics creates a new InferenceMetrics instance

func (*InferenceMetrics) GetPrometheusMetrics

func (m *InferenceMetrics) GetPrometheusMetrics() string

GetPrometheusMetrics returns metrics in Prometheus text format

func (*InferenceMetrics) GetRequestHistory

func (m *InferenceMetrics) GetRequestHistory(limit int, modelFilter string) []RequestMetric

GetRequestHistory returns recent requests, optionally filtered by model

func (*InferenceMetrics) GetSnapshot

func (m *InferenceMetrics) GetSnapshot() InferenceMetrics

GetSnapshot returns a copy of the current metrics

func (*InferenceMetrics) RecordConnectionState

func (m *InferenceMetrics) RecordConnectionState(state string)

RecordConnectionState updates the connection state

func (*InferenceMetrics) RecordReconnect

func (m *InferenceMetrics) RecordReconnect()

RecordReconnect increments the reconnect counter

func (*InferenceMetrics) RecordRequest

func (m *InferenceMetrics) RecordRequest(req RequestMetric)

RecordRequest adds a request to the history circular buffer

func (*InferenceMetrics) RecordRequestEnd

func (m *InferenceMetrics) RecordRequestEnd(model string, latencyMs float64, tokensIn, tokensOut int, success bool, errorReason string)

RecordRequestEnd records the completion of a request

func (*InferenceMetrics) RecordRequestStart

func (m *InferenceMetrics) RecordRequestStart(model string, streaming bool)

RecordRequestStart records the start of a request

func (*InferenceMetrics) Reset

func (m *InferenceMetrics) Reset()

Reset resets all metrics

func (*InferenceMetrics) UpdateGPUMetrics

func (m *InferenceMetrics) UpdateGPUMetrics(gpuMetrics []GPUMetrics)

UpdateGPUMetrics updates the GPU metrics

func (*InferenceMetrics) UpdateSystemMetrics

func (m *InferenceMetrics) UpdateSystemMetrics(cpuPercent, memPercent, memUsedGB, memTotalGB float64)

UpdateSystemMetrics updates system-level metrics

type InferencePayload

type InferencePayload struct {
	EndpointID string          `json:"endpoint_id"`
	ModelID    string          `json:"model_id"`
	Request    json.RawMessage `json:"request"`
	Stream     bool            `json:"stream"` // Whether to stream the response
}

InferencePayload is sent to provider for inference request

type InferenceResponse

type InferenceResponse struct {
	RequestID  string          `json:"request_id"`
	Response   json.RawMessage `json:"response"`
	Error      string          `json:"error,omitempty"`
	StatusCode int             `json:"status_code,omitempty"` // HTTP status code for Swan Inference to map to proper responses
	Latency    int64           `json:"latency_ms"`
}

InferenceResponse is returned by provider

type InferenceService

type InferenceService struct {
	// contains filtered or unexported fields
}

InferenceService manages the Inference client and inference handling

func NewInferenceService

func NewInferenceService(nodeID, cpPath string) *InferenceService

NewInferenceService creates a new Inference service

func (*InferenceService) DisableModel

func (s *InferenceService) DisableModel(modelID string) error

DisableModel disables a model from serving requests

func (*InferenceService) EnableModel

func (s *InferenceService) EnableModel(modelID string) error

EnableModel enables a model for serving requests

func (*InferenceService) ForceHealthCheck

func (s *InferenceService) ForceHealthCheck(modelID string)

ForceHealthCheck triggers an immediate health check for a model

func (*InferenceService) GetActiveModels

func (s *InferenceService) GetActiveModels() []string

GetActiveModels returns the list of active model deployments

func (*InferenceService) GetAllModelHealth

func (s *InferenceService) GetAllModelHealth() map[string]*ModelStatus

GetAllModelHealth returns health status of all models

func (*InferenceService) GetAllModels

func (s *InferenceService) GetAllModels() []*RegisteredModel

GetAllModels returns all registered models with their status

func (*InferenceService) GetClient

func (s *InferenceService) GetClient() *InferenceClient

GetClient returns the Inference client

func (*InferenceService) GetConcurrencyMetrics

func (s *InferenceService) GetConcurrencyMetrics() *ConcurrencyMetrics

GetConcurrencyMetrics returns concurrency limiter metrics

func (*InferenceService) GetHealthChecker

func (s *InferenceService) GetHealthChecker() *ModelHealthChecker

GetHealthChecker returns the model health checker

func (*InferenceService) GetMetrics

func (s *InferenceService) GetMetrics() *InferenceMetrics

GetMetrics returns the current inference metrics

func (*InferenceService) GetMetricsHistory

func (s *InferenceService) GetMetricsHistory(duration, resolution time.Duration) ([]HistoricalDataPoint, error)

GetMetricsHistory returns historical metrics for the specified duration and resolution

func (*InferenceService) GetMetricsPrometheus

func (s *InferenceService) GetMetricsPrometheus() string

GetMetricsPrometheus returns metrics in Prometheus text format

func (*InferenceService) GetModelDetailedMetrics

func (s *InferenceService) GetModelDetailedMetrics(modelID string) map[string]interface{}

GetModelDetailedMetrics returns detailed metrics for a specific model including recent requests

func (*InferenceService) GetModelHealth

func (s *InferenceService) GetModelHealth(modelID string) (*ModelStatus, bool)

GetModelHealth returns the health status of a specific model

func (*InferenceService) GetModelStatus

func (s *InferenceService) GetModelStatus(modelID string) (*RegisteredModel, bool)

GetModelStatus returns the status of a specific model

func (*InferenceService) GetModelsSummary

func (s *InferenceService) GetModelsSummary() map[string]interface{}

GetModelsSummary returns a summary of model statuses

func (*InferenceService) GetRateLimiterMetrics

func (s *InferenceService) GetRateLimiterMetrics() *RateLimiterMetrics

GetRateLimiterMetrics returns rate limiter metrics

func (*InferenceService) GetRegistry

func (s *InferenceService) GetRegistry() *ModelRegistry

GetRegistry returns the model registry

func (*InferenceService) GetRequestHistory

func (s *InferenceService) GetRequestHistory(limit int, modelFilter string) []RequestMetric

GetRequestHistory returns recent request history, optionally filtered by model

func (*InferenceService) GetRequestManagementStatus

func (s *InferenceService) GetRequestManagementStatus() map[string]interface{}

GetRequestManagementStatus returns combined status of all request management components

func (*InferenceService) GetRetryMetrics

func (s *InferenceService) GetRetryMetrics() *RetryMetrics

GetRetryMetrics returns retry policy metrics

func (*InferenceService) IsConnected

func (s *InferenceService) IsConnected() bool

IsConnected returns whether the Inference client is connected

func (*InferenceService) IsHealthy

func (s *InferenceService) IsHealthy() bool

IsHealthy returns whether the service is healthy (connected to Swan Inference)

func (*InferenceService) Name

func (s *InferenceService) Name() string

Name returns the service name for the supervisor

func (*InferenceService) RegisterModels

func (s *InferenceService) RegisterModels(models []string)

RegisterModels updates the models this provider serves

func (*InferenceService) ReloadModels

func (s *InferenceService) ReloadModels() error

ReloadModels manually triggers a reload of the models configuration

func (*InferenceService) SetGlobalConcurrencyLimit

func (s *InferenceService) SetGlobalConcurrencyLimit(max int)

SetGlobalConcurrencyLimit updates the global concurrency limit

func (*InferenceService) SetGlobalRateLimit

func (s *InferenceService) SetGlobalRateLimit(tokensPerSecond float64)

SetGlobalRateLimit updates the global rate limit

func (*InferenceService) SetModelConcurrencyLimit

func (s *InferenceService) SetModelConcurrencyLimit(modelID string, max int)

SetModelConcurrencyLimit sets concurrency limit for a specific model

func (*InferenceService) SetModelRateLimit

func (s *InferenceService) SetModelRateLimit(modelID string, tokensPerSecond float64, burstSize int)

SetModelRateLimit sets rate limit for a specific model

func (*InferenceService) Start

func (s *InferenceService) Start() error

Start initializes and starts the Inference client

func (*InferenceService) Stop

func (s *InferenceService) Stop()

Stop gracefully shuts down the Inference service

type JobService

type JobService struct {
	*gorm.DB
}

func NewJobService

func NewJobService() JobService

func (JobService) DeleteJobEntityByJobUuId

func (jobServ JobService) DeleteJobEntityByJobUuId(jobUuid string, jobStatus int) error

func (JobService) DeleteJobEntityBySpaceUuId

func (jobServ JobService) DeleteJobEntityBySpaceUuId(spaceUuid, jobUuid string, jobStatus int) error

func (JobService) GetJobEntityByJobUuid

func (jobServ JobService) GetJobEntityByJobUuid(jobUuid string) (models.JobEntity, error)

func (JobService) GetJobEntityBySpaceUuid

func (jobServ JobService) GetJobEntityBySpaceUuid(spaceUuid string) int64

func (JobService) GetJobEntityByTaskUuid

func (jobServ JobService) GetJobEntityByTaskUuid(taskUuid string) (models.JobEntity, error)

func (JobService) GetJobList

func (jobServ JobService) GetJobList(status int, tailNum int) (list []*models.JobEntity, err error)

func (JobService) GetJobListByNoRejectStatus

func (jobServ JobService) GetJobListByNoRejectStatus() (list []*models.JobEntity, err error)

func (JobService) GetJobListByNoReward

func (jobServ JobService) GetJobListByNoReward() (list []*models.JobEntity, err error)

func (JobService) SaveJobEntity

func (jobServ JobService) SaveJobEntity(job *models.JobEntity) (err error)

func (JobService) UpdateJobEntityByJobUuid

func (jobServ JobService) UpdateJobEntityByJobUuid(job *models.JobEntity) (err error)

func (JobService) UpdateJobEntityStatusByJobUuid

func (jobServ JobService) UpdateJobEntityStatusByJobUuid(jobUuid string, status int) (err error)

func (JobService) UpdateJobResultUrlByJobUuid

func (jobServ JobService) UpdateJobResultUrlByJobUuid(jobUuid string, resultUrl string) (err error)

func (JobService) UpdateJobReward

func (jobServ JobService) UpdateJobReward(taskUuid string, amount string) (err error)

func (JobService) UpdateJobScannedBlock

func (jobServ JobService) UpdateJobScannedBlock(taskUuid string, end uint64) (err error)

type Message

type Message struct {
	Type      MessageType     `json:"type"`
	RequestID string          `json:"request_id,omitempty"`
	Payload   json.RawMessage `json:"payload"`
}

Message is the base WebSocket message structure

type MessageType

type MessageType string

Inference WebSocket Protocol Types

const (
	MsgTypeRegister          MessageType = "register"
	MsgTypeInference         MessageType = "inference"
	MsgTypeVerify            MessageType = "verify"
	MsgTypeHeartbeat         MessageType = "heartbeat"
	MsgTypeAck               MessageType = "ack"
	MsgTypeError             MessageType = "error"
	MsgTypeStreamChunk       MessageType = "stream_chunk"        // Streaming chunk to Swan Inference
	MsgTypeStreamEnd         MessageType = "stream_end"          // End of stream marker
	MsgTypeWarmup            MessageType = "warmup"              // Model warmup request
	MsgTypeModelHealthUpdate MessageType = "model_health_update" // Model health status update
)

type MetricsHistory

type MetricsHistory struct {
	// contains filtered or unexported fields
}

MetricsHistory manages historical metrics storage and retrieval

func NewMetricsHistory

func NewMetricsHistory() *MetricsHistory

NewMetricsHistory creates a new MetricsHistory instance

func (*MetricsHistory) GetHistory

func (h *MetricsHistory) GetHistory(duration time.Duration, resolution time.Duration) ([]HistoricalDataPoint, error)

GetHistory retrieves historical metrics for the given duration with the specified resolution

func (*MetricsHistory) GetRecentDataPoints

func (h *MetricsHistory) GetRecentDataPoints(count int) ([]HistoricalDataPoint, error)

GetRecentDataPoints returns the most recent N data points (for quick access)

func (*MetricsHistory) Start

func (h *MetricsHistory) Start(metricsProvider func() *InferenceMetrics) error

Start begins the metrics recording goroutine

func (*MetricsHistory) Stop

func (h *MetricsHistory) Stop()

Stop stops the metrics recording goroutine

type MetricsHistoryEntity

type MetricsHistoryEntity struct {
	ID                uint      `gorm:"primaryKey;autoIncrement"`
	Timestamp         time.Time `gorm:"index;not null"`
	TotalRequests     int64     `json:"total_requests"`
	SuccessfulReqs    int64     `json:"successful_requests"`
	FailedReqs        int64     `json:"failed_requests"`
	SuccessRate       float64   `json:"success_rate"`
	AvgLatencyMs      float64   `json:"avg_latency_ms"`
	P50LatencyMs      float64   `json:"p50_latency_ms"`
	P95LatencyMs      float64   `json:"p95_latency_ms"`
	P99LatencyMs      float64   `json:"p99_latency_ms"`
	TokensPerSecond   float64   `json:"tokens_per_second"`
	RequestsPerMinute float64   `json:"requests_per_minute"`
	ActiveRequests    int64     `json:"active_requests"`
	TotalTokensIn     int64     `json:"total_tokens_in"`
	TotalTokensOut    int64     `json:"total_tokens_out"`
}

MetricsHistoryEntity represents a historical metrics data point in the database

func (MetricsHistoryEntity) TableName

func (MetricsHistoryEntity) TableName() string

type ModelError

type ModelError struct {
	Message string
}

func (*ModelError) Error

func (e *ModelError) Error() string

type ModelHealth

type ModelHealth int

ModelHealth represents the health state of a model endpoint

const (
	ModelHealthUnknown ModelHealth = iota
	ModelHealthHealthy
	ModelHealthDegraded
	ModelHealthUnhealthy
)

func (ModelHealth) String

func (h ModelHealth) String() string

type ModelHealthChecker

type ModelHealthChecker struct {
	// contains filtered or unexported fields
}

ModelHealthChecker performs periodic health checks on model endpoints

func NewModelHealthChecker

func NewModelHealthChecker(config HealthCheckConfig) *ModelHealthChecker

NewModelHealthChecker creates a new health checker

func (*ModelHealthChecker) ForceCheck

func (h *ModelHealthChecker) ForceCheck(modelID string)

ForceCheck triggers an immediate health check for a model

func (*ModelHealthChecker) GetAllStatuses

func (h *ModelHealthChecker) GetAllStatuses() map[string]*ModelStatus

GetAllStatuses returns health status of all models

func (*ModelHealthChecker) GetHealthyModels

func (h *ModelHealthChecker) GetHealthyModels() []string

GetHealthyModels returns list of healthy model IDs

func (*ModelHealthChecker) GetModelStatus

func (h *ModelHealthChecker) GetModelStatus(modelID string) (*ModelStatus, bool)

GetModelStatus returns the health status of a specific model

func (*ModelHealthChecker) GetStatusJSON

func (h *ModelHealthChecker) GetStatusJSON() ([]byte, error)

GetStatusJSON returns all statuses as JSON

func (*ModelHealthChecker) IsModelHealthy

func (h *ModelHealthChecker) IsModelHealthy(modelID string) bool

IsModelHealthy returns whether a specific model is healthy enough to serve requests

func (*ModelHealthChecker) RegisterModel

func (h *ModelHealthChecker) RegisterModel(modelID, endpoint, apiKey string)

RegisterModel adds a model to health checking

func (*ModelHealthChecker) SetStatusChangeCallback

func (h *ModelHealthChecker) SetStatusChangeCallback(cb func(modelID string, oldHealth, newHealth ModelHealth))

SetStatusChangeCallback sets a callback for health status changes

func (*ModelHealthChecker) Start

func (h *ModelHealthChecker) Start()

Start begins periodic health checking

func (*ModelHealthChecker) Stop

func (h *ModelHealthChecker) Stop()

Stop stops the health checker

func (*ModelHealthChecker) UnregisterModel

func (h *ModelHealthChecker) UnregisterModel(modelID string)

UnregisterModel removes a model from health checking

type ModelHealthUpdatePayload

type ModelHealthUpdatePayload struct {
	NodeID      string            `json:"node_id"`               // Local node ID (not the DB provider ID)
	ProviderID  string            `json:"provider_id,omitempty"` // Deprecated: use NodeID
	ModelHealth map[string]string `json:"model_health"`          // modelID -> health status ("healthy", "degraded", "unhealthy")
	Timestamp   int64             `json:"timestamp"`
}

ModelHealthUpdatePayload is sent to Swan Inference when model health changes

type ModelInfo

type ModelInfo struct {
	ModelID      string `json:"model_id"`
	WeightHash   string `json:"weight_hash,omitempty"`  // Composite SHA256 of all weight files
	HashAlgo     string `json:"hash_algo,omitempty"`    // Hash algorithm, e.g. "sha256"
	Format       string `json:"format,omitempty"`       // Weight format: "fp16", "fp8", "awq", "gptq", "gguf"
	Quantization string `json:"quantization,omitempty"` // Quantization detail: "q4_k_m", "q8_0", "w4a16", etc.
}

ModelInfo contains model identification and verification hash

type ModelMapping

type ModelMapping struct {
	Container    string `json:"container"`
	Endpoint     string `json:"endpoint"`
	GPUMemory    int    `json:"gpu_memory"`
	Category     string `json:"category"`
	LocalModel   string `json:"local_model"`            // Actual model name for local inference server (e.g., Ollama model name)
	Format       string `json:"format,omitempty"`       // Weight format: "fp16", "fp8", "awq", "gptq", "gguf"
	Quantization string `json:"quantization,omitempty"` // Quantization detail: "q4_k_m", "q8_0", "w4a16", etc.
	APIKey       string `json:"api_key,omitempty"`      // API key for authenticated model endpoints (e.g., vLLM --api-key)
}

ModelMapping represents a model-to-endpoint mapping from models.json

type ModelMetrics

type ModelMetrics struct {
	ModelName       string  `json:"model_name"`
	TotalRequests   int64   `json:"total_requests"`
	SuccessfulReqs  int64   `json:"successful_requests"`
	FailedReqs      int64   `json:"failed_requests"`
	AvgLatencyMs    float64 `json:"avg_latency_ms"`
	TotalTokensIn   int64   `json:"total_tokens_in"`
	TotalTokensOut  int64   `json:"total_tokens_out"`
	TokensPerSecond float64 `json:"tokens_per_second"`
	ActiveRequests  int64   `json:"active_requests"`
	// contains filtered or unexported fields
}

ModelMetrics tracks metrics for a specific model

type ModelRegistry

type ModelRegistry struct {
	// contains filtered or unexported fields
}

ModelRegistry manages the lifecycle of model configurations

func NewModelRegistry

func NewModelRegistry(configPath string, healthChecker *ModelHealthChecker) *ModelRegistry

NewModelRegistry creates a new model registry

func (*ModelRegistry) DisableModel

func (r *ModelRegistry) DisableModel(modelID string) error

DisableModel disables a model from serving

func (*ModelRegistry) EnableModel

func (r *ModelRegistry) EnableModel(modelID string) error

EnableModel enables a model for serving

func (*ModelRegistry) GetAllModelHealthMap

func (r *ModelRegistry) GetAllModelHealthMap() map[string]string

GetAllModelHealthMap returns a map of all model health statuses Returns modelID -> health status string ("healthy", "degraded", "unhealthy", "unknown")

func (*ModelRegistry) GetAllModels

func (r *ModelRegistry) GetAllModels() []*RegisteredModel

GetAllModels returns all registered models

func (*ModelRegistry) GetLocalModelName

func (r *ModelRegistry) GetLocalModelName(modelID string) string

GetLocalModelName returns the local model name for a model (e.g., Ollama model name) Returns empty string if not configured (use the model ID directly)

func (*ModelRegistry) GetModel

func (r *ModelRegistry) GetModel(modelID string) (*RegisteredModel, bool)

GetModel returns a registered model by ID

func (*ModelRegistry) GetModelAPIKey

func (r *ModelRegistry) GetModelAPIKey(modelID string) string

GetModelAPIKey returns the API key for a model endpoint Returns empty string if not configured

func (*ModelRegistry) GetModelEndpoint

func (r *ModelRegistry) GetModelEndpoint(modelID string) (string, bool)

GetModelEndpoint returns the endpoint for a model if it's ready

func (*ModelRegistry) GetModelMappings

func (r *ModelRegistry) GetModelMappings() map[string]ModelMapping

GetModelMappings returns model mappings in the original format (for compatibility)

func (*ModelRegistry) GetReadyModelIDs

func (r *ModelRegistry) GetReadyModelIDs() []string

GetReadyModelIDs returns IDs of models ready to serve requests

func (*ModelRegistry) GetReadyModels

func (r *ModelRegistry) GetReadyModels() []*RegisteredModel

GetReadyModels returns models that are ready to serve requests

func (*ModelRegistry) GetStatusSummary

func (r *ModelRegistry) GetStatusSummary() map[string]interface{}

GetStatusSummary returns a summary of model statuses

func (*ModelRegistry) ReloadConfig

func (r *ModelRegistry) ReloadConfig() error

ReloadConfig manually triggers a configuration reload

func (*ModelRegistry) SetCallbacks

func (r *ModelRegistry) SetCallbacks(
	onAdded func(model *RegisteredModel),
	onRemoved func(modelID string),
	onUpdated func(model *RegisteredModel),
)

SetCallbacks sets callbacks for model lifecycle events

func (*ModelRegistry) SetHealthUpdateCallback

func (r *ModelRegistry) SetHealthUpdateCallback(callback func(modelHealth map[string]string))

SetHealthUpdateCallback sets the callback for model health updates The callback receives a map of modelID -> health status ("healthy", "degraded", "unhealthy")

func (*ModelRegistry) Start

func (r *ModelRegistry) Start() error

Start loads initial configuration and begins watching for changes

func (*ModelRegistry) Stop

func (r *ModelRegistry) Stop()

Stop stops the registry and file watcher

type ModelServerError

type ModelServerError struct {
	StatusCode int    // HTTP status code from the model server
	Body       []byte // Raw response body
	Message    string // Parsed error message (from OpenAI error format or raw body)
}

ModelServerError represents a non-2xx HTTP response from the model server. It preserves the original status code and body so callers can propagate meaningful error codes (e.g. 400, 404, 429, 503) to Swan Inference.

func (*ModelServerError) Error

func (e *ModelServerError) Error() string

type ModelState

type ModelState int

ModelState represents the current state of a model

const (
	ModelStateUnknown ModelState = iota
	ModelStateLoading
	ModelStateReady
	ModelStateUnhealthy
	ModelStateDisabled
)

func (ModelState) String

func (s ModelState) String() string

type ModelStatus

type ModelStatus struct {
	ModelID          string      `json:"model_id"`
	Endpoint         string      `json:"endpoint"`
	Health           ModelHealth `json:"health"`
	HealthString     string      `json:"health_string"`
	LastCheck        time.Time   `json:"last_check"`
	LastSuccess      time.Time   `json:"last_success"`
	LastError        string      `json:"last_error,omitempty"`
	LatencyMs        float64     `json:"latency_ms"`
	AvgLatencyMs     float64     `json:"avg_latency_ms"`
	ConsecutiveFails int         `json:"consecutive_fails"`
	TotalChecks      int64       `json:"total_checks"`
	TotalSuccesses   int64       `json:"total_successes"`
	TotalFailures    int64       `json:"total_failures"`
	CircuitOpen      bool        `json:"circuit_open"`
}

ModelStatus tracks the health status of a single model

type PerModelRateLimiter

type PerModelRateLimiter struct {
	*RateLimiter
	// contains filtered or unexported fields
}

PerModelRateLimiter wraps RateLimiter for per-model rate limiting

func NewPerModelRateLimiter

func NewPerModelRateLimiter(config RateLimiterConfig, gpuCollector *GPUMetricsCollector, defaultRate float64, defaultBurst int) *PerModelRateLimiter

NewPerModelRateLimiter creates a rate limiter with per-model defaults

func (*PerModelRateLimiter) EnsureModelLimit

func (prl *PerModelRateLimiter) EnsureModelLimit(modelID string)

EnsureModelLimit creates a model rate limit if it doesn't exist

type ProviderStatusResponse

type ProviderStatusResponse struct {
	ProviderID      string   `json:"provider_id"`
	Name            string   `json:"name"`
	Status          string   `json:"status"`
	CanConnect      bool     `json:"can_connect"`
	APIKeyValid     bool     `json:"api_key_valid"`
	Message         string   `json:"message"`
	Warning         string   `json:"warning,omitempty"`
	NextSteps       []string `json:"next_steps,omitempty"`
	Step            int      `json:"step"`
	TotalSteps      int      `json:"total_steps"`
	StepLabel       string   `json:"step_label"`
	EarningsEnabled bool     `json:"earnings_enabled"`
}

ProviderStatusResponse represents the status check response from Swan Inference

type QueueConfig

type QueueConfig struct {
	MaxQueueSize     int           // Maximum total queue size
	MaxPerModelQueue int           // Maximum queue size per model
	DefaultTimeout   time.Duration // Default request timeout
	DrainTimeout     time.Duration // Timeout for draining on shutdown
	EnablePriority   bool          // Enable priority-based queuing
}

QueueConfig configures the request queue behavior

func DefaultQueueConfig

func DefaultQueueConfig() QueueConfig

DefaultQueueConfig returns sensible defaults

type QueueMetrics

type QueueMetrics struct {
	TotalEnqueued  int64            `json:"total_enqueued"`
	TotalDequeued  int64            `json:"total_dequeued"`
	TotalRejected  int64            `json:"total_rejected"`
	TotalTimedOut  int64            `json:"total_timed_out"`
	TotalCancelled int64            `json:"total_cancelled"`
	CurrentDepth   int64            `json:"current_depth"`
	AvgWaitTimeMs  float64          `json:"avg_wait_time_ms"`
	MaxWaitTimeMs  float64          `json:"max_wait_time_ms"`
	PerModelDepth  map[string]int64 `json:"per_model_depth"`
}

QueueMetrics tracks queue statistics

type QueueResult

type QueueResult struct {
	Response json.RawMessage
	Error    error
}

QueueResult contains the result of a queued request

type QueuedRequest

type QueuedRequest struct {
	ID          string
	ModelID     string
	Priority    RequestPriority
	Payload     json.RawMessage
	EnqueueTime time.Time
	Deadline    time.Time
	ResultChan  chan *QueueResult
	// contains filtered or unexported fields
}

QueuedRequest represents a request waiting in the queue

type RateLimiter

type RateLimiter struct {
	// contains filtered or unexported fields
}

RateLimiter provides rate limiting with optional adaptive adjustment

func NewRateLimiter

func NewRateLimiter(config RateLimiterConfig, gpuCollector *GPUMetricsCollector) *RateLimiter

NewRateLimiter creates a new rate limiter

func (*RateLimiter) Allow

func (rl *RateLimiter) Allow() bool

Allow checks if a global request is allowed

func (*RateLimiter) AllowModel

func (rl *RateLimiter) AllowModel(modelID string) bool

AllowModel checks if a request for a specific model is allowed

func (*RateLimiter) GetBackoffTime

func (rl *RateLimiter) GetBackoffTime() time.Duration

GetBackoffTime returns suggested wait time based on current state

func (*RateLimiter) GetMetrics

func (rl *RateLimiter) GetMetrics() RateLimiterMetrics

GetMetrics returns rate limiter metrics

func (*RateLimiter) GetModelMetrics

func (rl *RateLimiter) GetModelMetrics(modelID string) *RateLimiterMetrics

GetModelMetrics returns metrics for a specific model

func (*RateLimiter) RemoveModelLimit

func (rl *RateLimiter) RemoveModelLimit(modelID string)

RemoveModelLimit removes the rate limit for a model

func (*RateLimiter) SetModelLimit

func (rl *RateLimiter) SetModelLimit(modelID string, tokensPerSecond float64, burstSize int)

SetModelLimit sets a rate limit for a specific model

func (*RateLimiter) Start

func (rl *RateLimiter) Start()

Start begins the rate limiter (adaptive adjustment if enabled)

func (*RateLimiter) Stop

func (rl *RateLimiter) Stop()

Stop stops the rate limiter

func (*RateLimiter) WaitForToken

func (rl *RateLimiter) WaitForToken(modelID string, timeout time.Duration) error

WaitForToken blocks until a token is available or context is cancelled

type RateLimiterConfig

type RateLimiterConfig struct {
	// Token bucket settings
	TokensPerSecond float64 // Rate of token replenishment
	BurstSize       int     // Maximum burst capacity

	// Adaptive rate limiting
	EnableAdaptive     bool    // Enable GPU-aware rate limiting
	GPUThresholdHigh   float64 // GPU utilization above which to reduce rate
	GPUThresholdLow    float64 // GPU utilization below which to increase rate
	AdaptiveMinRate    float64 // Minimum tokens per second when adapting
	AdaptiveMaxRate    float64 // Maximum tokens per second when adapting
	AdaptiveAdjustment float64 // Rate adjustment factor per interval
}

RateLimiterConfig configures the rate limiter

func DefaultRateLimiterConfig

func DefaultRateLimiterConfig() RateLimiterConfig

DefaultRateLimiterConfig returns sensible defaults

type RateLimiterMetrics

type RateLimiterMetrics struct {
	TotalAllowed    int64   `json:"total_allowed"`
	TotalThrottled  int64   `json:"total_throttled"`
	CurrentRate     float64 `json:"current_rate"`
	CurrentTokens   float64 `json:"current_tokens"`
	BurstSize       int     `json:"burst_size"`
	AdaptiveEnabled bool    `json:"adaptive_enabled"`
}

RateLimiterMetrics tracks rate limiter statistics

type RegisterPayload

type RegisterPayload struct {
	NodeID       string        `json:"node_id"`               // Local node ID (not the DB provider ID)
	ProviderID   string        `json:"provider_id,omitempty"` // Deprecated: use NodeID
	NodeName     string        `json:"node_name,omitempty"`   // Human-readable provider name from config
	WorkerAddr   string        `json:"worker_addr"`
	OwnerAddr    string        `json:"owner_addr"`
	Token        string        `json:"token,omitempty"` // API key for authentication (sk-prov-*)
	Signature    string        `json:"signature,omitempty"`
	Models       []string      `json:"models"`
	ModelHashes  []ModelInfo   `json:"model_hashes,omitempty"` // Per-model composite hashes for verification
	Capabilities []string      `json:"capabilities"`
	Hardware     *HardwareInfo `json:"hardware,omitempty"`
}

RegisterPayload is sent by provider on connection

type RegisteredModel

type RegisteredModel struct {
	ID           string      `json:"id"`
	Container    string      `json:"container"`
	Endpoint     string      `json:"endpoint"`
	GPUMemory    int         `json:"gpu_memory"`
	Category     string      `json:"category"`
	LocalModel   string      `json:"local_model,omitempty"`  // Actual model name for local inference server
	Format       string      `json:"format,omitempty"`       // Weight format: fp16, awq, gptq, gguf, etc.
	Quantization string      `json:"quantization,omitempty"` // Quantization detail: q4_k_m, q8_0, w4a16, etc.
	APIKey       string      `json:"api_key,omitempty"`      // API key for authenticated model endpoints
	State        ModelState  `json:"state"`
	StateString  string      `json:"state_string"`
	Health       ModelHealth `json:"health"`
	HealthString string      `json:"health_string"`
	LoadedAt     time.Time   `json:"loaded_at,omitempty"`
	UpdatedAt    time.Time   `json:"updated_at"`
	Enabled      bool        `json:"enabled"`
}

RegisteredModel represents a fully configured model in the registry

type RequestMetric

type RequestMetric struct {
	RequestID   string    `json:"request_id"`
	Model       string    `json:"model"`
	StartTime   time.Time `json:"start_time"`
	EndTime     time.Time `json:"end_time,omitempty"`
	LatencyMs   float64   `json:"latency_ms"`
	TokensIn    int       `json:"tokens_in"`
	TokensOut   int       `json:"tokens_out"`
	Streaming   bool      `json:"streaming"`
	Success     bool      `json:"success"`
	ErrorReason string    `json:"error_reason,omitempty"`
}

RequestMetric represents a single request's metrics

type RequestPriority

type RequestPriority int

Priority levels for request queue

const (
	PriorityLow    RequestPriority = 0
	PriorityNormal RequestPriority = 1
	PriorityHigh   RequestPriority = 2
)

type RequestQueue

type RequestQueue struct {
	// contains filtered or unexported fields
}

RequestQueue manages incoming inference requests with priority and backpressure

func NewRequestQueue

func NewRequestQueue(config QueueConfig) *RequestQueue

NewRequestQueue creates a new request queue

func (*RequestQueue) Dequeue

func (q *RequestQueue) Dequeue() *QueuedRequest

Dequeue removes and returns the highest priority request

func (*RequestQueue) Enqueue

func (q *RequestQueue) Enqueue(req *QueuedRequest) error

Enqueue adds a request to the queue

func (*RequestQueue) EnqueueWithTimeout

func (q *RequestQueue) EnqueueWithTimeout(req *QueuedRequest, timeout time.Duration) (*QueueResult, error)

EnqueueWithTimeout enqueues a request and waits for the result

func (*RequestQueue) GetDepth

func (q *RequestQueue) GetDepth() int

GetDepth returns the current queue depth

func (*RequestQueue) GetMetrics

func (q *RequestQueue) GetMetrics() QueueMetrics

GetMetrics returns current queue metrics

func (*RequestQueue) GetModelDepth

func (q *RequestQueue) GetModelDepth(modelID string) int

GetModelDepth returns queue depth for a specific model

func (*RequestQueue) IsAccepting

func (q *RequestQueue) IsAccepting() bool

IsAccepting returns whether the queue can accept new requests

func (*RequestQueue) SetProcessFunc

func (q *RequestQueue) SetProcessFunc(f func(*QueuedRequest))

SetProcessFunc sets the function to process dequeued requests

func (*RequestQueue) Start

func (q *RequestQueue) Start()

Start begins the queue processor

func (*RequestQueue) Stop

func (q *RequestQueue) Stop()

Stop gracefully stops the queue, draining pending requests

type RestartableService

type RestartableService interface {
	Start() error
	Stop()
	IsHealthy() bool
	Name() string
}

RestartableService defines the interface for services that can be monitored and restarted

type ResultChecker

type ResultChecker interface {
	Check() error
}

type RetryConfig

type RetryConfig struct {
	MaxRetries         int           // Maximum number of retry attempts
	InitialDelay       time.Duration // Initial delay before first retry
	MaxDelay           time.Duration // Maximum delay between retries
	Multiplier         float64       // Delay multiplier for exponential backoff
	JitterFactor       float64       // Random jitter factor (0-1)
	RetryableErrors    []string      // Error substrings that are retryable
	NonRetryableErrors []string      // Error substrings that should not be retried
}

RetryConfig configures retry behavior

func DefaultRetryConfig

func DefaultRetryConfig() RetryConfig

DefaultRetryConfig returns sensible defaults

type RetryMetrics

type RetryMetrics struct {
	TotalAttempts        int64   `json:"total_attempts"`
	TotalRetries         int64   `json:"total_retries"`
	TotalSuccesses       int64   `json:"total_successes"`
	TotalFailures        int64   `json:"total_failures"`
	TotalNonRetryable    int64   `json:"total_non_retryable"`
	AvgRetriesPerRequest float64 `json:"avg_retries_per_request"`
	RetrySuccessRate     float64 `json:"retry_success_rate"`
}

RetryMetrics tracks retry statistics

type RetryPolicy

type RetryPolicy struct {
	// contains filtered or unexported fields
}

RetryPolicy implements retry logic with exponential backoff and jitter

func NewRetryPolicy

func NewRetryPolicy(config RetryConfig) *RetryPolicy

NewRetryPolicy creates a new retry policy

func (*RetryPolicy) CalculateDelay

func (rp *RetryPolicy) CalculateDelay(attempt int) time.Duration

CalculateDelay calculates the delay for a given attempt with jitter

func (*RetryPolicy) Execute

func (rp *RetryPolicy) Execute(ctx context.Context, operation func() error) error

Execute runs a function with retry logic

func (*RetryPolicy) ExecuteWithResult

func (rp *RetryPolicy) ExecuteWithResult(ctx context.Context, operation func() (interface{}, error)) error

ExecuteWithResult runs a function that returns a result with retry logic

func (*RetryPolicy) GetMetrics

func (rp *RetryPolicy) GetMetrics() RetryMetrics

GetMetrics returns retry metrics

func (*RetryPolicy) IsRetryable

func (rp *RetryPolicy) IsRetryable(err error) bool

IsRetryable determines if an error should be retried

type RetryableOperation

type RetryableOperation struct {
	// contains filtered or unexported fields
}

RetryableOperation wraps an operation with retry capability

func NewRetryableOperation

func NewRetryableOperation(policy *RetryPolicy, op func(ctx context.Context) error) *RetryableOperation

NewRetryableOperation creates a new retryable operation

func (*RetryableOperation) OnRetry

func (ro *RetryableOperation) OnRetry(callback func(attempt int, err error)) *RetryableOperation

OnRetry sets a callback for retry events

func (*RetryableOperation) Run

func (ro *RetryableOperation) Run(ctx context.Context) error

Run executes the operation with retries

type Semaphore

type Semaphore struct {
	// contains filtered or unexported fields
}

Semaphore implements a counting semaphore

func NewSemaphore

func NewSemaphore(max int) *Semaphore

NewSemaphore creates a new semaphore

func (*Semaphore) Acquire

func (s *Semaphore) Acquire(timeout time.Duration) bool

Acquire tries to acquire a slot, blocking until available or timeout

func (*Semaphore) GetStats

func (s *Semaphore) GetStats() (current, max int, acquired, released, rejected, timeouts int64, avgHoldTime float64)

GetStats returns current semaphore stats

func (*Semaphore) Release

func (s *Semaphore) Release(holdTime time.Duration)

Release releases a slot

func (*Semaphore) SetMax

func (s *Semaphore) SetMax(max int)

SetMax updates the maximum concurrent slots

func (*Semaphore) TryAcquire

func (s *Semaphore) TryAcquire() bool

TryAcquire attempts to acquire without blocking

type SendProofResp

type SendProofResp struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
	Data struct {
		BlockHash string `json:"block_hash"`
		Sign      string `json:"sign"`
	} `json:"data"`
}

type SequenceTask

type SequenceTask struct {
	Id                 int    `json:"id"`
	Uuid               string `json:"uuid"`
	Type               int    `json:"type"`
	InputParam         string `json:"input_param"`
	VerifyParam        string `json:"verify_param"`
	ResourceType       int    `json:"resource_type"`
	Deadline           int    `json:"deadline"`
	Proof              string `json:"proof"`
	CheckCode          string `json:"check_code"`
	Reward             string `json:"reward"`
	Status             string `json:"status"`
	SequenceCid        string `json:"sequence_cid"`
	SettlementCid      string `json:"settlement_cid"`
	SequenceTaskAddr   string `json:"sequence_task_addr"`
	SettlementTaskAddr string `json:"settlement_task_addr"`
}

type Sequencer

type Sequencer struct {
	// contains filtered or unexported fields
}

func NewSequencer

func NewSequencer() *Sequencer

func (*Sequencer) GetToken

func (s *Sequencer) GetToken() error

func (*Sequencer) QueryTask

func (s *Sequencer) QueryTask(taskType int, taskIds []int64, uuids []string) (TaskListResp, error)

func (*Sequencer) SendTaskProof

func (s *Sequencer) SendTaskProof(data []byte) (SendProofResp, error)

type ServiceState

type ServiceState struct {
	Name           string
	Healthy        bool
	RestartCount   int
	LastRestartAt  time.Time
	LastHealthyAt  time.Time
	CurrentBackoff time.Duration
}

ServiceState tracks the state of a supervised service

type StreamChunkPayload

type StreamChunkPayload struct {
	RequestID string          `json:"request_id"`
	Chunk     json.RawMessage `json:"chunk"` // OpenAI-compatible SSE chunk data
	Done      bool            `json:"done"`  // True when stream is complete
}

StreamChunkPayload represents a streaming chunk sent to Swan Inference

type StreamEndPayload

type StreamEndPayload struct {
	RequestID    string `json:"request_id"`
	Latency      int64  `json:"latency_ms"`
	TokensInput  int64  `json:"tokens_input,omitempty"`
	TokensOutput int64  `json:"tokens_output,omitempty"`
	StatusCode   int    `json:"status_code,omitempty"` // HTTP status code for error responses
	Error        string `json:"error,omitempty"`
}

StreamEndPayload signals end of stream with usage stats

type StreamResult

type StreamResult struct {
	TokensInput  int64
	TokensOutput int64
	Error        error
}

StreamResult contains the final result of a streaming inference including token usage

type StreamingInferenceHandler

type StreamingInferenceHandler func(requestID string, payload InferencePayload, sendChunk func(chunk []byte, done bool) error) *StreamResult

StreamingInferenceHandler handles streaming inference requests It receives a callback to send chunks back to Swan Inference and returns token usage

type Supervisor

type Supervisor struct {
	// contains filtered or unexported fields
}

Supervisor monitors and restarts services when they become unhealthy

func NewSupervisor

func NewSupervisor(config SupervisorConfig) *Supervisor

NewSupervisor creates a new service supervisor

func (*Supervisor) ForceRestart

func (s *Supervisor) ForceRestart(name string) error

ForceRestart forces a restart of a specific service

func (*Supervisor) GetServiceState

func (s *Supervisor) GetServiceState(name string) (ServiceState, bool)

GetServiceState returns the state of a specific service

func (*Supervisor) GetServiceStates

func (s *Supervisor) GetServiceStates() map[string]ServiceState

GetServiceStates returns the current state of all supervised services

func (*Supervisor) Register

func (s *Supervisor) Register(service RestartableService)

Register adds a service to be supervised

func (*Supervisor) Start

func (s *Supervisor) Start()

Start begins the supervisor monitoring loop

func (*Supervisor) Stop

func (s *Supervisor) Stop()

Stop stops the supervisor

func (*Supervisor) Unregister

func (s *Supervisor) Unregister(name string)

Unregister removes a service from supervision

type SupervisorConfig

type SupervisorConfig struct {
	HealthCheckInterval time.Duration // How often to check service health
	MaxRestartAttempts  int           // Maximum restart attempts before giving up (0 = unlimited)
	RestartBackoff      time.Duration // Initial backoff between restart attempts
	MaxRestartBackoff   time.Duration // Maximum backoff between restart attempts
}

SupervisorConfig configures the supervisor behavior

func DefaultSupervisorConfig

func DefaultSupervisorConfig() SupervisorConfig

DefaultSupervisorConfig returns sensible defaults

type SupervisorError

type SupervisorError struct {
	Message string
}

func (*SupervisorError) Error

func (e *SupervisorError) Error() string

type TaskGroup

type TaskGroup struct {
	Items []*models.TaskEntity
	Ids   []int64
	Uuids []string
	Type  int // 1: contract  2: sequncer 3: mining
}

type TaskListResp

type TaskListResp struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
	Data struct {
		Total int            `json:"total"`
		List  []SequenceTask `json:"list"`
	} `json:"data"`
}

type TaskPaymentService

type TaskPaymentService struct {
	// contains filtered or unexported fields
}

func NewTaskPaymentService

func NewTaskPaymentService() *TaskPaymentService

func (*TaskPaymentService) ScannerChainGetTaskPayment

func (tps *TaskPaymentService) ScannerChainGetTaskPayment()

type TaskService

type TaskService struct {
	*gorm.DB
}

func NewTaskService

func NewTaskService() TaskService

func (TaskService) GetTaskByUuid

func (taskServ TaskService) GetTaskByUuid(uuid string) (*models.TaskEntity, error)

func (TaskService) GetTaskEntity

func (taskServ TaskService) GetTaskEntity(taskId int64) (*models.TaskEntity, error)

func (TaskService) GetTaskList

func (taskServ TaskService) GetTaskList(tailNum int, taskStatus ...int) (list []*models.TaskEntity, err error)

func (TaskService) GetTaskListNoRewardForFilC2

func (taskServ TaskService) GetTaskListNoRewardForFilC2() (list []*models.TaskEntity, err error)

func (TaskService) GetTaskListNoRewardForMining

func (taskServ TaskService) GetTaskListNoRewardForMining() (list []*models.TaskEntity, err error)

func (TaskService) SaveTaskEntity

func (taskServ TaskService) SaveTaskEntity(task *models.TaskEntity) (err error)

func (TaskService) UpdateTaskEntityByTaskId

func (taskServ TaskService) UpdateTaskEntityByTaskId(task *models.TaskEntity) (err error)

func (TaskService) UpdateTaskEntityByTaskUuId

func (taskServ TaskService) UpdateTaskEntityByTaskUuId(task *models.TaskEntity) (err error)

func (TaskService) UpdateTaskStatusById

func (taskServ TaskService) UpdateTaskStatusById(taskId int, status int) (err error)

func (TaskService) UpdateTaskStatusByUuid

func (taskServ TaskService) UpdateTaskStatusByUuid(uuid string, status int) (err error)

type TaskStatus

type TaskStatus struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
	Data struct {
		Ended  bool   `json:"ended"`
		Status string `json:"status"`
	} `json:"data"`
}

type TokenBucket

type TokenBucket struct {
	// contains filtered or unexported fields
}

TokenBucket implements a token bucket rate limiter

func NewTokenBucket

func NewTokenBucket(tokensPerSecond float64, burstSize int) *TokenBucket

NewTokenBucket creates a new token bucket

func (*TokenBucket) Allow

func (tb *TokenBucket) Allow() bool

Allow checks if a request is allowed and consumes a token

func (*TokenBucket) AllowN

func (tb *TokenBucket) AllowN(n int) bool

AllowN checks if n requests are allowed and consumes n tokens

func (*TokenBucket) GetStats

func (tb *TokenBucket) GetStats() (tokens float64, rate float64, allowed, throttled int64)

GetStats returns current bucket stats

func (*TokenBucket) SetRate

func (tb *TokenBucket) SetRate(tokensPerSecond float64)

SetRate updates the token refill rate

type TokenResp

type TokenResp struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
	Data struct {
		Token string `json:"token"`
	} `json:"data"`
}

type VerifyPayload

type VerifyPayload struct {
	ChallengeID   string          `json:"challenge_id"`
	ChallengeType string          `json:"challenge_type"`
	ModelID       string          `json:"model_id"`
	Challenge     json.RawMessage `json:"challenge"`
}

VerifyPayload is sent to provider for model verification

type VerifyResponsePayload

type VerifyResponsePayload struct {
	ChallengeID string          `json:"challenge_id"`
	Success     bool            `json:"success"`
	Response    json.RawMessage `json:"response"`
	Error       string          `json:"error,omitempty"`
}

VerifyResponsePayload is returned after processing a verification challenge

type WarmupHandler

type WarmupHandler func(payload WarmupPayload) (*WarmupResponse, error)

WarmupHandler handles model warmup requests

type WarmupPayload

type WarmupPayload struct {
	ModelID    string `json:"model_id"`
	WarmupType string `json:"warmup_type"` // "load" or "inference"
}

WarmupPayload is sent from Swan Inference to pre-load a model

type WarmupResponse

type WarmupResponse struct {
	RequestID  string `json:"request_id"`
	ModelID    string `json:"model_id"`
	Success    bool   `json:"success"`
	LoadTimeMs int64  `json:"load_time_ms,omitempty"`
	MemoryMB   int64  `json:"memory_mb,omitempty"`
	Error      string `json:"error,omitempty"`
}

WarmupResponse is returned by provider after warmup

type WsClient

type WsClient struct {
	// contains filtered or unexported fields
}

func NewWsClient

func NewWsClient(client *websocket.Conn) *WsClient

func (*WsClient) Close

func (ws *WsClient) Close()

func (*WsClient) HandleLogs

func (ws *WsClient) HandleLogs(reader io.Reader)

type YamlStruct

type YamlStruct struct {
	Services struct {
		Image      string            `yaml:"image"`
		Cmd        []string          `yaml:"command"`
		ExposePort []int             `yaml:"expose"`
		Envs       map[string]string `yaml:"environment"`
	} `yaml:"services"`
}

YamlStruct represents the structure for YAML deployment content

Jump to

Keyboard shortcuts

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