Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
823a90767b
9 changed files with 16 additions and 140 deletions
|
@ -11,6 +11,7 @@
|
|||
"aiTranslate_de_DE": "German",
|
||||
"aiBrainStorm": "Brainstorm",
|
||||
"aiFixGrammarSpell": "Fix grammar and spelling",
|
||||
"aiCustomAction": "Custom action...",
|
||||
"attributeView": "Attribute View",
|
||||
"mgmt": "Management",
|
||||
"spaceRepetition": "Spaced Repetition",
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
"aiTranslate_de_DE": "Alemán",
|
||||
"aiBrainStorm": "Lluvia de ideas",
|
||||
"aiFixGrammarSpell": "Corregir gramática y ortografía",
|
||||
"aiCustomAction": "Acción personalizada...",
|
||||
"attributeView": "Vista de atributos",
|
||||
"mgmt": "Administración",
|
||||
"spaceRepetition": "Repetición Espaciada",
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
"aiTranslate_de_DE": "Allemand",
|
||||
"aiBrainStorm": "Remue-méninges",
|
||||
"aiFixGrammarSpell": "Corrige la grammaire et l'orthographe",
|
||||
"aiCustomAction": "Action personnalisée...",
|
||||
"attributeView": "Vista de atributos",
|
||||
"mgmt": "Gestion",
|
||||
"spaceRepetition": "Répétition espacée",
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
"aiTranslate_de_DE": "德文",
|
||||
"aiBrainStorm": "頭腦風暴",
|
||||
"aiFixGrammarSpell": "修正語法和拼寫",
|
||||
"aiCustomAction": "自定義操作...",
|
||||
"attributeView": "屬性視圖",
|
||||
"mgmt": "管理",
|
||||
"spaceRepetition": "間隔重複",
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
"aiTranslate_de_DE": "德文",
|
||||
"aiBrainStorm": "头脑风暴",
|
||||
"aiFixGrammarSpell": "修正语法和拼写",
|
||||
"aiCustomAction": "自定义操作...",
|
||||
"attributeView": "属性视图",
|
||||
"mgmt": "管理",
|
||||
"spaceRepetition": "间隔重复",
|
||||
|
|
|
@ -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)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -121,10 +81,11 @@ func getBlocksContent(ids []string) string {
|
|||
}
|
||||
}
|
||||
|
||||
luteEngine := util.NewLute()
|
||||
buf := bytes.Buffer{}
|
||||
for _, node := range nodes {
|
||||
content := treenode.NodeStaticContent(node, nil, true)
|
||||
buf.WriteString(content)
|
||||
md := treenode.ExportNodeStdMd(node, luteEngine)
|
||||
buf.WriteString(md)
|
||||
buf.WriteString("\n\n")
|
||||
}
|
||||
return buf.String()
|
||||
|
|
|
@ -45,26 +45,8 @@ 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) (ret string) {
|
||||
msg = action + ":\n\n" + msg
|
||||
ret, _ = ChatGPTContinueWrite(msg, nil)
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue