Show HN: I built an SDK to select the best model for your task
1 day ago
1
Auto-select the best AI model based on your query. This SDK automatically finds the most suitable models from Hugging Face based on semantic similarity to your task description.
npm install autorouter-sdk
AutoRouter requires OpenAI and Pinecone credentials. You'll need:
The process takes about 10-15 minutes. You only need to run this once.
import{AutoRouter}from'autorouter-sdk';constrouter=newAutoRouter({openaiKey: 'your-openai-key',pineconeKey: 'your-pinecone-key',pineconeIndexName: 'autorouter-models'// optional, defaults to 'autorouter-models'});constmodels=awaitrouter.selectModel('build a chatbot');console.log(models);// [// {// id: 'meta-llama/Llama-2-7b-chat-hf',// name: 'Llama-2-7b-chat-hf',// description: 'A conversational AI model...',// task: 'text-generation',// provider: 'huggingface',// license: 'apache-2.0',// downloads: 5000000,// score: 0.95,// endpoint: 'https://api-inference.huggingface.co/models/...'// },// ...// ]
// With optionsconstmodels=awaitrouter.selectModel('summarize text',{limit: 10,filter: {license: 'apache-2.0'}});// Get top 5 modelsconsttopModels=awaitrouter.selectModel('generate images',{limit: 5});
newAutoRouter(config: AutoRouterConfig)
config.openaiKey (string): Your OpenAI API key
config.pineconeKey (string): Your Pinecone API key
config.pineconeIndexName (string, optional): Pinecone index name (defaults to 'autorouter-models')
selectModel(query, options?)
Returns an array of model recommendations sorted by relevance.
query (string): Description of your task (e.g., "build a chatbot", "generate images")
options (object, optional):
limit (number): Maximum number of results (default: 10)
filter (object): Filter options
license (string): Filter by license type (e.g., "apache-2.0", "mit")
interfaceModelResult{id: string;// Model identifiername: string;// Model namedescription: string;// Model descriptiontask: string;// Task type (e.g., 'text-generation')provider: string;// Provider (e.g., 'huggingface')license: string;// License typedownloads?: number;// Download countscore: number;// Similarity score (0-1)endpoint?: string;// Inference endpoint URL}
The package includes a pre-built registry with 7,000+ models. You can customize which models are included by modifying scripts/generate-model-registry.ts and running:
npm run generate-registry
This will regenerate data/model-registry.json based on your changes. Then run the indexing process again:
npx autorouter-sdk index-models
Key parameters in generate-model-registry.ts:
modelsPerTask: Number of models to fetch per task type (default: 200)
taskCategories: Which task types to include
sortBy: How to sort models (default: 'downloads')
autorouter-sdk index-models
Options:
--openai-key <key>: OpenAI API key (or use OPENAI_API_KEY env var)
--pinecone-key <key>: Pinecone API key (or use PINECONE_API_KEY env var)
--index-name <name>: Pinecone index name (default: 'autorouter-models')
--registry-path <path>: Path to custom model registry JSON file
try{constmodels=awaitrouter.selectModel('build a chatbot');}catch(error){console.error('Failed to select model:',error);}