test-ai.js 931 B

123456789101112131415161718192021222324252627282930
  1. const axios = require('axios');
  2. const BASE_URL = 'http://localhost:3000';
  3. async function testAIModels() {
  4. console.log('=== 测试 AI 模型接口 ===\n');
  5. try {
  6. console.log('1️⃣ 测试获取 AI 模型列表...');
  7. const result = await axios.get(`${BASE_URL}/api/ai/models`);
  8. console.log('✅ AI 模型列表:', JSON.stringify(result.data, null, 2));
  9. console.log('\n2️⃣ 测试 AI 文本生成...');
  10. const generate = await axios.post(`${BASE_URL}/api/ai/generate`, {
  11. prompt: '写一首关于春天的短诗',
  12. model: 'tongyi-xiaomi-analysis-pro'
  13. }, {
  14. timeout: 60000
  15. });
  16. console.log('✅ AI 生成成功:', JSON.stringify(generate.data, null, 2));
  17. } catch (error) {
  18. console.error('❌ 测试失败:', error.message);
  19. if (error.response) {
  20. console.error('📋 错误响应:', JSON.stringify(error.response.data, null, 2));
  21. }
  22. }
  23. }
  24. testAIModels();