-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-ai-correct.js
More file actions
131 lines (121 loc) Β· 5.26 KB
/
test-ai-correct.js
File metadata and controls
131 lines (121 loc) Β· 5.26 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Correct Chrome AI API Test - Based on Official Documentation
// Paste this into browser console
console.log('π¬ Chrome AI API Test (Official Method)');
console.log('=====================================');
// Check Chrome version
const userAgent = navigator.userAgent;
const chromeMatch = userAgent.match(/Chrome\/(\d+)/);
if (chromeMatch) {
const version = parseInt(chromeMatch[1]);
console.log(`Chrome Version: ${version}`);
if (version < 127) {
console.error('β Chrome version too old! Need 127+');
} else {
console.log('β
Chrome version should support AI APIs');
}
} else {
console.error('β Not running on Chrome');
}
async function testAIAPIs() {
console.log('\nπ€ Testing AI APIs with correct methods...');
// Test LanguageModel (Prompt API)
console.log('\n--- LanguageModel (Prompt API) ---');
if ('LanguageModel' in self) {
console.log('β
LanguageModel API exists');
try {
const availability = await LanguageModel.availability();
console.log('π LanguageModel availability:', availability);
switch(availability) {
case 'available':
console.log('π LanguageModel is ready to use!');
// Try creating a session
try {
const session = await LanguageModel.create();
console.log('β
LanguageModel session created successfully');
const response = await session.prompt('Say hello');
console.log('π€ Response:', response);
} catch (e) {
console.error('β Failed to create session:', e);
}
break;
case 'downloadable':
console.log('β³ Model needs download (requires user activation)');
console.log('π‘ Try clicking a button first, then call LanguageModel.create()');
break;
case 'downloading':
console.log('π₯ Model is currently downloading...');
break;
case 'unavailable':
console.log('β LanguageModel not available on this device');
break;
default:
console.log('β Unknown availability status:', availability);
}
} catch (e) {
console.error('β Error checking LanguageModel availability:', e);
}
} else {
console.log('β LanguageModel API not found');
console.log('π‘ Make sure chrome://flags/#prompt-api-for-gemini-nano is ENABLED');
}
// Test Summarizer API
console.log('\n--- Summarizer API ---');
if ('Summarizer' in self) {
console.log('β
Summarizer API exists');
try {
const availability = await Summarizer.availability();
console.log('π Summarizer availability:', availability);
switch(availability) {
case 'available':
console.log('π Summarizer is ready to use!');
break;
case 'downloadable':
console.log('β³ Model needs download (requires user activation)');
break;
case 'downloading':
console.log('π₯ Model is currently downloading...');
break;
case 'unavailable':
console.log('β Summarizer not available on this device');
break;
default:
console.log('β Unknown availability status:', availability);
}
} catch (e) {
console.error('β Error checking Summarizer availability:', e);
}
} else {
console.log('β Summarizer API not found');
console.log('π‘ Make sure chrome://flags/#summarization-api-for-gemini-nano is ENABLED');
}
// Test Translator API
console.log('\n--- Translator API ---');
if ('Translator' in self) {
console.log('β
Translator API exists');
try {
const availability = await Translator.availability();
console.log('π Translator availability:', availability);
} catch (e) {
console.error('β Error checking Translator availability:', e);
}
} else {
console.log('β Translator API not found');
console.log('π‘ Make sure chrome://flags/#translation-api is ENABLED');
}
}
// Run the test
testAIAPIs().then(() => {
console.log('\nπ Test completed!');
console.log('π Location:', window.location.href);
console.log('π Extension Context:', !!chrome?.runtime?.id);
console.log('\nπ‘ Next steps if APIs not available:');
console.log('1. Go to chrome://flags/');
console.log('2. Enable: prompt-api-for-gemini-nano');
console.log('3. Enable: summarization-api-for-gemini-nano');
console.log('4. Enable: translation-api');
console.log('5. Restart Chrome completely');
console.log('6. Check hardware requirements (22GB free space, 4GB+ VRAM)');
console.log('=====================================');
}).catch(e => {
console.error('Test failed:', e);
});