new-api icon indicating copy to clipboard operation
new-api copied to clipboard

调用火山引擎联网模型报错:bufio.Scanner: token too long

Open im-lee opened this issue 1 year ago • 5 comments

例行检查

  • [x] 我已确认目前没有类似 issue
  • [x] 我已确认我已升级到最新版本
  • [x] 我已完整查看过项目 README,尤其是常见问题部分
  • [x] 我理解并愿意跟进此 issue,协助测试和提供反馈
  • [x] 我理解并认可上述内容,并理解项目维护者精力有限,不遵循规则的 issue 可能会被无视或直接关闭

问题描述 调用火山引擎联网模型日志中报错: [ERR] 2025/03/18 - 21:43:53 | 20250318214351624772645271d9eoq | scanner error: bufio.Scanner: token too long

猜测原因 测试发现火山引擎在开启墨迹天气内容源时返回体中的json超过3000行,且数据大小接近200KB,可能因此是因此导致缓冲区溢出

复现步骤 1.火山引擎联网应用内容源选择搜索引擎、墨迹天气 2.NewApi中增加自定义渠道、设置火山引擎的url和模型映射

预期结果 正常流式输出

相关截图

Image Image

im-lee avatar Mar 18 '25 13:03 im-lee

https://github.com/Calcium-Ion/new-api/blob/73263e02d6abe268a264a1d9bf577b54b371927a/relay/helper/stream_scanner.go#L33

I think this can be handled easily, most of the time it's less than 16MB. scanner.Buffer(make([]byte, 64*1024), 16 * 1024 * 1024) // 64kb -> 16m

pekrockstar avatar Mar 20 '25 15:03 pekrockstar

@im-lee 试试0.6.1.1及之后的版本,我提了PR修复了这个问题

Praying avatar Apr 11 '25 03:04 Praying

我确认有此问题。添加 scanner.Buffer(make([]byte, 64*1024), 16 * 1024 * 1024 可以解决此问题。

当我让gemini画图时,返回的内容是base64内容,就会提示bufio.Scanner: token too long 错误。

smecrusher avatar Sep 25 '25 06:09 smecrusher

[Bot Review]

This issue has been automatically marked as stale due to inactivity. If this is still relevant, please reply within 7 days — otherwise it will be closed automatically.

[Bot Review]

This issue has been automatically closed and locked due to prolonged inactivity. If the problem persists, please open a new issue.