@probeo/anymodel 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -650,7 +650,19 @@ function createOpenAIAdapter(apiKey, baseURL) {
650
650
  async listModels() {
651
651
  const res = await makeRequest("/models", void 0, "GET");
652
652
  const data = await res.json();
653
- return (data.data || []).filter((m) => m.id.startsWith("gpt-") || m.id.startsWith("o") || m.id.startsWith("chatgpt-")).map((m) => ({
653
+ return (data.data || []).filter((m) => {
654
+ const id = m.id;
655
+ if (id.includes("embedding")) return false;
656
+ if (id.includes("whisper")) return false;
657
+ if (id.includes("tts")) return false;
658
+ if (id.includes("dall-e")) return false;
659
+ if (id.includes("davinci")) return false;
660
+ if (id.includes("babbage")) return false;
661
+ if (id.includes("moderation")) return false;
662
+ if (id.includes("realtime")) return false;
663
+ if (id.startsWith("ft:")) return false;
664
+ return id.startsWith("gpt-") || id.startsWith("o1") || id.startsWith("o3") || id.startsWith("o4") || id.startsWith("chatgpt-");
665
+ }).map((m) => ({
654
666
  id: `openai/${m.id}`,
655
667
  name: m.id,
656
668
  created: m.created,
@@ -716,10 +728,16 @@ var SUPPORTED_PARAMS2 = /* @__PURE__ */ new Set([
716
728
  "tool_choice",
717
729
  "response_format"
718
730
  ]);
719
- var KNOWN_MODELS = [
720
- { id: "anthropic/claude-opus-4-6", name: "Claude Opus 4.6", created: 0, description: "Most capable model", context_length: 2e5, pricing: { prompt: "0.000005", completion: "0.000025" }, architecture: { modality: "text+image->text", input_modalities: ["text", "image"], output_modalities: ["text"], tokenizer: "claude" }, top_provider: { context_length: 2e5, max_completion_tokens: 32768, is_moderated: false }, supported_parameters: Array.from(SUPPORTED_PARAMS2) },
731
+ var FALLBACK_MODELS = [
732
+ // Claude 4.6
733
+ { id: "anthropic/claude-opus-4-6", name: "Claude Opus 4.6", created: 0, description: "Most capable model", context_length: 2e5, pricing: { prompt: "0.000015", completion: "0.000075" }, architecture: { modality: "text+image->text", input_modalities: ["text", "image"], output_modalities: ["text"], tokenizer: "claude" }, top_provider: { context_length: 2e5, max_completion_tokens: 32768, is_moderated: false }, supported_parameters: Array.from(SUPPORTED_PARAMS2) },
721
734
  { id: "anthropic/claude-sonnet-4-6", name: "Claude Sonnet 4.6", created: 0, description: "Best balance of speed and capability", context_length: 2e5, pricing: { prompt: "0.000003", completion: "0.000015" }, architecture: { modality: "text+image->text", input_modalities: ["text", "image"], output_modalities: ["text"], tokenizer: "claude" }, top_provider: { context_length: 2e5, max_completion_tokens: 16384, is_moderated: false }, supported_parameters: Array.from(SUPPORTED_PARAMS2) },
722
- { id: "anthropic/claude-haiku-4-5", name: "Claude Haiku 4.5", created: 0, description: "Fastest and most compact", context_length: 2e5, pricing: { prompt: "0.000001", completion: "0.000005" }, architecture: { modality: "text+image->text", input_modalities: ["text", "image"], output_modalities: ["text"], tokenizer: "claude" }, top_provider: { context_length: 2e5, max_completion_tokens: 8192, is_moderated: false }, supported_parameters: Array.from(SUPPORTED_PARAMS2) }
735
+ // Claude 4.5
736
+ { id: "anthropic/claude-sonnet-4-5-20251022", name: "Claude Sonnet 4.5", created: 0, description: "Previous generation balanced model", context_length: 2e5, pricing: { prompt: "0.000003", completion: "0.000015" }, architecture: { modality: "text+image->text", input_modalities: ["text", "image"], output_modalities: ["text"], tokenizer: "claude" }, top_provider: { context_length: 2e5, max_completion_tokens: 16384, is_moderated: false }, supported_parameters: Array.from(SUPPORTED_PARAMS2) },
737
+ { id: "anthropic/claude-haiku-4-5", name: "Claude Haiku 4.5", created: 0, description: "Fast and compact", context_length: 2e5, pricing: { prompt: "0.000001", completion: "0.000005" }, architecture: { modality: "text+image->text", input_modalities: ["text", "image"], output_modalities: ["text"], tokenizer: "claude" }, top_provider: { context_length: 2e5, max_completion_tokens: 8192, is_moderated: false }, supported_parameters: Array.from(SUPPORTED_PARAMS2) },
738
+ // Claude 3.5
739
+ { id: "anthropic/claude-3-5-sonnet-20241022", name: "Claude 3.5 Sonnet", created: 0, description: "Legacy balanced model", context_length: 2e5, pricing: { prompt: "0.000003", completion: "0.000015" }, architecture: { modality: "text+image->text", input_modalities: ["text", "image"], output_modalities: ["text"], tokenizer: "claude" }, top_provider: { context_length: 2e5, max_completion_tokens: 8192, is_moderated: false }, supported_parameters: Array.from(SUPPORTED_PARAMS2) },
740
+ { id: "anthropic/claude-3-5-haiku-20241022", name: "Claude 3.5 Haiku", created: 0, description: "Legacy fast model", context_length: 2e5, pricing: { prompt: "0.0000008", completion: "0.000004" }, architecture: { modality: "text+image->text", input_modalities: ["text", "image"], output_modalities: ["text"], tokenizer: "claude" }, top_provider: { context_length: 2e5, max_completion_tokens: 8192, is_moderated: false }, supported_parameters: Array.from(SUPPORTED_PARAMS2) }
723
741
  ];
724
742
  function createAnthropicAdapter(apiKey) {
725
743
  async function makeRequest(path, body, stream = false) {
@@ -979,7 +997,40 @@ ${body.system}` : jsonInstruction;
979
997
  };
980
998
  },
981
999
  async listModels() {
982
- return KNOWN_MODELS;
1000
+ try {
1001
+ const res = await fetch(`${ANTHROPIC_API_BASE}/models`, {
1002
+ method: "GET",
1003
+ headers: {
1004
+ "x-api-key": apiKey,
1005
+ "anthropic-version": ANTHROPIC_VERSION
1006
+ }
1007
+ });
1008
+ if (!res.ok) return FALLBACK_MODELS;
1009
+ const data = await res.json();
1010
+ const models = data.data || [];
1011
+ return models.filter((m) => m.type === "model").map((m) => ({
1012
+ id: `anthropic/${m.id}`,
1013
+ name: m.display_name || m.id,
1014
+ created: m.created_at ? new Date(m.created_at).getTime() / 1e3 : 0,
1015
+ description: m.display_name || "",
1016
+ context_length: 2e5,
1017
+ pricing: { prompt: "0", completion: "0" },
1018
+ architecture: {
1019
+ modality: "text+image->text",
1020
+ input_modalities: ["text", "image"],
1021
+ output_modalities: ["text"],
1022
+ tokenizer: "claude"
1023
+ },
1024
+ top_provider: {
1025
+ context_length: 2e5,
1026
+ max_completion_tokens: 16384,
1027
+ is_moderated: false
1028
+ },
1029
+ supported_parameters: Array.from(SUPPORTED_PARAMS2)
1030
+ }));
1031
+ } catch {
1032
+ return FALLBACK_MODELS;
1033
+ }
983
1034
  },
984
1035
  supportsParameter(param) {
985
1036
  return SUPPORTED_PARAMS2.has(param);
@@ -1017,9 +1068,16 @@ var SUPPORTED_PARAMS3 = /* @__PURE__ */ new Set([
1017
1068
  "tool_choice",
1018
1069
  "response_format"
1019
1070
  ]);
1020
- var KNOWN_MODELS2 = [
1071
+ var FALLBACK_MODELS2 = [
1072
+ // Gemini 2.5
1021
1073
  { id: "google/gemini-2.5-pro", name: "Gemini 2.5 Pro", created: 0, description: "Most capable Gemini model", context_length: 1048576, pricing: { prompt: "0.00000125", completion: "0.000005" }, architecture: { modality: "text+image->text", input_modalities: ["text", "image", "video", "audio"], output_modalities: ["text"], tokenizer: "gemini" }, top_provider: { context_length: 1048576, max_completion_tokens: 65536, is_moderated: false }, supported_parameters: Array.from(SUPPORTED_PARAMS3) },
1022
- { id: "google/gemini-2.5-flash", name: "Gemini 2.5 Flash", created: 0, description: "Fast and efficient", context_length: 1048576, pricing: { prompt: "0.00000015", completion: "0.0000006" }, architecture: { modality: "text+image->text", input_modalities: ["text", "image", "video", "audio"], output_modalities: ["text"], tokenizer: "gemini" }, top_provider: { context_length: 1048576, max_completion_tokens: 65536, is_moderated: false }, supported_parameters: Array.from(SUPPORTED_PARAMS3) }
1074
+ { id: "google/gemini-2.5-flash", name: "Gemini 2.5 Flash", created: 0, description: "Fast and efficient", context_length: 1048576, pricing: { prompt: "0.00000015", completion: "0.0000006" }, architecture: { modality: "text+image->text", input_modalities: ["text", "image", "video", "audio"], output_modalities: ["text"], tokenizer: "gemini" }, top_provider: { context_length: 1048576, max_completion_tokens: 65536, is_moderated: false }, supported_parameters: Array.from(SUPPORTED_PARAMS3) },
1075
+ // Gemini 2.0
1076
+ { id: "google/gemini-2.0-flash", name: "Gemini 2.0 Flash", created: 0, description: "Fast multimodal model", context_length: 1048576, pricing: { prompt: "0.0000001", completion: "0.0000004" }, architecture: { modality: "text+image->text", input_modalities: ["text", "image", "video", "audio"], output_modalities: ["text"], tokenizer: "gemini" }, top_provider: { context_length: 1048576, max_completion_tokens: 65536, is_moderated: false }, supported_parameters: Array.from(SUPPORTED_PARAMS3) },
1077
+ { id: "google/gemini-2.0-flash-lite", name: "Gemini 2.0 Flash Lite", created: 0, description: "Lightweight and fast", context_length: 1048576, pricing: { prompt: "0.00000005", completion: "0.0000002" }, architecture: { modality: "text+image->text", input_modalities: ["text", "image", "video", "audio"], output_modalities: ["text"], tokenizer: "gemini" }, top_provider: { context_length: 1048576, max_completion_tokens: 65536, is_moderated: false }, supported_parameters: Array.from(SUPPORTED_PARAMS3) },
1078
+ // Gemini 1.5
1079
+ { id: "google/gemini-1.5-pro", name: "Gemini 1.5 Pro", created: 0, description: "Previous generation pro model", context_length: 2097152, pricing: { prompt: "0.00000125", completion: "0.000005" }, architecture: { modality: "text+image->text", input_modalities: ["text", "image", "video", "audio"], output_modalities: ["text"], tokenizer: "gemini" }, top_provider: { context_length: 2097152, max_completion_tokens: 8192, is_moderated: false }, supported_parameters: Array.from(SUPPORTED_PARAMS3) },
1080
+ { id: "google/gemini-1.5-flash", name: "Gemini 1.5 Flash", created: 0, description: "Previous generation flash model", context_length: 1048576, pricing: { prompt: "0.000000075", completion: "0.0000003" }, architecture: { modality: "text+image->text", input_modalities: ["text", "image", "video", "audio"], output_modalities: ["text"], tokenizer: "gemini" }, top_provider: { context_length: 1048576, max_completion_tokens: 8192, is_moderated: false }, supported_parameters: Array.from(SUPPORTED_PARAMS3) }
1023
1081
  ];
1024
1082
  function createGoogleAdapter(apiKey) {
1025
1083
  function getModelEndpoint(model, stream) {
@@ -1221,7 +1279,37 @@ function createGoogleAdapter(apiKey) {
1221
1279
  };
1222
1280
  },
1223
1281
  async listModels() {
1224
- return KNOWN_MODELS2;
1282
+ try {
1283
+ const res = await fetch(`${GEMINI_API_BASE}/models?key=${apiKey}`);
1284
+ if (!res.ok) return FALLBACK_MODELS2;
1285
+ const data = await res.json();
1286
+ const models = data.models || [];
1287
+ return models.filter((m) => m.name?.startsWith("models/gemini-") && m.supportedGenerationMethods?.includes("generateContent")).map((m) => {
1288
+ const modelId = m.name.replace("models/", "");
1289
+ return {
1290
+ id: `google/${modelId}`,
1291
+ name: m.displayName || modelId,
1292
+ created: 0,
1293
+ description: m.description || "",
1294
+ context_length: m.inputTokenLimit || 1048576,
1295
+ pricing: { prompt: "0", completion: "0" },
1296
+ architecture: {
1297
+ modality: "text+image->text",
1298
+ input_modalities: ["text", "image", "video", "audio"],
1299
+ output_modalities: ["text"],
1300
+ tokenizer: "gemini"
1301
+ },
1302
+ top_provider: {
1303
+ context_length: m.inputTokenLimit || 1048576,
1304
+ max_completion_tokens: m.outputTokenLimit || 65536,
1305
+ is_moderated: false
1306
+ },
1307
+ supported_parameters: Array.from(SUPPORTED_PARAMS3)
1308
+ };
1309
+ });
1310
+ } catch {
1311
+ return FALLBACK_MODELS2;
1312
+ }
1225
1313
  },
1226
1314
  supportsParameter(param) {
1227
1315
  return SUPPORTED_PARAMS3.has(param);
@@ -1385,14 +1473,22 @@ function deepMerge(target, source) {
1385
1473
  }
1386
1474
  function envConfig() {
1387
1475
  const config = {};
1388
- if (process.env.ANTHROPIC_API_KEY) {
1389
- config.anthropic = { apiKey: process.env.ANTHROPIC_API_KEY };
1390
- }
1391
- if (process.env.OPENAI_API_KEY) {
1392
- config.openai = { apiKey: process.env.OPENAI_API_KEY };
1393
- }
1394
- if (process.env.GOOGLE_API_KEY) {
1395
- config.google = { apiKey: process.env.GOOGLE_API_KEY };
1476
+ const envMap = [
1477
+ ["openai", "OPENAI_API_KEY"],
1478
+ ["anthropic", "ANTHROPIC_API_KEY"],
1479
+ ["google", "GOOGLE_API_KEY"],
1480
+ ["mistral", "MISTRAL_API_KEY"],
1481
+ ["groq", "GROQ_API_KEY"],
1482
+ ["deepseek", "DEEPSEEK_API_KEY"],
1483
+ ["xai", "XAI_API_KEY"],
1484
+ ["together", "TOGETHER_API_KEY"],
1485
+ ["fireworks", "FIREWORKS_API_KEY"],
1486
+ ["perplexity", "PERPLEXITY_API_KEY"]
1487
+ ];
1488
+ for (const [key, envVar] of envMap) {
1489
+ if (process.env[envVar]) {
1490
+ config[key] = { apiKey: process.env[envVar] };
1491
+ }
1396
1492
  }
1397
1493
  return config;
1398
1494
  }
@@ -1807,21 +1903,42 @@ var AnyModel = class {
1807
1903
  };
1808
1904
  }
1809
1905
  registerProviders() {
1810
- const { anthropic, openai, google } = this.config;
1811
- const anthropicKey = anthropic?.apiKey || process.env.ANTHROPIC_API_KEY;
1812
- const openaiKey = openai?.apiKey || process.env.OPENAI_API_KEY;
1813
- const googleKey = google?.apiKey || process.env.GOOGLE_API_KEY;
1906
+ const config = this.config;
1907
+ const openaiKey = config.openai?.apiKey || process.env.OPENAI_API_KEY;
1814
1908
  if (openaiKey) {
1815
1909
  this.registry.register("openai", createOpenAIAdapter(openaiKey));
1816
1910
  }
1911
+ const anthropicKey = config.anthropic?.apiKey || process.env.ANTHROPIC_API_KEY;
1817
1912
  if (anthropicKey) {
1818
1913
  this.registry.register("anthropic", createAnthropicAdapter(anthropicKey));
1819
1914
  }
1915
+ const googleKey = config.google?.apiKey || process.env.GOOGLE_API_KEY;
1820
1916
  if (googleKey) {
1821
1917
  this.registry.register("google", createGoogleAdapter(googleKey));
1822
1918
  }
1823
- if (this.config.custom) {
1824
- for (const [name, customConfig] of Object.entries(this.config.custom)) {
1919
+ const builtinProviders = [
1920
+ { name: "mistral", baseURL: "https://api.mistral.ai/v1", configKey: "mistral", envVar: "MISTRAL_API_KEY" },
1921
+ { name: "groq", baseURL: "https://api.groq.com/openai/v1", configKey: "groq", envVar: "GROQ_API_KEY" },
1922
+ { name: "deepseek", baseURL: "https://api.deepseek.com", configKey: "deepseek", envVar: "DEEPSEEK_API_KEY" },
1923
+ { name: "xai", baseURL: "https://api.x.ai/v1", configKey: "xai", envVar: "XAI_API_KEY" },
1924
+ { name: "together", baseURL: "https://api.together.xyz/v1", configKey: "together", envVar: "TOGETHER_API_KEY" },
1925
+ { name: "fireworks", baseURL: "https://api.fireworks.ai/inference/v1", configKey: "fireworks", envVar: "FIREWORKS_API_KEY" },
1926
+ { name: "perplexity", baseURL: "https://api.perplexity.ai", configKey: "perplexity", envVar: "PERPLEXITY_API_KEY" }
1927
+ ];
1928
+ for (const { name, baseURL, configKey, envVar } of builtinProviders) {
1929
+ const providerConfig = config[configKey];
1930
+ const key = providerConfig?.apiKey || process.env[envVar];
1931
+ if (key) {
1932
+ this.registry.register(name, createCustomAdapter(name, { baseURL, apiKey: key }));
1933
+ }
1934
+ }
1935
+ const ollamaConfig = config.ollama;
1936
+ const ollamaURL = ollamaConfig?.baseURL || process.env.OLLAMA_BASE_URL || "http://localhost:11434/v1";
1937
+ if (ollamaConfig || process.env.OLLAMA_BASE_URL) {
1938
+ this.registry.register("ollama", createCustomAdapter("ollama", { baseURL: ollamaURL }));
1939
+ }
1940
+ if (config.custom) {
1941
+ for (const [name, customConfig] of Object.entries(config.custom)) {
1825
1942
  this.registry.register(name, createCustomAdapter(name, customConfig));
1826
1943
  }
1827
1944
  }