From ed46c2b274e245947dc8b55ffb9154011731c1f5 Mon Sep 17 00:00:00 2001 From: Yiyang Kang Date: Wed, 8 Mar 2023 04:25:20 +0800 Subject: [PATCH] feat: adjust prompt for translation --- botcmd_translate.go | 2 ++ openai/prompts/prompts.go | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/botcmd_translate.go b/botcmd_translate.go index 82a38b2..5c45e89 100644 --- a/botcmd_translate.go +++ b/botcmd_translate.go @@ -4,6 +4,7 @@ import ( "regexp" "strings" + "github.com/samber/lo" tele "gopkg.in/telebot.v3" "git.gensokyo.cafe/kkyy/tgbot_misaka_5882f7/openai" @@ -91,6 +92,7 @@ func handleTranslateBtn(c tele.Context) error { Content: payload, }, }, + Temperature: lo.ToPtr(0.6), } resp, err := ai.ChatCompletion(req) diff --git a/openai/prompts/prompts.go b/openai/prompts/prompts.go index 43f5ef5..d0e74df 100644 --- a/openai/prompts/prompts.go +++ b/openai/prompts/prompts.go @@ -1,6 +1,9 @@ package prompts -import "fmt" +import ( + "fmt" + "strings" +) func General() string { return "You are a helpful assistant." @@ -8,7 +11,14 @@ func General() string { func Translate(targetLang string) string { 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.", - targetLang, targetLang, + strings.Join([]string{ + "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, ) }