From b0bf2907316e18160152ca7b3a1db025f1796aa7 Mon Sep 17 00:00:00 2001 From: liyp Date: Wed, 3 Jul 2024 17:01:00 +0800 Subject: [PATCH] =?UTF-8?q?fix(workers):=20=E4=BF=AE=E5=A4=8DAI=E5=9B=9E?= =?UTF-8?q?=E5=A4=8D=E5=88=87=E7=89=87=E8=B6=8A=E7=95=8C=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 由于在获取AI回复时错误地使用了字符串切片,导致当RawMsg为空或仅有一个字符时会出现越界错误。现在修正了索引的计算方法,确保在任何情况下都不会出现越界。 --- workers/ai.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/workers/ai.go b/workers/ai.go index 61c71d5..12d3dc2 100644 --- a/workers/ai.go +++ b/workers/ai.go @@ -127,7 +127,7 @@ func (a *AI) GetMsg() string { "role": "system", "content": PROMPT, }, - {"role": "user", "content": ask}}, + {"role": "user", "content": a.RawMsg[strings.Index(a.RawMsg, " ")+1:]}}, // "max_tokens": 200, "temperature": 0.7, }