This commit is contained in:
Liang Ding 2023-03-06 11:28:27 +08:00
parent 863df0a2e1
commit 6edcdf7d50
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
4 changed files with 68 additions and 0 deletions

View file

@ -89,3 +89,37 @@ func chatGPTSummary(c *gin.Context) {
}
ret.Data = model.ChatGPTSummary(ids)
}
func chatGPTBrainStorm(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)
arg, ok := util.JsonArg(c, ret)
if !ok {
return
}
idsArg := arg["ids"].([]interface{})
var ids []string
for _, id := range idsArg {
ids = append(ids, id.(string))
}
ret.Data = model.ChatGPTBrainStorm(ids)
}
func chatGPTFixGrammarSpell(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)
arg, ok := util.JsonArg(c, ret)
if !ok {
return
}
idsArg := arg["ids"].([]interface{})
var ids []string
for _, id := range idsArg {
ids = append(ids, id.(string))
}
ret.Data = model.ChatGPTFixGrammarSpell(ids)
}

View file

@ -332,4 +332,6 @@ func ServeAPI(ginServer *gin.Engine) {
ginServer.Handle("POST", "/api/ai/chatGPTContinueWriteBlocks", model.CheckAuth, chatGPTContinueWriteBlocks)
ginServer.Handle("POST", "/api/ai/chatGPTTranslate", model.CheckAuth, chatGPTTranslate)
ginServer.Handle("POST", "/api/ai/chatGPTSummary", model.CheckAuth, chatGPTSummary)
ginServer.Handle("POST", "/api/ai/chatGPTBrainStorm", model.CheckAuth, chatGPTBrainStorm)
ginServer.Handle("POST", "/api/ai/chatGPTFixGrammarSpell", model.CheckAuth, chatGPTFixGrammarSpell)
}

View file

@ -25,6 +25,26 @@ import (
"github.com/siyuan-note/siyuan/kernel/util"
)
func ChatGPTFixGrammarSpell(ids []string) (ret string) {
if !isOpenAIAPIEnabled() {
return
}
msg := getBlocksContent(ids)
ret = util.ChatGPTFixGrammarSpell(msg, Conf.Lang)
return
}
func ChatGPTBrainStorm(ids []string) (ret string) {
if !isOpenAIAPIEnabled() {
return
}
msg := getBlocksContent(ids)
ret = util.ChatGPTBrainStorm(msg, Conf.Lang)
return
}
func ChatGPTSummary(ids []string) (ret string) {
if !isOpenAIAPIEnabled() {
return

View file

@ -57,6 +57,18 @@ func ChatGPTSummary(msg string, lang string) (ret string) {
return
}
func ChatGPTBrainStorm(msg string, lang string) (ret string) {
msg = "Brainstorm ideas as follows, the result is in {" + lang + "}:\n" + msg
ret, _ = ChatGPTContinueWrite(msg, nil)
return
}
func ChatGPTFixGrammarSpell(msg string, lang string) (ret string) {
msg = "Fix grammar and spelling as follows, the result is in {" + lang + "}:\n" + msg
ret, _ = ChatGPTContinueWrite(msg, nil)
return
}
func ChatGPTContinueWrite(msg string, contextMsgs []string) (ret string, retContextMsgs []string) {
if "" == OpenAIAPIKey {
return