songquanpeng / one-api

OpenAI 接口管理 & 分发系统,支持 Azure、Anthropic Claude、Google PaLM 2 & Gemini、智谱 ChatGLM、百度文心一言、讯飞星火认知、阿里通义千问、360 智脑以及腾讯混元,可用于二次分发管理 key,仅单可执行文件,已打包好 Docker 镜像,一键部署,开箱即用. OpenAI key management & redistribution system, using a single API for all LLMs, and features an English UI.
https://openai.justsong.cn/
MIT License
17.91k stars 4.06k forks source link

讯飞模型出现意义不明报错 #1266

Closed bincooo closed 5 months ago

bincooo commented 5 months ago

例行检查

问题描述 panic detected: runtime error: invalid memory address or nil pointer dereference

[GIN] 2024/04/03 - 14:03:24 | 2024040314032326483969861767128 | 500 |  803.472797ms |      172.31.0.5 |    POST /v1/chat/completions
[INFO] 2024/04/03 - 14:03:24 | 2024040314032488907379974244809 | user 1 has enough quota 9999246880600, trusted and no need to pre-consume 
[SYS] 2024/04/03 - 14:03:25 | error reading stream response: websocket: close 1000 (normal): close this ws conn 
[ERR] 2024/04/03 - 14:03:25 | 2024040314032488907379974244809 | panic detected: runtime error: invalid memory address or nil pointer dereference 
[ERR] 2024/04/03 - 14:03:25 | 2024040314032488907379974244809 | stacktrace from panic: goroutine 573 [running]:
runtime/debug.Stack()
        /usr/local/go/src/runtime/debug/stack.go:24 +0x5e
github.com/songquanpeng/one-api/router.SetRelayRouter.RelayPanicRecover.func2.1()
        /build/middleware/recover.go:18 +0xc5
panic({0xf56e40?, 0x3b1d010?})
        /usr/local/go/src/runtime/panic.go:770 +0x132
github.com/songquanpeng/one-api/relay/channel/openai.ErrorWrapper(...)
        /build/relay/channel/openai/util.go:7
github.com/songquanpeng/one-api/relay/channel/xunfei.Handler(_, {{0xc000b81540, 0x9}, {0xc000b1ce40, 0x1, 0x1}, {0x0, 0x0}, 0x0, 0x0, ...}, ...)
        /build/relay/channel/xunfei/main.go:174 +0x64f
github.com/songquanpeng/one-api/relay/channel/xunfei.(*Adaptor).DoResponse(0xc0002d8700, 0xc000716600, 0x10921cb?, 0xc000bf3e10)
        /build/relay/channel/xunfei/adaptor.go:59 +0x186
github.com/songquanpeng/one-api/relay/controller.RelayTextHelper(0xc000716600)
        /build/relay/controller/text.go:95 +0xd69
github.com/songquanpeng/one-api/controller.relay(0xc0004348a5?, 0x1084d84?)
        /build/controller/relay.go:37 +0x52
github.com/songquanpeng/one-api/controller.Relay(0xc000716600)
        /build/controller/relay.go:50 +0x145
github.com/gin-gonic/gin.(*Context).Next(0xc000716600)
        /go/pkg/mod/github.com/gin-gonic/gin@v1.9.1/context.go:174 +0x2b
github.com/songquanpeng/one-api/router.SetRelayRouter.Distribute.func4(0xc000716600)
        /build/middleware/distributor.go:83 +0x3b7
github.com/gin-gonic/gin.(*Context).Next(0xc000716600)
        /go/pkg/mod/github.com/gin-gonic/gin@v1.9.1/context.go:174 +0x2b
github.com/songquanpeng/one-api/router.SetRelayRouter.TokenAuth.func3(0xc000716600)
        /build/middleware/auth.go:121 +0x1d4
github.com/gin-gonic/gin.(*Context).Next(0xc000716600)
        /go/pkg/mod/github.com/gin-gonic/gin@v1.9.1/context.go:174 +0x2b
github.com/songquanpeng/one-api/router.SetRelayRouter.RelayPanicRecover.func2(0xc000716698?)
        /build/middleware/recover.go:31 +0x45
github.com/gin-gonic/gin.(*Context).Next(0xc000716600)
        /go/pkg/mod/github.com/gin-gonic/gin@v1.9.1/context.go:174 +0x2b
main.main.Sessions.func3(0xc000716600)
        /go/pkg/mod/github.com/gin-contrib/sessions@v0.0.5/sessions.go:54 +0x169
github.com/gin-gonic/gin.(*Context).Next(...)
        /go/pkg/mod/github.com/gin-gonic/gin@v1.9.1/context.go:174
github.com/gin-gonic/gin.LoggerWithConfig.func1(0xc000716600)
        /go/pkg/mod/github.com/gin-gonic/gin@v1.9.1/logger.go:240 +0xdd
github.com/gin-gonic/gin.(*Context).Next(0xc000716600)
        /go/pkg/mod/github.com/gin-gonic/gin@v1.9.1/context.go:174 +0x2b
main.main.RequestId.func2(0xc000716600)
        /build/middleware/request-id.go:17 +0x106
github.com/gin-gonic/gin.(*Context).Next(...)
        /go/pkg/mod/github.com/gin-gonic/gin@v1.9.1/context.go:174
github.com/gin-gonic/gin.CustomRecoveryWithWriter.func1(0xc000716600)
        /go/pkg/mod/github.com/gin-gonic/gin@v1.9.1/recovery.go:102 +0x7a
github.com/gin-gonic/gin.(*Context).Next(...)
        /go/pkg/mod/github.com/gin-gonic/gin@v1.9.1/context.go:174
github.com/gin-gonic/gin.(*Engine).handleHTTPRequest(0xc000506680, 0xc000716600)
        /go/pkg/mod/github.com/gin-gonic/gin@v1.9.1/gin.go:620 +0x66e
github.com/gin-gonic/gin.(*Engine).ServeHTTP(0xc000506680, {0x34a9ff8, 0xc0007beb60}, 0xc00097dd40)
        /go/pkg/mod/github.com/gin-gonic/gin@v1.9.1/gin.go:576 +0x1b2
net/http.serverHandler.ServeHTTP({0x34a7060?}, {0x34a9ff8?, 0xc0007beb60?}, 0x6?)
        /usr/local/go/src/net/http/server.go:3137 +0x8e
net/http.(*conn).serve(0xc000397440, {0x34ac078, 0xc0002e4c60})
        /usr/local/go/src/net/http/server.go:2039 +0x5e8
created by net/http.(*Server).Serve in goroutine 1
        /usr/local/go/src/net/http/server.go:3285 +0x4b4

[ERR] 2024/04/03 - 14:03:25 | 2024040314032488907379974244809 | request: POST /v1/chat/completions 
[ERR] 2024/04/03 - 14:03:25 | 2024040314032488907379974244809 | request body: {

复现步骤 正常对话

预期结果

相关截图 如果没有的话,请删除此节。

songquanpeng commented 5 months ago

是最新版本吗?发生 panic 了这是

Linusp commented 5 months ago

我也遇到了这个问题,原因可能和你的不一样,说一下我解决的过程,供参考:

  1. 我最开始只领取了讯飞星火 v3.5 的免费额度,在 one-api 里添加渠道后,测试 v3.5 是没有问题的,但后来测试 v3.1 出现这个错,到控制台发现各个版本的模型的额度是分开的,所以建议你看一下你使用的模型版本是否有额度(在讯飞的后台看不是在 one-api 看),没额度讯飞会报错关掉连接,但它把错误信息都塞在数据字段里,所以 one-api 里也没有显示出来错误原因
  2. 后来我调用 v2 模型又报错,看了代码后发现 one-api 的实现里都会在调用参数里加 functions 字段(哪怕你没有想使用 functions 功能),而 v2 模型的接口是不支持这个参数的,参数里出现这个字段就报错,哪怕是没有值,所以建议看下你调用的是不是 v2,是的话换一个看看还报错不
bincooo commented 5 months ago

哦,我用的讯飞v2 试试3.5,先关闭了

songquanpeng commented 5 months ago

后来我调用 v2 模型又报错,看了代码后发现 one-api 的实现里都会在调用参数里加 functions 字段(哪怕你没有想使用 functions 功能),而 v2 模型的接口是不支持这个参数的,参数里出现这个字段就报错,哪怕是没有值,所以建议看下你调用的是不是 v2,是的话换一个看看还报错不

不对哦,我测试是 okay 的: image