zmh-program / chatnio

🚀 Next Generation AI One-Stop Internationalization Solution. 🚀 下一代 AI 一站式 B/C 端解决方案,支持 OpenAI,Midjourney,Claude,讯飞星火,Stable Diffusion,DALL·E,ChatGLM,通义千问,腾讯混元,360 智脑,百川 AI,火山方舟,新必应,Gemini,Moonshot 等模型,支持对话分享,自定义预设,云端同步,模型市场,支持弹性计费和订阅计划模式,支持图片解析,支持联网搜索,支持模型缓存,丰富美观的后台管理与仪表盘数据统计。
https://chatnio.com
Apache License 2.0
4.17k stars 619 forks source link

nil pointer dereference错误 #221

Closed SHLE1 closed 4 months ago

SHLE1 commented 4 months ago

在上传图片时会出现一直转圈,后台错误日志如下:

caught panic from chat request: runtime error: invalid memory address or nil pointer dereference
goroutine 631 [running]:
runtime/debug.Stack()
    /usr/local/go/src/runtime/debug/stack.go:24 +0x65
chat/manager.createChatTask.func2.1()
    /backend/manager/chat.go:99 +0x94
panic({0x1120a00, 0x1aff630})
    /usr/local/go/src/runtime/panic.go:884 +0x213
chat/utils.(*Buffer).AddImage(0xc0006fa6d8, 0xc00028e480)
    /backend/utils/buffer.go:114 +0x122
chat/adapter/openai.formatMessages.func1.1({0xc000ba2838, 0x2633})
    /backend/adapter/openai/processor.go:19 +0x76
chat/utils.EachNotNil[...]({0xc000a123b0, 0x1?, 0x0}, 0xc00001d7a8?)
    /backend/utils/base.go:250 +0xc2
chat/adapter/openai.formatMessages.func1({{0xc000ba280a, 0x4}, {0xc000ba281b, 0x2662}, 0x0, 0x0, 0x0, 0x0})
    /backend/adapter/openai/processor.go:17 +0x1a5
chat/utils.Each[...](...)
    /backend/utils/base.go:233
chat/adapter/openai.formatMessages(0xc0006fa600)
    /backend/adapter/openai/processor.go:14 +0x1aa
chat/adapter/openai.(*ChatInstance).GetChatBody(0x1119ce0?, 0xc0006fa600, 0x1)
    /backend/adapter/openai/chat.go:46 +0x78
chat/adapter/openai.(*ChatInstance).CreateStreamChatRequest(0xc00028e0c0, 0xc0006fa600, 0xc000736be8)
    /backend/adapter/openai/chat.go:114 +0x1df
chat/adapter.createChatRequest({0x13f8340, 0xc00014d300}, 0xc0006fa600, 0x10dade0?)
    /backend/adapter/adapter.go:49 +0x192
chat/adapter.NewChatRequest({0x13f8340, 0xc00014d300}, 0xc0006fa600, 0x1258e72?)
    /backend/adapter/request.go:28 +0x48
chat/channel.NewChatRequest({0x1258e72?, 0xc0004fae98?}, 0xc0006fa600, 0xc00096c5a0?)
    /backend/channel/worker.go:23 +0x186
chat/channel.NewChatRequestWithCache(0xc0009d76d8?, 0x448f60?, {0x1258e72, 0x6}, 0xc0006fa600, 0x459914?)
    /backend/channel/worker.go:94 +0x12b
chat/manager.createChatTask.func2()
    /backend/manager/chat.go:104 +0x325
created by chat/manager.createChatTask
    /backend/manager/chat.go:96 +0x28a
Issues-translate-bot commented 4 months ago

Bot detected the issue body's language is not English, translate it automatically.


Title: nil pointer dereference error

Sh1n3zZ commented 4 months ago

Hi,

感谢反馈,可能是下放 searxng 时造成的问题。 https://github.com/Deeptrain-Community/chatnio/commit/04ad6afa98a2f38cc6f9554ed26ee942088aea7a

请问在报错发生时(即导致报错的请求) 联网搜索 的是否开启?

Regards, Junhai Deng

SHLE1 commented 4 months ago

Hi,

感谢反馈,可能是下放 searxng 时造成的问题。

https://github.com/Deeptrain-Community/chatnio/commit/04ad6afa98a2f38cc6f9554ed26ee942088aea7a

请问在报错发生时(即导致报错的请求) 联网搜索 的是否开启?

Regards,

Junhai Deng

在线搜索开启或者关闭都会出现这个问题。另外单独进去searxng搜索可以正常出现结果,在chatnio里使用在线搜索时,大概率也是一直转圈,不知道是我设置有问题还是bug?

感谢您

Issues-translate-bot commented 4 months ago

Bot detected the issue body's language is not English, translate it automatically.


Hi,

Thanks for the feedback, it may be a problem caused when decentralizing searxng.

https://github.com/Deeptrain-Community/chatnio/commit/04ad6afa98a2f38cc6f9554ed26ee942088aea7a

When an error occurs (that is, the request that caused the error), is Internet Search enabled?

Regards,

Junhai Deng

This problem occurs when online search is turned on or off. In addition, if you go to searxng alone to search, the results will appear normally. When using online search in chatnio, there is a high probability that it will keep spinning. I don’t know if there is a problem with my settings or a bug?

Thanks you

Sh1n3zZ commented 4 months ago

Hi,

Thanks for the feedback. 我目前已经复现并修复了该问题,证实确实是下放更新时出现的问题,不过是 https://github.com/Deeptrain-Community/chatnio/commit/c81b599e907a79ff46c9e6c5551844e4490309f2 这个 commit 在更新 token 计算方式时未将需要用到的传入部分写完整出现的问题 该问题已在 https://github.com/Deeptrain-Community/chatnio/commit/576213d21f342a18c1169e34a5c6e37dc9365d70 中得到修复,待 Workflow 执行完毕后重新拉取镜像即可

Best Regards, Junhai Deng

SHLE1 commented 4 months ago

您好

在拉取最新镜像后仍然存在这一问题,打开/不打开在线搜索均出现。同时是不是可以在将最新版镜像打 latest tag的时候也打一个小版本号tag,方便在新版本出现错误时回退旧版本?

感谢开发者

[WARNING] - [2024-07-01 15:45:50] - caught panic from chat request: runtime error: invalid memory address or nil pointer dereference
goroutine 73 [running]:
runtime/debug.Stack()
    /usr/local/go/src/runtime/debug/stack.go:24 +0x65
chat/manager.createChatTask.func2.1()
    /backend/manager/chat.go:99 +0x94
panic({0x1121b80, 0x1b01630})
    /usr/local/go/src/runtime/panic.go:884 +0x213
chat/utils.(*Buffer).AddImage(0xc00036e8f8, 0xc000896000?)
    /backend/utils/buffer.go:136 +0x164
chat/adapter/openai.formatMessages.func1.1({0xc000868035, 0x18cf7})
    /backend/adapter/openai/processor.go:19 +0x76
chat/utils.EachNotNil[...]({0xc000769930, 0x1?, 0x0}, 0xc00089b7a8?)
    /backend/utils/base.go:250 +0xc2
chat/adapter/openai.formatMessages.func1({{0xc00086800a, 0x4}, {0xc00086801b, 0x18d23}, 0x0, 0x0, 0x0, 0x0})
    /backend/adapter/openai/processor.go:17 +0x1a5
chat/utils.Each[...](...)
    /backend/utils/base.go:233
chat/adapter/openai.formatMessages(0xc00036e820)
    /backend/adapter/openai/processor.go:14 +0x1aa
chat/adapter/openai.(*ChatInstance).GetChatBody(0x111ae60?, 0xc00036e820, 0x1)
    /backend/adapter/openai/chat.go:46 +0x78
chat/adapter/openai.(*ChatInstance).CreateStreamChatRequest(0xc000897580, 0xc00036e820, 0xc000012678)
    /backend/adapter/openai/chat.go:114 +0x1df
chat/adapter.createChatRequest({0x13f97c0, 0xc0000d1300}, 0xc00036e820, 0x10dbf60?)
    /backend/adapter/adapter.go:49 +0x192
chat/adapter.NewChatRequest({0x13f97c0, 0xc0000d1300}, 0xc00036e820, 0x125a1f9?)
    /backend/adapter/request.go:28 +0x48
chat/channel.NewChatRequest({0x125a1f9?, 0xc00025e6b8?}, 0xc00036e820, 0xc00003fa00?)
    /backend/channel/worker.go:23 +0x186
chat/channel.NewChatRequestWithCache(0x0?, 0x0?, {0x125a1f9, 0x6}, 0xc00036e820, 0x0?)
    /backend/channel/worker.go:94 +0x12b
chat/manager.createChatTask.func2()
    /backend/manager/chat.go:104 +0x325
created by chat/manager.createChatTask
    /backend/manager/chat.go:96 +0x28a
Sh1n3zZ commented 4 months ago

Hi,

修复后尝试 r2 存储和 base64 等多种方法未能复现,我的请求日志如下:

[DEBUG] - [2024-07-02 00:25:22] - [sse] event source: POST https://api.chatnio.net/v1/chat/completions
headers: {"Authorization":"Bearer sk-xxx","Content-Type":"application/json"}
body: {"model":"gpt-4o","messages":[{"role":"user","content":[{"type":"text","text":"```file\n[[Ministry_of_Industry_and_Information_Technology_of_P.R.China_(MIIT)_logo.png]]\n\n```\n\n请简述图片中的内容"},{"type":"image_url","image_url":{"url":"https://使用 r2 存储.png"}}]}],"max_tokens":2000,"stream":true,"presence_penalty":0,"frequency_penalty":0,"temperature":0.6,"top_p":1}

是否方便添加下联系方式详细排查

另:打 tag 确实是个好主意,近段时间忙完会考虑重新梳理一下开源版的相关内容。

Regards, Junhai Deng

Issues-translate-bot commented 4 months ago

Bot detected the issue body's language is not English, translate it automatically.


Hi,

After repairing, I tried multiple methods such as r2 storage and base64 but failed to reproduce. My request log is as follows:

[DEBUG] - [2024-07-02 00:25:22] - [sse] event source: POST https://api.chatnio.net/v1/chat/completions
headers: {"Authorization":"Bearer sk-xxx","Content-Type":"application/json"}
body: {"model":"gpt-4o","messages":[{"role":"user","content":[{"type":"text","text":"```file \n[[Ministry_of_Industry_and_Information_Technology_of_P.R.China_(MIIT)_logo.png]]\n\n```\n\nPlease briefly describe the content in the picture"},{"type":"image_url","image_url" :{"url":"https://use r2 storage.png"}}]}],"max_tokens":2000,"stream":true,"presence_penalty":0,"frequency_penalty":0,"temperature" :0.6,"top_p":1}

Is it convenient to add contact information for detailed troubleshooting?

Another note: tag is indeed a good idea. I will consider reorganizing the relevant content of the open source version after I have been busy recently.

Regards, Junhai Deng

SHLE1 commented 4 months ago

您好

我发现在图片为 png 格式时,可以正常进行回复。在图片为 jpeg 格式时,会出现以上错误。尝试多次可以复现。

Issues-translate-bot commented 4 months ago

Bot detected the issue body's language is not English, translate it automatically.


Hello

I found that when the image is in png format, I can reply normally. The above error will occur when the image is in jpeg format. It can be reproduced by trying several times.

Sh1n3zZ commented 4 months ago

Hi,

已测试 png jpeg 均无问题,仍然是 buffer 的锅 https://github.com/Deeptrain-Community/chatnio/commit/140bed53f95a979d91aad258b917f81f6a460ff1 编译完更新镜像谢谢喵,如果还有其他问题欢迎继续反馈。 ef617b94801c39898740192ba6e90204

Regards, Junhai Deng

Sh1n3zZ commented 4 months ago

Hi,

长期无回复,关闭该 issue

Regards, Junhai Deng

Issues-translate-bot commented 4 months ago

Bot detected the issue body's language is not English, translate it automatically.


Hi,

No reply for a long time, close this issue

Regards, Junhai Deng