feat: adjust prompt for translation

This commit is contained in:
Yiyang Kang 2023-03-08 04:25:20 +08:00
parent 899491e867
commit ed46c2b274
2 changed files with 15 additions and 3 deletions

View File

@ -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"
@ -91,6 +92,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)

View File

@ -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,
) )
} }