const { OpenAI } = require('openai'); const config = require('../config'); const client = new OpenAI({ apiKey: config.API_KEY, baseURL: config.BASE_URL }); async function img2text(prompt, imageUrl) { try { if (!prompt) { throw new Error('Missing prompt'); } if (!imageUrl) { throw new Error('Missing imageUrl'); } const response = await client.chat.completions.create({ model: 'gpt-4o', messages: [ { role: 'user', content: [ { type: 'text', text: prompt }, { type: 'image_url', image_url: { url: imageUrl, detail: 'high' } } ] } ], max_tokens: 300, stream: false }); return { success: true, data: response }; } catch (error) { throw error; } } module.exports = img2text;