Files
Avtex/scripts/test_openrouter.cjs
T

72 lines
2.3 KiB
JavaScript

/**
* Тест стабильных OpenRouter моделей (Laguna & Nemotron)
* Запуск: node scripts/test_openrouter.cjs
*/
require('dotenv').config()
const OPENROUTER_BASE_URL = 'https://openrouter.ai/api/v1/chat/completions'
const MODELS = {
laguna: 'poolside/laguna-m.1:free',
nemotron: 'nvidia/nemotron-3-super-120b-a12b:free',
}
const LABELS = {
laguna: '🏊 Laguna M.1 (Claude)',
nemotron: '🔬 Nemotron Super 120B (NVIDIA)',
}
async function testModel(key, modelId) {
const apiKey = process.env.OPEN_ROUTER_API_KEY || process.env.NUXT_OPEN_ROUTER_API_KEY
if (!apiKey) throw new Error('OPEN_ROUTER_API_KEY not set in .env')
const start = Date.now()
try {
const res = await fetch(OPENROUTER_BASE_URL, {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json',
'HTTP-Referer': 'https://a-crm.controlsystem.kz',
'X-Title': 'XFlow AI Test',
},
body: JSON.stringify({
model: modelId,
messages: [
{ role: 'system', content: 'You are a helpful assistant. Reply briefly.' },
{ role: 'user', content: 'Say "OK" and your model name in one short sentence.' },
],
stream: false,
}),
})
const data = await res.json()
const elapsed = ((Date.now() - start) / 1000).toFixed(1)
if (!res.ok) {
console.log(` ❌ ${LABELS[key]} — HTTP ${res.status}: ${data?.error?.message || JSON.stringify(data)}`)
return
}
const content = data?.choices?.[0]?.message?.content || '(empty)'
console.log(` ✅ ${LABELS[key]} (${elapsed}s): ${content.trim().slice(0, 120)}`)
} catch (err) {
console.log(` ❌ ${LABELS[key]} — ${err.message}`)
}
}
async function main() {
console.log('\n🚀 XFlow — OpenRouter Stable Models Test\n')
const apiKey = process.env.OPEN_ROUTER_API_KEY || process.env.NUXT_OPEN_ROUTER_API_KEY
console.log(`🔑 API Key: ${apiKey ? apiKey.slice(0, 20) + '...' : 'NOT FOUND'}\n`)
for (const [key, modelId] of Object.entries(MODELS)) {
process.stdout.write(`Testing ${LABELS[key]}...\n`)
await testModel(key, modelId)
await new Promise(r => setTimeout(r, 1000))
}
console.log('\n✨ Done!\n')
}
main().catch(console.error)