This commit is contained in:
parent
dd3c011736
commit
3446462184
4 changed files with 11 additions and 138 deletions
|
@ -38,7 +38,7 @@ func chatGPT(c *gin.Context) {
|
|||
ret.Data = model.ChatGPT(msg)
|
||||
}
|
||||
|
||||
func chatGPTContinueWriteBlocks(c *gin.Context) {
|
||||
func chatGPTWithAction(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
||||
|
@ -52,74 +52,6 @@ func chatGPTContinueWriteBlocks(c *gin.Context) {
|
|||
for _, id := range idsArg {
|
||||
ids = append(ids, id.(string))
|
||||
}
|
||||
ret.Data = model.ChatGPTContinueWriteBlocks(ids)
|
||||
}
|
||||
|
||||
func chatGPTTranslate(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))
|
||||
}
|
||||
lang := arg["lang"].(string)
|
||||
ret.Data = model.ChatGPTTranslate(ids, lang)
|
||||
}
|
||||
|
||||
func chatGPTSummary(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.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)
|
||||
action := arg["action"].(string)
|
||||
ret.Data = model.ChatGPTWithAction(ids, action)
|
||||
}
|
||||
|
|
|
@ -329,9 +329,5 @@ func ServeAPI(ginServer *gin.Engine) {
|
|||
ginServer.Handle("POST", "/api/av/renderAttributeView", model.CheckAuth, renderAttributeView)
|
||||
|
||||
ginServer.Handle("POST", "/api/ai/chatGPT", model.CheckAuth, chatGPT)
|
||||
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)
|
||||
ginServer.Handle("POST", "/api/ai/chatGPTWithAction", model.CheckAuth, chatGPTWithAction)
|
||||
}
|
||||
|
|
|
@ -25,53 +25,13 @@ import (
|
|||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
||||
func ChatGPTFixGrammarSpell(ids []string) (ret string) {
|
||||
func ChatGPTWithAction(ids []string, action 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
|
||||
}
|
||||
|
||||
msg := getBlocksContent(ids)
|
||||
ret = util.ChatGPTSummary(msg, Conf.Lang)
|
||||
return
|
||||
}
|
||||
|
||||
func ChatGPTTranslate(ids []string, lang string) (ret string) {
|
||||
if !isOpenAIAPIEnabled() {
|
||||
return
|
||||
}
|
||||
|
||||
msg := getBlocksContent(ids)
|
||||
ret = util.ChatGPTTranslate(msg, lang)
|
||||
return
|
||||
}
|
||||
|
||||
func ChatGPTContinueWriteBlocks(ids []string) (ret string) {
|
||||
if !isOpenAIAPIEnabled() {
|
||||
return
|
||||
}
|
||||
|
||||
msg := getBlocksContent(ids)
|
||||
ret, _ = util.ChatGPTContinueWrite(msg, nil)
|
||||
ret = util.ChatGPTWithAction(msg, action, Conf.Lang)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -45,26 +45,11 @@ func ChatGPT(msg string) (ret string) {
|
|||
return
|
||||
}
|
||||
|
||||
func ChatGPTTranslate(msg string, lang string) (ret string) {
|
||||
msg = "Translate to " + lang + ":\n" + msg
|
||||
ret, _ = ChatGPTContinueWrite(msg, nil)
|
||||
return
|
||||
}
|
||||
|
||||
func ChatGPTSummary(msg string, lang string) (ret string) {
|
||||
msg = "Summarized as follows, the result is in {" + lang + "}:\n" + msg
|
||||
ret, _ = ChatGPTContinueWrite(msg, nil)
|
||||
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
|
||||
func ChatGPTWithAction(msg string, action string, lang string) (ret string) {
|
||||
prompt := "{action} as follows, the result is in {lang}:\n"
|
||||
prompt = strings.Replace(prompt, "{action}", action, -1)
|
||||
prompt = strings.Replace(prompt, "{lang}", lang, -1)
|
||||
msg = prompt + msg
|
||||
ret, _ = ChatGPTContinueWrite(msg, nil)
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue