fix-think.js 1.3 KB

12345678910111213141516171819202122232425262728293031
  1. const fs = require('fs');
  2. const file = 'src/modules/book-generator/langgraph-generator.ts';
  3. let content = fs.readFileSync(file, 'utf8');
  4. // 修复错误的字符串
  5. content = content.replace(
  6. "const thinkEndIdx = cleanedStr.indexOf('>>>>>>>');",
  7. "const thinkEndIdx = cleanedStr.indexOf('>>>>>>>>' + ' endthink'.substring(0,0) + ''); // 搜索 ffffff"
  8. );
  9. // 实际上应该直接搜索
  10. content = content.replace(
  11. "const thinkEndIdx = cleanedStr.indexOf('>>>>>>>>' + ' endthink'.substring(0,0) + ''); // 搜索 ffffff",
  12. "const thinkEndIdx = cleanedStr.indexOf(String.fromCharCode(0x1f4e8) + ' end'); // 占位"
  13. );
  14. // 最简单的方式:直接替换整个块
  15. content = content.replace(
  16. / \/\/ 移除思考标签.*?const thinkEndIdx = cleanedStr\.indexOf\(.*?\);[\s\S]*?cleanedStr = cleanedStr\.substring\(thinkEndIdx \+ 8\)\.trim\(\);[\s\S]*?\}/,
  17. ` // 移除思考标签
  18. const endTag = String.fromCodePoint(0x1F4E8); // 使用emoji占位,实际搜索
  19. const searchStr = '<' + 'thi' + 'nk' + ' end>';
  20. const thinkEndIdx = cleanedStr.indexOf(searchStr);
  21. if (thinkEndIdx !== -1) {
  22. cleanedStr = cleanedStr.substring(thinkEndIdx + searchStr.length).trim();
  23. }`
  24. );
  25. fs.writeFileSync(file, content, 'utf8');
  26. console.log('✅ 修复完成');