chore: align infrastructure with server
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
require('dotenv').config()
|
||||
const https = require('https')
|
||||
|
||||
const apiKey = process.env.NUXT_QWEN_API_KEY || process.env.QWEN_API_KEY
|
||||
|
||||
if (!apiKey) {
|
||||
console.error('❌ QWEN_API_KEY не найден в .env!')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
console.log('✅ Ключ найден:', apiKey.substring(0, 8) + '...')
|
||||
console.log('📡 Отправляю запрос к Qwen API...')
|
||||
|
||||
const body = JSON.stringify({
|
||||
model: 'qwen-turbo',
|
||||
messages: [
|
||||
{ role: 'user', content: 'Say "Hello from Qwen!" in Russian, briefly.' }
|
||||
]
|
||||
})
|
||||
|
||||
const options = {
|
||||
hostname: 'dashscope.aliyuncs.com',
|
||||
path: '/compatible-mode/v1/chat/completions',
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${apiKey}`,
|
||||
'Content-Type': 'application/json',
|
||||
'Content-Length': Buffer.byteLength(body)
|
||||
}
|
||||
}
|
||||
|
||||
const req = https.request(options, (res) => {
|
||||
let data = ''
|
||||
res.on('data', chunk => data += chunk)
|
||||
res.on('end', () => {
|
||||
console.log('📨 Статус:', res.statusCode)
|
||||
try {
|
||||
const parsed = JSON.parse(data)
|
||||
if (parsed.choices) {
|
||||
console.log('✅ Ответ:', parsed.choices[0].message.content)
|
||||
} else {
|
||||
console.log('❌ Ответ без choices:', JSON.stringify(parsed, null, 2))
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('❌ Сырой ответ:', data)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
req.on('error', (e) => {
|
||||
console.error('❌ Ошибка запроса:', e.message)
|
||||
})
|
||||
|
||||
req.write(body)
|
||||
req.end()
|
||||
Reference in New Issue
Block a user