UNPKG

aiwrapper

Version:

A Universal AI Wrapper for JavaScript & TypeScript

82 lines 2.93 kB
import { models } from 'aimodels'; import { OpenAILang } from "./openai/openai-lang.js"; import { AnthropicLang } from "./anthropic/anthropic-lang.js"; import { OllamaLang } from "./ollama/ollama-lang.js"; import { GroqLang } from "./groq/groq-lang.js"; import { DeepSeekLang } from "./deepseek/deepseek-lang.js"; import { XAILang } from "./xai/xai-lang.js"; import { GoogleLang } from "./google/google-lang.js"; import { CohereLang } from "./cohere/cohere-lang.js"; import { OpenRouterLang } from "./openrouter/openrouter-lang.js"; import { MistralLang } from "./mistral/mistral-lang.js"; import { OpenAILikeLang } from "./openai-like/openai-like-lang.js"; /** * Lang is a factory class for using language models from different providers. */ export class Lang { /** Get all language models */ static get models() { return models.can("chat"); } /** Create an OpenAI provider instance */ static openai(options) { return new OpenAILang(options); } /** Create an Anthropic provider instance */ static anthropic(options) { return new AnthropicLang(options); } /** Create an Ollama provider instance */ static ollama(options) { return new OllamaLang(options); } /** Create a Groq provider instance */ static groq(options) { return new GroqLang(options); } /** Create a DeepSeek provider instance */ static deepseek(options) { return new DeepSeekLang(options); } /** Create an xAI provider instance */ static xai(options) { return new XAILang(options); } /** Create a Google provider instance */ static google(options) { return new GoogleLang(options); } /** Create a Cohere provider instance */ static cohere(options) { return new CohereLang(options); } /** Create an OpenRouter provider instance */ static openrouter(options) { return new OpenRouterLang(options); } /** Create a Mistral provider instance */ static mistral(options) { return new MistralLang(options); } /** * Creates an instance for custom OpenAI-compatible APIs * @param options Configuration options for the custom API * @returns A new OpenAILikeLang instance */ static openaiLike(options) { return OpenAILikeLang.custom(options); } // Dynamic provider access static [Symbol.iterator]() { const providers = models.providers.reduce((acc, provider) => { // Handle provider as object with id property (new aimodels behavior) const providerId = typeof provider === 'object' && provider !== null ? provider.id : provider; if (providerId in this) { acc[providerId] = this[providerId]; } return acc; }, {}); return Object.values(providers)[Symbol.iterator](); } } //# sourceMappingURL=lang.js.map