UNPKG

unified-ai-router

Version:

A unified interface for multiple LLM providers with automatic fallback. This project includes an OpenAI-compatible server and a deployable Telegram bot with a Mini App interface. It supports major providers like OpenAI, Google, Grok, and more, ensuring re

32 lines (27 loc) 668 B
const AIRouter = require( "../main" ); require( "dotenv" ).config({ quiet: true }); const providers = require( "../provider" ) const llm = new AIRouter( providers ); async function getResponse () { try { const messages = [ { role: "system", content: "You are a helpful assistant." }, { role: "user", content: "Hello, say something short." } ]; const stream = await llm.chatCompletion( messages, { temperature: 0.7, stream: true, }); for await ( const chunk of stream ) { process.stdout.write( chunk.reasoning || chunk.content ); } } catch ( error ) { console.error( "All providers failed:", error.message ); } } getResponse();