img2text.js 869 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. const config = require('../config');
  2. const PATH = 'chat/completions';
  3. const TIMEOUT_MS = 120000;
  4. // 普通 AI 请求参数
  5. function getBody(prompt, imageUrl) {
  6. return {
  7. model: config.MODEL_NAME || 'gpt-4o',
  8. messages: [{
  9. role: 'user',
  10. content: [
  11. { type: 'text', text: prompt },
  12. { type: 'image_url', image_url: { url: imageUrl, detail: 'high' } }
  13. ]
  14. }],
  15. max_tokens: 300,
  16. stream: false
  17. };
  18. }
  19. // 豆包请求参数
  20. function getDoubaoBody(prompt, imageUrl) {
  21. return {
  22. model: config.DOUBAO_MODEL,
  23. messages: [{
  24. role: 'user',
  25. content: [
  26. { type: 'text', text: prompt },
  27. { type: 'image_url', image_url: { url: imageUrl, detail: 'high' } }
  28. ]
  29. }],
  30. max_tokens: 300,
  31. stream: false
  32. };
  33. }
  34. module.exports = { path: PATH, getBody, getDoubaoBody, timeoutMs: TIMEOUT_MS };