test-ai.js 847 B

123456789101112131415161718192021222324252627282930
  1. const axios = require('axios');
  2. async function testAI() {
  3. try {
  4. console.log('🧪 测试 AI 接口...');
  5. const response = await axios.post('https://api.minimaxi.chat/v1/text/chatcompletion_v2', {
  6. model: 'MiniMax-M2.7',
  7. messages: [
  8. { role: 'user', content: '你好,请回复OK' }
  9. ],
  10. max_tokens: 10
  11. }, {
  12. headers: {
  13. 'Authorization': `Bearer ${process.env.MINIMAX_API_KEY}`,
  14. 'Content-Type': 'application/json'
  15. },
  16. timeout: 30000
  17. });
  18. console.log('✅ AI 接口正常');
  19. console.log('响应:', response.data.choices?.[0]?.message?.content);
  20. } catch (error) {
  21. console.error('❌ AI 接口失败:');
  22. console.error('状态码:', error.response?.status);
  23. console.error('错误信息:', error.response?.data || error.message);
  24. }
  25. }
  26. testAI();