This commit is contained in:
Liang Ding 2023-03-05 11:49:57 +08:00
parent ba400854b0
commit 69c18db9ed
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
4 changed files with 81 additions and 9 deletions

View file

@ -23,20 +23,32 @@ import (
"github.com/siyuan-note/siyuan/kernel/util"
)
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
}
sqlBlocks := sql.GetBlocks(ids)
buf := bytes.Buffer{}
for _, sqlBlock := range sqlBlocks {
buf.WriteString(sqlBlock.Content)
buf.WriteString("\n\n")
}
msg := buf.String()
msg := getBlocksContent(ids)
ret, _ = util.ChatGPTContinueWrite(msg, nil)
return
}
@ -56,3 +68,14 @@ func isOpenAIAPIEnabled() bool {
}
return true
}
func getBlocksContent(ids []string) string {
sqlBlocks := sql.GetBlocks(ids)
buf := bytes.Buffer{}
for _, sqlBlock := range sqlBlocks {
buf.WriteString(sqlBlock.Content)
buf.WriteString("\n\n")
}
return buf.String()
}