File size: 2,462 Bytes
eb7f5ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env node

// Test script for EmbeddingWordService
require('dotenv').config();
const EmbeddingWordService = require('./services/embeddingWordService');

async function testEmbeddingService() {
  console.log('🧪 Testing EmbeddingWordService...\n');

  try {
    // Test 1: Check service initialization
    console.log('1️⃣ Testing service initialization...');
    const stats = EmbeddingWordService.getCacheStats();
    console.log('   Service stats:', stats);
    
    if (stats.isInitialized) {
      console.log('   ✅ HuggingFace service initialized successfully');
    } else {
      console.log('   ⚠️  HuggingFace service not initialized (likely missing API key)');
      console.log('   📝 This is expected if HUGGINGFACE_API_KEY is not set');
    }

    // Test 2: Generate words for topics
    console.log('\n2️⃣ Testing word generation...');
    const topics = ['animals', 'science'];
    const words = await EmbeddingWordService.generateWordsForTopics(topics, 'medium', 8);
    
    console.log(`   Generated ${words.length} words for topics: ${topics.join(', ')}`);
    words.forEach((word, index) => {
      console.log(`   ${index + 1}. ${word.word} - "${word.clue}"`);
    });

    // Test 3: Test different difficulties
    console.log('\n3️⃣ Testing different difficulties...');
    const difficulties = ['easy', 'medium', 'hard'];
    
    for (const difficulty of difficulties) {
      const diffWords = await EmbeddingWordService.generateWordsForTopics(['technology'], difficulty, 3);
      console.log(`   ${difficulty.toUpperCase()}: ${diffWords.map(w => w.word).join(', ')}`);
    }

    // Test 4: Cache stats
    console.log('\n4️⃣ Final cache stats...');
    const finalStats = EmbeddingWordService.getCacheStats();
    console.log('   Final stats:', finalStats);

    console.log('\n✅ All tests completed successfully!');
    
    // Instructions for next steps
    console.log('\n📋 Next Steps:');
    console.log('   1. Sign up for HuggingFace account at https://huggingface.co/join');
    console.log('   2. Generate API token at https://huggingface.co/settings/tokens');
    console.log('   3. Update HUGGINGFACE_API_KEY in .env file');
    console.log('   4. Run this test again to verify AI-powered word generation');

  } catch (error) {
    console.error('❌ Test failed:', error.message);
    console.error('   Stack trace:', error.stack);
  }
}

// Run the test
testEmbeddingService();