mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-16 18:03:50 +00:00
feat(ai): Add models.dev data integration
- Add models script to download latest model information - Create models.ts module to query model capabilities - Include models.json in package distribution - Export utilities to check model features (reasoning, tools) - Update build process to copy models.json to dist
This commit is contained in:
parent
4bb3a5ad02
commit
02a9b4f09f
6 changed files with 8516 additions and 6 deletions
131
packages/ai/src/models.ts
Normal file
131
packages/ai/src/models.ts
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
import { readFileSync } from "fs";
|
||||
import { dirname, join } from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
export interface ModelInfo {
|
||||
id: string;
|
||||
name: string;
|
||||
attachment?: boolean;
|
||||
reasoning?: boolean;
|
||||
temperature?: boolean;
|
||||
tool_call?: boolean;
|
||||
knowledge?: string;
|
||||
release_date?: string;
|
||||
last_updated?: string;
|
||||
modalities?: {
|
||||
input?: string[];
|
||||
output?: string[];
|
||||
};
|
||||
open_weights?: boolean;
|
||||
cost?: {
|
||||
input?: number;
|
||||
output?: number;
|
||||
cache_read?: number;
|
||||
cache_write?: number;
|
||||
};
|
||||
limit?: {
|
||||
context?: number;
|
||||
output?: number;
|
||||
};
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
export interface ProviderInfo {
|
||||
id: string;
|
||||
env?: string[];
|
||||
npm?: string;
|
||||
api?: string;
|
||||
name: string;
|
||||
doc?: string;
|
||||
models: Record<string, ModelInfo>;
|
||||
}
|
||||
|
||||
export type ModelsData = Record<string, ProviderInfo>;
|
||||
|
||||
let cachedModels: ModelsData | null = null;
|
||||
|
||||
/**
|
||||
* Load models data from models.json
|
||||
* The file is loaded relative to this module's location
|
||||
*/
|
||||
export function loadModels(): ModelsData {
|
||||
if (cachedModels) {
|
||||
return cachedModels;
|
||||
}
|
||||
|
||||
try {
|
||||
// Get the directory of this module
|
||||
const currentDir = dirname(fileURLToPath(import.meta.url));
|
||||
const modelsPath = join(currentDir, "models.json");
|
||||
|
||||
const data = readFileSync(modelsPath, "utf-8");
|
||||
cachedModels = JSON.parse(data);
|
||||
return cachedModels!;
|
||||
} catch (error) {
|
||||
console.error("Failed to load models.json:", error);
|
||||
// Return empty providers object as fallback
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get information about a specific model
|
||||
*/
|
||||
export function getModelInfo(modelId: string): ModelInfo | undefined {
|
||||
const data = loadModels();
|
||||
|
||||
// Search through all providers
|
||||
for (const provider of Object.values(data)) {
|
||||
if (provider.models && provider.models[modelId]) {
|
||||
return provider.models[modelId];
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all models for a specific provider
|
||||
*/
|
||||
export function getProviderModels(providerId: string): ModelInfo[] {
|
||||
const data = loadModels();
|
||||
const provider = data[providerId];
|
||||
|
||||
if (!provider || !provider.models) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Object.values(provider.models);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get provider information
|
||||
*/
|
||||
export function getProviderInfo(providerId: string): ProviderInfo | undefined {
|
||||
const data = loadModels();
|
||||
return data[providerId];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a model supports thinking/reasoning
|
||||
*/
|
||||
export function supportsThinking(modelId: string): boolean {
|
||||
const model = getModelInfo(modelId);
|
||||
return model?.reasoning === true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a model supports tool calling
|
||||
*/
|
||||
export function supportsTools(modelId: string): boolean {
|
||||
const model = getModelInfo(modelId);
|
||||
return model?.tool_call === true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all available providers
|
||||
*/
|
||||
export function getAllProviders(): ProviderInfo[] {
|
||||
const data = loadModels();
|
||||
return Object.values(data);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue