@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/cli.js CHANGED
@@ -622,7 +622,19 @@ function createOpenAIAdapter(apiKey, baseURL) {
622
622
  async listModels() {
623
623
  const res = await makeRequest("/models", void 0, "GET");
624
624
  const data = await res.json();
625
- return (data.data || []).filter((m) => m.id.startsWith("gpt-") || m.id.startsWith("o") || m.id.startsWith("chatgpt-")).map((m) => ({
625
+ return (data.data || []).filter((m) => {
626
+ const id = m.id;
627
+ if (id.includes("embedding")) return false;
628
+ if (id.includes("whisper")) return false;
629
+ if (id.includes("tts")) return false;
630
+ if (id.includes("dall-e")) return false;
631
+ if (id.includes("davinci")) return false;
632
+ if (id.includes("babbage")) return false;
633
+ if (id.includes("moderation")) return false;
634
+ if (id.includes("realtime")) return false;
635
+ if (id.startsWith("ft:")) return false;
636
+ return id.startsWith("gpt-") || id.startsWith("o1") || id.startsWith("o3") || id.startsWith("o4") || id.startsWith("chatgpt-");
637
+ }).map((m) => ({
626
638
  id: `openai/${m.id}`,
627
639
  name: m.id,
628
640
  created: m.created,
@@ -688,10 +700,16 @@ var SUPPORTED_PARAMS2 = /* @__PURE__ */ new Set([
688
700
  "tool_choice",
689
701
  "response_format"
690
702
  ]);
691
- var KNOWN_MODELS = [
692
- { 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) },
703
+ var FALLBACK_MODELS = [
704
+ // Claude 4.6
705
+ { 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) },
693
706
  { 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) },
694
- { 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) }
707
+ // Claude 4.5
708
+ { 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) },
709
+ { 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) },
710
+ // Claude 3.5
711
+ { 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) },
712
+ { 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) }
695
713
  ];
696
714
  function createAnthropicAdapter(apiKey) {
697
715
  async function makeRequest(path, body, stream = false) {
@@ -951,7 +969,40 @@ ${body.system}` : jsonInstruction;
951
969
  };
952
970
  },
953
971
  async listModels() {
954
- return KNOWN_MODELS;
972
+ try {
973
+ const res = await fetch(`${ANTHROPIC_API_BASE}/models`, {
974
+ method: "GET",
975
+ headers: {
976
+ "x-api-key": apiKey,
977
+ "anthropic-version": ANTHROPIC_VERSION
978
+ }
979
+ });
980
+ if (!res.ok) return FALLBACK_MODELS;
981
+ const data = await res.json();
982
+ const models = data.data || [];
983
+ return models.filter((m) => m.type === "model").map((m) => ({
984
+ id: `anthropic/${m.id}`,
985
+ name: m.display_name || m.id,
986
+ created: m.created_at ? new Date(m.created_at).getTime() / 1e3 : 0,
987
+ description: m.display_name || "",
988
+ context_length: 2e5,
989
+ pricing: { prompt: "0", completion: "0" },
990
+ architecture: {
991
+ modality: "text+image->text",
992
+ input_modalities: ["text", "image"],
993
+ output_modalities: ["text"],
994
+ tokenizer: "claude"
995
+ },
996
+ top_provider: {
997
+ context_length: 2e5,
998
+ max_completion_tokens: 16384,
999
+ is_moderated: false
1000
+ },
1001
+ supported_parameters: Array.from(SUPPORTED_PARAMS2)
1002
+ }));
1003
+ } catch {
1004
+ return FALLBACK_MODELS;
1005
+ }
955
1006
  },
956
1007
  supportsParameter(param) {
957
1008
  return SUPPORTED_PARAMS2.has(param);
@@ -989,9 +1040,16 @@ var SUPPORTED_PARAMS3 = /* @__PURE__ */ new Set([
989
1040
  "tool_choice",
990
1041
  "response_format"
991
1042
  ]);
992
- var KNOWN_MODELS2 = [
1043
+ var FALLBACK_MODELS2 = [
1044
+ // Gemini 2.5
993
1045
  { 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) },
994
- { 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) }
1046
+ { 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) },
1047
+ // Gemini 2.0
1048
+ { 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) },
1049
+ { 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) },
1050
+ // Gemini 1.5
1051
+ { 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) },
1052
+ { 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) }
995
1053
  ];
996
1054
  function createGoogleAdapter(apiKey) {
997
1055
  function getModelEndpoint(model, stream) {
@@ -1193,7 +1251,37 @@ function createGoogleAdapter(apiKey) {
1193
1251
  };
1194
1252
  },
1195
1253
  async listModels() {
1196
- return KNOWN_MODELS2;
1254
+ try {
1255
+ const res = await fetch(`${GEMINI_API_BASE}/models?key=${apiKey}`);
1256
+ if (!res.ok) return FALLBACK_MODELS2;
1257
+ const data = await res.json();
1258
+ const models = data.models || [];
1259
+ return models.filter((m) => m.name?.startsWith("models/gemini-") && m.supportedGenerationMethods?.includes("generateContent")).map((m) => {
1260
+ const modelId = m.name.replace("models/", "");
1261
+ return {
1262
+ id: `google/${modelId}`,
1263
+ name: m.displayName || modelId,
1264
+ created: 0,
1265
+ description: m.description || "",
1266
+ context_length: m.inputTokenLimit || 1048576,
1267
+ pricing: { prompt: "0", completion: "0" },
1268
+ architecture: {
1269
+ modality: "text+image->text",
1270
+ input_modalities: ["text", "image", "video", "audio"],
1271
+ output_modalities: ["text"],
1272
+ tokenizer: "gemini"
1273
+ },
1274
+ top_provider: {
1275
+ context_length: m.inputTokenLimit || 1048576,
1276
+ max_completion_tokens: m.outputTokenLimit || 65536,
1277
+ is_moderated: false
1278
+ },
1279
+ supported_parameters: Array.from(SUPPORTED_PARAMS3)
1280
+ };
1281
+ });
1282
+ } catch {
1283
+ return FALLBACK_MODELS2;
1284
+ }
1197
1285
  },
1198
1286
  supportsParameter(param) {
1199
1287
  return SUPPORTED_PARAMS3.has(param);
@@ -1357,14 +1445,22 @@ function deepMerge(target, source) {
1357
1445
  }
1358
1446
  function envConfig() {
1359
1447
  const config = {};
1360
- if (process.env.ANTHROPIC_API_KEY) {
1361
- config.anthropic = { apiKey: process.env.ANTHROPIC_API_KEY };
1362
- }
1363
- if (process.env.OPENAI_API_KEY) {
1364
- config.openai = { apiKey: process.env.OPENAI_API_KEY };
1365
- }
1366
- if (process.env.GOOGLE_API_KEY) {
1367
- config.google = { apiKey: process.env.GOOGLE_API_KEY };
1448
+ const envMap = [
1449
+ ["openai", "OPENAI_API_KEY"],
1450
+ ["anthropic", "ANTHROPIC_API_KEY"],
1451
+ ["google", "GOOGLE_API_KEY"],
1452
+ ["mistral", "MISTRAL_API_KEY"],
1453
+ ["groq", "GROQ_API_KEY"],
1454
+ ["deepseek", "DEEPSEEK_API_KEY"],
1455
+ ["xai", "XAI_API_KEY"],
1456
+ ["together", "TOGETHER_API_KEY"],
1457
+ ["fireworks", "FIREWORKS_API_KEY"],
1458
+ ["perplexity", "PERPLEXITY_API_KEY"]
1459
+ ];
1460
+ for (const [key, envVar] of envMap) {
1461
+ if (process.env[envVar]) {
1462
+ config[key] = { apiKey: process.env[envVar] };
1463
+ }
1368
1464
  }
1369
1465
  return config;
1370
1466
  }
@@ -1779,21 +1875,42 @@ var AnyModel = class {
1779
1875
  };
1780
1876
  }
1781
1877
  registerProviders() {
1782
- const { anthropic, openai, google } = this.config;
1783
- const anthropicKey = anthropic?.apiKey || process.env.ANTHROPIC_API_KEY;
1784
- const openaiKey = openai?.apiKey || process.env.OPENAI_API_KEY;
1785
- const googleKey = google?.apiKey || process.env.GOOGLE_API_KEY;
1878
+ const config = this.config;
1879
+ const openaiKey = config.openai?.apiKey || process.env.OPENAI_API_KEY;
1786
1880
  if (openaiKey) {
1787
1881
  this.registry.register("openai", createOpenAIAdapter(openaiKey));
1788
1882
  }
1883
+ const anthropicKey = config.anthropic?.apiKey || process.env.ANTHROPIC_API_KEY;
1789
1884
  if (anthropicKey) {
1790
1885
  this.registry.register("anthropic", createAnthropicAdapter(anthropicKey));
1791
1886
  }
1887
+ const googleKey = config.google?.apiKey || process.env.GOOGLE_API_KEY;
1792
1888
  if (googleKey) {
1793
1889
  this.registry.register("google", createGoogleAdapter(googleKey));
1794
1890
  }
1795
- if (this.config.custom) {
1796
- for (const [name, customConfig] of Object.entries(this.config.custom)) {
1891
+ const builtinProviders = [
1892
+ { name: "mistral", baseURL: "https://api.mistral.ai/v1", configKey: "mistral", envVar: "MISTRAL_API_KEY" },
1893
+ { name: "groq", baseURL: "https://api.groq.com/openai/v1", configKey: "groq", envVar: "GROQ_API_KEY" },
1894
+ { name: "deepseek", baseURL: "https://api.deepseek.com", configKey: "deepseek", envVar: "DEEPSEEK_API_KEY" },
1895
+ { name: "xai", baseURL: "https://api.x.ai/v1", configKey: "xai", envVar: "XAI_API_KEY" },
1896
+ { name: "together", baseURL: "https://api.together.xyz/v1", configKey: "together", envVar: "TOGETHER_API_KEY" },
1897
+ { name: "fireworks", baseURL: "https://api.fireworks.ai/inference/v1", configKey: "fireworks", envVar: "FIREWORKS_API_KEY" },
1898
+ { name: "perplexity", baseURL: "https://api.perplexity.ai", configKey: "perplexity", envVar: "PERPLEXITY_API_KEY" }
1899
+ ];
1900
+ for (const { name, baseURL, configKey, envVar } of builtinProviders) {
1901
+ const providerConfig = config[configKey];
1902
+ const key = providerConfig?.apiKey || process.env[envVar];
1903
+ if (key) {
1904
+ this.registry.register(name, createCustomAdapter(name, { baseURL, apiKey: key }));
1905
+ }
1906
+ }
1907
+ const ollamaConfig = config.ollama;
1908
+ const ollamaURL = ollamaConfig?.baseURL || process.env.OLLAMA_BASE_URL || "http://localhost:11434/v1";
1909
+ if (ollamaConfig || process.env.OLLAMA_BASE_URL) {
1910
+ this.registry.register("ollama", createCustomAdapter("ollama", { baseURL: ollamaURL }));
1911
+ }
1912
+ if (config.custom) {
1913
+ for (const [name, customConfig] of Object.entries(config.custom)) {
1797
1914
  this.registry.register(name, createCustomAdapter(name, customConfig));
1798
1915
  }
1799
1916
  }