UNPKG

sesterce-cli

Version:

A powerful command-line interface tool for managing Sesterce Cloud services. Sesterce CLI provides easy access to GPU cloud instances, AI inference services, container registries, and SSH key management directly from your terminal.

89 lines (84 loc) 2.56 kB
import { UseCase } from "@/core/domain/use-case"; import { Either, left, right } from "@/core/logic/either"; import { ApiClientProvider } from "@/providers/api-client-provider"; import { InferenceInstance } from "../../domain/inference-instance"; import { LaunchInferenceInstanceError } from "./errors/launch-instance-error"; import { LaunchInferenceInstanceDto } from "./launch-instance-dto"; export class LaunchInferenceInstance implements UseCase< LaunchInferenceInstanceDto, InferenceInstance, LaunchInferenceInstanceError > { constructor(private readonly apiClient: ApiClientProvider) {} async execute({ hardwareName, regionsIds, minContainers, maxContainers, cooldownPeriod, triggers, envs, startupCommand, modelId, registryId, containerPort, name, timeout, }: LaunchInferenceInstanceDto): Promise< Either<LaunchInferenceInstanceError, InferenceInstance> > { try { const instance = await this.apiClient.post<InferenceInstance>( "/ai-inference/instances", { body: JSON.stringify({ modelId, registryId, containerPort, name, autoScalingConfigurations: regionsIds.map((regionId) => ({ regionId, scale: { min: minContainers, max: maxContainers, cooldownPeriod, triggers: { cpu: triggers?.cpu ? { threshold: triggers.cpu } : null, gpuUtilization: triggers?.gpuUtilization ? { threshold: triggers.gpuUtilization } : null, gpuMemory: triggers?.gpuMemory ? { threshold: triggers.gpuMemory } : null, memory: triggers?.memory ? { threshold: triggers.memory } : null, http: triggers?.http ? { rate: triggers.http } : null, }, }, })), podLifetime: timeout, envs, hardwareName, startupCommand, }), } ); if (!instance) { return left( new LaunchInferenceInstanceError("Failed to create instance") ); } return right(instance); } catch (error) { return left( new LaunchInferenceInstanceError( error instanceof Error ? error.message : "Unexpected error occurred." ) ); } } }