@llumiverse/common
Version:
Public types, enums and options used by Llumiverse API.
115 lines • 5.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getModelCapabilities = getModelCapabilities;
exports.supportsToolUse = supportsToolUse;
exports.modelModalitiesToArray = modelModalitiesToArray;
const anthropic_js_1 = require("./capability/anthropic.js");
const azure_foundry_js_1 = require("./capability/azure_foundry.js");
const bedrock_js_1 = require("./capability/bedrock.js");
const openai_js_1 = require("./capability/openai.js");
const vertexai_js_1 = require("./capability/vertexai.js");
const types_js_1 = require("./types.js");
function getModelCapabilities(model, provider) {
//Check for locations/<location>/ prefix and remove it
if (model.startsWith("locations/")) {
const parts = model.split("/");
if (parts.length >= 3) {
model = parts.slice(2).join("/");
}
}
const capabilities = _getModelCapabilities(model, provider);
// Globally disable audio and video for all models, as we don't support them yet
// TODO: Remove this when we add support.
capabilities.input.audio = false;
capabilities.output.audio = false;
capabilities.output.video = false;
// Preserve tool_support_streaming from provider-specific capabilities if set,
// otherwise default to false for providers that haven't been verified
return capabilities;
}
function _getModelCapabilities(model, provider) {
switch (provider?.toLowerCase()) {
case types_js_1.Providers.anthropic:
return (0, anthropic_js_1.getModelCapabilitiesAnthropic)(model);
case types_js_1.Providers.vertexai:
return (0, vertexai_js_1.getModelCapabilitiesVertexAI)(model);
case types_js_1.Providers.openai:
return (0, openai_js_1.getModelCapabilitiesOpenAI)(model);
case types_js_1.Providers.openai_compatible:
return getModelCapabilitiesOpenAICompatible(model);
case types_js_1.Providers.bedrock:
return (0, bedrock_js_1.getModelCapabilitiesBedrock)(model);
case types_js_1.Providers.azure_foundry:
// Azure Foundry uses OpenAI capabilities
return (0, azure_foundry_js_1.getModelCapabilitiesAzureFoundry)(model);
case types_js_1.Providers.groq:
case types_js_1.Providers.togetherai:
case types_js_1.Providers.mistralai:
// These providers host text models that generally support tool use
return getModelCapabilitiesOpenAICompatible(model);
case types_js_1.Providers.xai:
// xAI (Grok) models support tool use and are text-based
return {
input: { text: true, image: model.includes("vision") },
output: { text: true },
tool_support: true,
tool_support_streaming: false, // Conservative - may work but not tested
};
default:
// Guess the provider based on the model name
if (model.startsWith("gpt")) {
return (0, openai_js_1.getModelCapabilitiesOpenAI)(model);
}
else if (model.startsWith("claude")) {
return (0, anthropic_js_1.getModelCapabilitiesAnthropic)(model);
}
else if (model.startsWith("grok")) {
// xAI Grok models
return {
input: { text: true, image: model.includes("vision") },
output: { text: true },
tool_support: true,
tool_support_streaming: false,
};
}
else if (model.startsWith("publishers/")) {
return (0, vertexai_js_1.getModelCapabilitiesVertexAI)(model);
}
else if (model.startsWith("arn:aws")) {
return (0, bedrock_js_1.getModelCapabilitiesBedrock)(model);
}
// Fallback to a generic model with no capabilities
return { input: {}, output: {} };
}
}
// Patterns for models known NOT to support tool use on OpenAI-compatible endpoints
const NO_TOOL_SUPPORT_PATTERNS = ['image', 'embed', 'moderation', 'whisper', 'sora', 'dall-e', 'tts'];
/**
* For OpenAI-compatible endpoints (e.g., OpenRouter), try OpenAI capability lookup first.
* If no explicit match is found, default to tool_support: true since most models
* on these platforms support tool use. Blacklist known non-tool-supporting patterns.
*/
function getModelCapabilitiesOpenAICompatible(model) {
const caps = (0, openai_js_1.getModelCapabilitiesOpenAI)(model);
if (caps.tool_support !== undefined) {
return caps;
}
const normalized = model.toLowerCase();
const isNonToolModel = NO_TOOL_SUPPORT_PATTERNS.some(p => normalized.includes(p));
return {
input: { text: true },
output: { text: true },
tool_support: !isNonToolModel,
tool_support_streaming: !isNonToolModel,
};
}
function supportsToolUse(model, provider, streaming = false) {
const capabilities = getModelCapabilities(model, provider);
return streaming ? !!capabilities.tool_support_streaming : !!capabilities.tool_support;
}
function modelModalitiesToArray(modalities) {
return Object.entries(modalities)
.filter(([_, isSupported]) => isSupported)
.map(([modality]) => modality);
}
//# sourceMappingURL=capability.js.map