UNPKG

deepinfra

Version:
31 lines (30 loc) 1.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BaseModel = void 0; const clients_1 = require("../../../clients"); const client_1 = require("../../../lib/constants/client"); const url_1 = require("../../../lib/utils/url"); class BaseModel { modelName; client; endpoint; authToken; constructor(modelName, authToken, config) { this.modelName = modelName; this.endpoint = url_1.URLUtils.isValidUrl(modelName) ? modelName : client_1.ROOT_URL + modelName; this.authToken = authToken || this.getAuthTokenFromEnv() || this.warnAboutMissingApiKey(); this.client = new clients_1.DeepInfraClient(this.endpoint, this.authToken, config); } warnAboutMissingApiKey() { console.warn("API key is not provided. Please provide an API key as an argument or set DEEPINFRA_API_KEY environment variable."); return ""; } getAuthTokenFromEnv() { const apiKey = process.env.DEEPINFRA_API_KEY; return apiKey || ""; } } exports.BaseModel = BaseModel;