Compare commits
3 Commits
899491e867
...
3af6f0a18d
Author | SHA1 | Date |
---|---|---|
Yiyang Kang | 3af6f0a18d | |
Yiyang Kang | 89ddf89052 | |
Yiyang Kang | ed46c2b274 |
2
bot.go
2
bot.go
|
@ -85,7 +85,7 @@ func logMiddleware(next tele.HandlerFunc) tele.HandlerFunc {
|
||||||
return func(c tele.Context) error {
|
return func(c tele.Context) error {
|
||||||
upd := c.Update()
|
upd := c.Update()
|
||||||
defer func() {
|
defer func() {
|
||||||
logger.Infow("Log middleware", "update", upd)
|
logger.Debugw("Log middleware", "update", upd)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return next(c)
|
return next(c)
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/samber/lo"
|
||||||
tele "gopkg.in/telebot.v3"
|
tele "gopkg.in/telebot.v3"
|
||||||
|
|
||||||
"git.gensokyo.cafe/kkyy/tgbot_misaka_5882f7/openai"
|
"git.gensokyo.cafe/kkyy/tgbot_misaka_5882f7/openai"
|
||||||
|
@ -48,7 +49,6 @@ func handleTranslateCmd(c tele.Context) error {
|
||||||
tele.Silent,
|
tele.Silent,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
logger.Infof("trimmed message: %q", payload)
|
|
||||||
|
|
||||||
_, err := c.Bot().Reply(msg, "Sure. To what language?", tele.Silent, translateMenu)
|
_, err := c.Bot().Reply(msg, "Sure. To what language?", tele.Silent, translateMenu)
|
||||||
return err
|
return err
|
||||||
|
@ -91,6 +91,7 @@ func handleTranslateBtn(c tele.Context) error {
|
||||||
Content: payload,
|
Content: payload,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Temperature: lo.ToPtr(0.6),
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := ai.ChatCompletion(req)
|
resp, err := ai.ChatCompletion(req)
|
||||||
|
|
1
cfg.go
1
cfg.go
|
@ -10,6 +10,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type ConfigDef struct {
|
type ConfigDef struct {
|
||||||
|
LogLevel string `env:"TG_LOG_LEVEL" env-default:"info"`
|
||||||
AdminUIDs []int64 `env:"TG_ADMIN_UIDS"`
|
AdminUIDs []int64 `env:"TG_ADMIN_UIDS"`
|
||||||
TGBotToken string `env:"TG_TOKEN" env-required:""`
|
TGBotToken string `env:"TG_TOKEN" env-required:""`
|
||||||
TGAnnounceCommands bool `env:"TG_ANNOUNCE_CMDS"`
|
TGAnnounceCommands bool `env:"TG_ANNOUNCE_CMDS"`
|
||||||
|
|
13
main.go
13
main.go
|
@ -7,6 +7,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
"go.uber.org/zap/zapcore"
|
||||||
tele "gopkg.in/telebot.v3"
|
tele "gopkg.in/telebot.v3"
|
||||||
|
|
||||||
"git.gensokyo.cafe/kkyy/mycurrencynet"
|
"git.gensokyo.cafe/kkyy/mycurrencynet"
|
||||||
|
@ -14,9 +15,13 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var logger *zap.SugaredLogger
|
var logger *zap.SugaredLogger
|
||||||
|
var loglvl zap.AtomicLevel
|
||||||
|
|
||||||
func initLogger() {
|
func initLogger() {
|
||||||
l, err := zap.NewProduction()
|
logCfg := zap.NewProductionConfig()
|
||||||
|
loglvl = logCfg.Level
|
||||||
|
|
||||||
|
l, err := logCfg.Build()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -89,6 +94,12 @@ func main() {
|
||||||
if err := LoadCfg(); err != nil {
|
if err := LoadCfg(); err != nil {
|
||||||
logger.Fatalw("Failed to load config", "err", err)
|
logger.Fatalw("Failed to load config", "err", err)
|
||||||
}
|
}
|
||||||
|
parsedLvl, err := zapcore.ParseLevel(config.LogLevel)
|
||||||
|
if err != nil {
|
||||||
|
logger.Warnf("Invalid log level %q", config.LogLevel)
|
||||||
|
} else {
|
||||||
|
loglvl.SetLevel(parsedLvl)
|
||||||
|
}
|
||||||
|
|
||||||
runBot()
|
runBot()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package prompts
|
package prompts
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
func General() string {
|
func General() string {
|
||||||
return "You are a helpful assistant."
|
return "You are a helpful assistant."
|
||||||
|
@ -8,7 +11,14 @@ func General() string {
|
||||||
|
|
||||||
func Translate(targetLang string) string {
|
func Translate(targetLang string) string {
|
||||||
return fmt.Sprintf(
|
return fmt.Sprintf(
|
||||||
"You are a helpful assistant. Your task is to help translate the following text to %s. You should not interpret the text. You should structure the translated text to look natural in native %s, while keeping the meaning unchanged.",
|
strings.Join([]string{
|
||||||
targetLang, targetLang,
|
"You are a helpful assistant.",
|
||||||
|
"Your task is to help translate the text sent by the user into %s.",
|
||||||
|
"You should never interpret the user's text, but only translate it.",
|
||||||
|
"You should structure the translated text to sound natural in native %s while keeping the meanings unchanged.",
|
||||||
|
"If the user's text contains only a single word, please also add a brief explanation in %s, of the meaning of the original word.",
|
||||||
|
"The first text to be translated is:",
|
||||||
|
}, " \n"),
|
||||||
|
targetLang, targetLang, targetLang,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue