UNPKG

doubao-i2i-generator-mcp

Version:

MCP Server for generating images using Doubao Seedream 3.0 i2i (image-to-image) model

87 lines (72 loc) 2.65 kB
// 测试豆包Seedream-3 i2i图片生成功能 import { spawn } from 'child_process'; // 测试参数 const testArgs = { model: 'doubao-seededit-3-0-i2i-250628', prompt: '改成爱心形状的泡泡', image: 'https://ark-project.tos-cn-beijing.volces.com/doc_image/seededit_i2i.jpeg', response_format: 'url', size: 'adaptive', seed: 21, guidance_scale: 5.5, watermark: true }; // 模拟MCP工具调用 async function testI2IGeneration() { console.log('测试豆包Seedream-3 i2i图片生成...'); console.log('输入参数:', JSON.stringify(testArgs, null, 2)); try { // 检查环境变量 const apiKey = process.env.ARK_API_KEY; if (!apiKey) { console.error('错误: 请设置 ARK_API_KEY 环境变量'); console.log('请参考 env_example.txt 文件进行配置'); return; } // 构造curl命令 const baseUrl = 'https://ark.cn-beijing.volces.com/api/v3'; const endpoint = `${baseUrl}/images/generations`; const args = [ '-sS', '-X', 'POST', endpoint, '-H', 'Content-Type: application/json', '-H', `Authorization: Bearer ${apiKey}`, '-d', JSON.stringify(testArgs) ]; console.log('\n执行curl命令...'); console.log('curl', args.join(' ')); // 执行curl const proc = spawn('curl', args, { stdio: ['ignore', 'pipe', 'pipe'] }); let stdout = ''; let stderr = ''; proc.stdout.on('data', (d) => { stdout += d.toString(); }); proc.stderr.on('data', (d) => { stderr += d.toString(); }); proc.on('close', (code) => { if (code !== 0) { console.error(`\n错误: curl执行失败,退出码 ${code}`); if (stderr) console.error('错误信息:', stderr); return; } try { const response = JSON.parse(stdout); console.log('\n✅ 成功! API响应:'); console.log(JSON.stringify(response, null, 2)); if (response.data && response.data[0] && response.data[0].url) { console.log('\n🎉 生成的图片URL:'); console.log(response.data[0].url); } } catch (e) { console.error('\n❌ 解析响应失败:', e.message); console.log('原始输出:', stdout); } }); proc.on('error', (err) => { console.error('\n❌ 启动curl失败:', err.message); console.log('请确保系统已安装curl'); }); } catch (error) { console.error('\n❌ 测试失败:', error.message); } } // 运行测试 testI2IGeneration();