text2text.js 862 B

12345678910111213141516171819
  1. const path = require('path')
  2. const aiModule = require(path.join(__dirname, '../../../../ai/ai.js'))
  3. async function executeText2text({ prompt, model, folderPath }) {
  4. const p = prompt != null ? String(prompt).trim() : ''
  5. const m = model != null ? String(model).trim().toLowerCase() : ''
  6. const action = m === 'doubao' ? 'doubao_text2text' : 'text2text'
  7. try {
  8. const result = await aiModule.run(action, p)
  9. if (!result.success) return { success: false, error: result.error || 'text2text 失败' }
  10. const data = result.data
  11. const text = data?.choices?.[0]?.message?.content ?? data?.choices?.[0]?.text ?? ''
  12. return { success: true, value: typeof text === 'string' ? text : String(text) }
  13. } catch (e) {
  14. return { success: false, error: (e && (e.message || String(e))) || 'text2text 异常' }
  15. }
  16. }
  17. module.exports = { executeText2text }