aiwrapper
Version:
A Universal AI Wrapper for JavaScript & TypeScript
92 lines (91 loc) • 3.06 kB
JavaScript
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 { OpenAIChatCompletionsLang } from "./openai/openai-chat-completions-lang.js";
import { MockOpenAILikeLang } from "./mock/mock-openai-like-lang.js";
import { MockResponseStreamLang } from "./mock/mock-response-stream-lang.js";
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 OpenAIChatCompletionsLang.custom(options);
}
/** Create a Mock OpenAI-like provider (no network) */
static mockOpenAI(options = {}) {
return new MockOpenAILikeLang(options);
}
/** Create a lightweight streaming mock provider */
static mockResponseStream(options = {}) {
return new MockResponseStreamLang(options);
}
// Dynamic provider access
static [Symbol.iterator]() {
const providers = models.providers.reduce((acc, provider) => {
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]();
}
}
export {
Lang
};
//# sourceMappingURL=lang.js.map