verify-img-center-gpt54.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**
  2. * 与 img-center-point-location 相同栈:nodejs/ai ai.run('img2text', prompt, [url1,url2], { model })。
  3. * 默认模型用 nodejs/ai/config IMG_CENTER_MODEL(可用 VERIFY_FORCE_MODEL 覆盖)。
  4. */
  5. const path = require('path')
  6. const fs = require('fs')
  7. const aiModule = require(path.join(__dirname, '..', 'ai.js'))
  8. const aiConfig = require(path.join(__dirname, '..', 'config.js'))
  9. const img2textReq = require(path.join(__dirname, '..', 'request', 'img2text.js'))
  10. function fileToDataUrlPng (absPath) {
  11. const buf = fs.readFileSync(absPath)
  12. return `data:image/png;base64,${buf.toString('base64')}`
  13. }
  14. function defaultFixtureDir () {
  15. const projectRoot = path.resolve(__dirname, '..', '..', '..')
  16. const d = path.join(
  17. projectRoot,
  18. 'static',
  19. 'process',
  20. 'GenerateNote',
  21. 'tmp',
  22. 'img-center-1774080885011'
  23. )
  24. return fs.existsSync(path.join(d, 'screenshot.png')) ? d : null
  25. }
  26. async function main () {
  27. const model = (
  28. process.env.VERIFY_FORCE_MODEL ||
  29. img2textReq.resolveImgCenterModel(undefined)
  30. ).trim()
  31. const def = defaultFixtureDir()
  32. const screenPath =
  33. process.argv[2] ||
  34. (def && path.join(def, 'screenshot.png')) ||
  35. path.join(__dirname, 'fixture-verify.png')
  36. const tplPath =
  37. process.argv[3] ||
  38. (def && path.join(def, 'template.png')) ||
  39. screenPath
  40. if (!fs.existsSync(screenPath)) {
  41. console.error('缺少截图:', screenPath)
  42. process.exit(1)
  43. }
  44. if (!fs.existsSync(tplPath)) {
  45. console.error('缺少模板:', tplPath)
  46. process.exit(1)
  47. }
  48. const verifyPrompt = `你收到两张图(与 img-center ROI 流程相同的多模态调用)。
  49. 请严格只输出纯文本三行,不要 markdown:
  50. 第1行:你认为本次 API 实际为你分配的模型名称或系列(若不确定写 未知)。
  51. 第2行:若你认为是 GPT-5.4 系列则写 YES,否则写 NO。
  52. 第3行:简短说明依据(不超过 40 字)。
  53. 注意:以服务端返回的 JSON 里 model 字段为准;你的自称可能不准。`
  54. console.log('IMG_CENTER_MODEL (resolveImgCenterModel default):', img2textReq.resolveImgCenterModel(undefined))
  55. console.log('request options.model:', model)
  56. const r = await aiModule.run('img2text', verifyPrompt, [fileToDataUrlPng(screenPath), fileToDataUrlPng(tplPath)], {
  57. model,
  58. timeoutMs: 300000,
  59. })
  60. if (!r.success) {
  61. console.error(r.error || '请求失败')
  62. process.exit(1)
  63. }
  64. const resp = r.data
  65. console.log('response.model (authoritative):', resp.model)
  66. const content = resp?.choices?.[0]?.message?.content
  67. console.log('assistant (self-report, not authoritative):\n---\n', content, '\n---')
  68. const ok =
  69. String(resp.model || '')
  70. .toLowerCase()
  71. .includes('gpt-5.4') || String(resp.model || '').toLowerCase().includes('5.4')
  72. console.log('response.model looks like gpt-5.4:', ok ? 'YES' : 'NO (check gateway mapping)')
  73. console.log('BASE_URL:', aiConfig.BASE_URL)
  74. }
  75. main().catch((e) => {
  76. console.error(e)
  77. process.exit(1)
  78. })