-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-image-models.js
More file actions
51 lines (41 loc) · 1.69 KB
/
test-image-models.js
File metadata and controls
51 lines (41 loc) · 1.69 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
// 测试不同的图像生成模型
const { GoogleGenerativeAI } = require("@google/generative-ai");
async function testImageModels() {
const apiKey = "AIzaSyCqfEuGQ4pph0OtsZjT4sapeKxzRD3oNVA";
const genAI = new GoogleGenerativeAI(apiKey);
const models = [
"gemini-2.5-flash-image-preview",
"imagen-3.0-generate-001", // 可能的Imagen模型
"gemini-pro-vision", // 旧版本视觉模型
];
const simplePrompt = "Create a simple poster design for a coffee maker product with the text 'Smart Coffee Maker' and price '$299'";
for (const modelName of models) {
try {
console.log(`🧪 Testing model: ${modelName}`);
const imageModel = genAI.getGenerativeModel({ model: modelName });
const result = await imageModel.generateContent(simplePrompt);
console.log(`✅ ${modelName}: SUCCESS`);
console.log("Response type:", typeof result.response);
if (result.response.candidates && result.response.candidates[0]) {
const candidate = result.response.candidates[0];
if (candidate.content && candidate.content.parts) {
const imagePart = candidate.content.parts.find(part => part.inlineData);
if (imagePart) {
console.log(`📸 Image generated successfully with ${modelName}`);
return modelName; // 返回工作的模型
}
}
}
} catch (error) {
console.error(`❌ ${modelName}: ${error.message.substring(0, 100)}...`);
}
}
return null;
}
testImageModels().then(workingModel => {
if (workingModel) {
console.log(`\n🎉 Found working model: ${workingModel}`);
} else {
console.log("\n😞 No working image models found");
}
});