@synthart/synthlite
Version:
A fast, lightweight Gen AI powered synthetic data generator written in TypeScript. 🌞
60 lines (59 loc) • 1.79 kB
JavaScript
;
/**
*
* @file ai.ts
* @description 🚀 AI is a singleton class that handles interactions with different AI models.
* @date January 2024
* @version 1.0.0
* @license Affero General Public License v3.0
* ✨ "Move fast, break things." — Meta Platforms, Inc.
*
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.AI = void 0;
const anthropic_1 = require("@ai-sdk/anthropic");
const constants_1 = require("./constants");
const openai_1 = require("@ai-sdk/openai");
/**
* AI: Singleton class to handle interactions with different AI models.
* @class AI
*/
class AI {
/**
* Private constructor to prevent direct instantiation.
* @param {string} provider - The AI provider to use.
*/
constructor(provider = constants_1.Constants.DEFAULT_AI_PROVIDER) {
if (provider === "anthropic") {
this.model = (0, anthropic_1.anthropic)(constants_1.Constants.DEFAULT_ANTHROPIC_AI_MODEL);
}
else if (provider === "meta") {
const groq = (0, openai_1.createOpenAI)({
baseURL: constants_1.Constants.GROQ_BASE_URL,
apiKey: process.env.GROQ_API_KEY,
});
this.model = groq(constants_1.Constants.DEFAULT_AI_MODEL);
}
else {
throw new Error("Invalid provider specified!");
}
}
/**
* Returns the singleton instance of AI.
* @returns {AI} - The singleton instance.
*/
static getInstance() {
if (!this.instance) {
this.instance = new AI();
}
return this.instance;
}
/**
* Returns the current AI model.
* @returns {LanguageModel} - The current AI model.
*/
getModel() {
return this.model;
}
}
exports.AI = AI;