Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: AI DeepSeek 422 Unprocessable Entity https://github.com/siyuan-note/siyuan/issues/14347

Daniel42c0461e3d21
diff --git a/kernel/model/ai.go b/kernel/model/ai.go
index 4b48ad1714..c4cf9d99b1 100644
--- a/kernel/model/ai.go
+++ b/kernel/model/ai.go
@@ -109,7 +109,9 @@ func chatGPTContinueWrite(msg string, contextMsgs []string, cloud bool) (ret str
ret = buf.String()
ret = strings.TrimSpace(ret)
- retContextMsgs = append(retContextMsgs, msg, ret)
+ if "" != ret {
+ retContextMsgs = append(retContextMsgs, msg, ret)
+ }
return
}
diff --git a/kernel/util/openai.go b/kernel/util/openai.go
index bb248ee864..f38606eea8 100644
--- a/kernel/util/openai.go
+++ b/kernel/util/openai.go
@@ -31,15 +31,27 @@ func ChatGPT(msg string, contextMsgs []string, c *openai.Client, model string, m
var reqMsgs []openai.ChatCompletionMessage
for _, ctxMsg := range contextMsgs {
+ if "" == ctxMsg {
+ continue
+ }
+
reqMsgs = append(reqMsgs, openai.ChatCompletionMessage{
Role: "user",
Content: ctxMsg,
})
}
- reqMsgs = append(reqMsgs, openai.ChatCompletionMessage{
- Role: "user",
- Content: msg,
- })
+
+ if "" != msg {
+ reqMsgs = append(reqMsgs, openai.ChatCompletionMessage{
+ Role: "user",
+ Content: msg,
+ })
+ }
+
+ if 1 > len(reqMsgs) {
+ stop = true
+ return
+ }
req := openai.ChatCompletionRequest{
Model: model,