feat: auto translate and rewrite prompt for midjourney and stable-diffusion

This commit is contained in:
RockYang
2024-03-27 13:45:52 +08:00
parent 342b76f666
commit b5947545cb
18 changed files with 162 additions and 355 deletions

View File

@@ -6,6 +6,7 @@ import (
"math/rand"
"strings"
"time"
"unicode"
"golang.org/x/crypto/sha3"
)
@@ -94,6 +95,7 @@ func InterfaceToString(value interface{}) string {
return JsonEncode(value)
}
// CutWords 截取前 N 个单词
func CutWords(str string, num int) string {
// 按空格分割字符串为单词切片
words := strings.Fields(str)
@@ -105,3 +107,13 @@ func CutWords(str string, num int) string {
return str
}
}
// HasChinese 判断文本是否含有中文
func HasChinese(text string) bool {
for _, char := range text {
if unicode.Is(unicode.Scripts["Han"], char) {
return true
}
}
return false
}