const path = require('path') const aiModule = require(path.join(__dirname, '../../../../ai/ai.js')) /** 入参:prompt, model, imageUrl(参考图地址,如 data URL 或 http URL) */ async function executeImg2text({ prompt, model, imageUrl, folderPath }) { const p = prompt != null ? String(prompt).trim() : '' const url = imageUrl != null ? String(imageUrl).trim() : '' if (!url) return { success: false, error: 'img2text 缺少 imageUrl' } const m = model != null ? String(model).trim().toLowerCase() : '' const action = m === 'doubao' ? 'doubao_img2text' : 'img2text' try { const result = await aiModule.run(action, p, url) if (!result.success) return { success: false, error: result.error || 'img2text 失败' } const data = result.data const text = data?.choices?.[0]?.message?.content ?? data?.choices?.[0]?.text ?? '' return { success: true, value: typeof text === 'string' ? text : String(text) } } catch (e) { return { success: false, error: (e && (e.message || String(e))) || 'img2text 异常' } } } module.exports = { executeImg2text }