72 lines
2.0 KiB
JavaScript
72 lines
2.0 KiB
JavaScript
/**
|
|
* API Debug Script
|
|
*/
|
|
require('dotenv').config();
|
|
const axios = require('axios');
|
|
|
|
const API_KEY = 'G9rXx3Ag2Xfa7Gs8zou6t6HqeZ';
|
|
const API_BASE = 'https://api.wuyinkeji.com/api';
|
|
|
|
async function debug() {
|
|
console.log('🔍 Starting API Debug...');
|
|
|
|
// 1. Debug Vision
|
|
console.log('\n--- 1. Testing Vision API ---');
|
|
try {
|
|
const res = await axios.post(`${API_BASE}/chat/index`, {
|
|
key: API_KEY,
|
|
model: 'gemini-1.5-flash',
|
|
content: 'Describe this image briefly.',
|
|
image_url: 'https://pub-777656770f4a44079545474665f00072.r2.dev/poc-1765607704915-IMG_6514.JPG' // 使用刚才日志里上传成功的图
|
|
});
|
|
console.log('Vision Response:', JSON.stringify(res.data, null, 2));
|
|
} catch (e) {
|
|
console.error('Vision Error:', e.message, e.response?.data);
|
|
}
|
|
|
|
// 2. Debug Image Submit
|
|
console.log('\n--- 2. Testing Image Submit ---');
|
|
let taskId;
|
|
try {
|
|
const res = await axios.post(`${API_BASE}/img/nanoBanana-pro`, {
|
|
key: API_KEY,
|
|
prompt: 'A cute cat',
|
|
aspectRatio: '1:1'
|
|
});
|
|
console.log('Submit Response:', JSON.stringify(res.data, null, 2));
|
|
|
|
// 尝试获取ID
|
|
if (res.data.data && typeof res.data.data === 'string') {
|
|
taskId = res.data.data;
|
|
} else if (res.data.data?.id) {
|
|
taskId = res.data.data.id;
|
|
} else if (res.data.id) {
|
|
taskId = res.data.id;
|
|
}
|
|
console.log('Extracted Task ID:', taskId);
|
|
} catch (e) {
|
|
console.error('Submit Error:', e.message, e.response?.data);
|
|
}
|
|
|
|
// 3. Debug Poll
|
|
if (taskId) {
|
|
console.log('\n--- 3. Testing Poll ---');
|
|
try {
|
|
// 等几秒让它处理
|
|
await new Promise(r => setTimeout(r, 3000));
|
|
|
|
const res = await axios.get(`${API_BASE}/img/drawDetail`, {
|
|
params: { key: API_KEY, id: taskId }
|
|
});
|
|
console.log('Poll Response:', JSON.stringify(res.data, null, 2));
|
|
} catch (e) {
|
|
console.error('Poll Error:', e.message, e.response?.data);
|
|
}
|
|
}
|
|
}
|
|
|
|
debug();
|
|
|
|
|
|
|