From bb58ebdf70a4bb3bfdaff4d56cba1299f98d3c91 Mon Sep 17 00:00:00 2001 From: Kelvin Chiu Date: Fri, 29 Sep 2023 18:52:15 +0800 Subject: [PATCH] fix: update query response (#661) --- controllers/util.go | 39 +++++++++++++-------------------------- object/message_ai.go | 4 ++-- 2 files changed, 15 insertions(+), 28 deletions(-) diff --git a/controllers/util.go b/controllers/util.go index 1098db7..0e5e3f9 100644 --- a/controllers/util.go +++ b/controllers/util.go @@ -146,34 +146,21 @@ func (c *Cleaner) GetCleanedData() string { } func cleanString(data string) string { - keywords := []string{ - "Answer:", - "answer:", - "A:", - "Question:", - "question:", - "Q:", - "?\n", - "?\n", - "\n?", - "\n?", - "? ", - "\n", - "回答:", - "答案:", - "答:", - "回答:", - "答案:", - "答:", - "?", - "?", - "-", - "——", + data = strings.Replace(data, "?", "", -1) + data = strings.Replace(data, "?", "", -1) + + data = strings.Replace(data, "-", "", -1) + data = strings.Replace(data, "——", "", -1) + + if strings.Contains(data, ":") { + parts := strings.Split(data, ":") + data = parts[len(parts)-1] + } else if strings.Contains(data, ":") { + parts := strings.Split(data, ":") + data = parts[len(parts)-1] } - for _, keyword := range keywords { - data = strings.ReplaceAll(data, keyword, "") - } + data = strings.TrimSpace(data) return data } diff --git a/object/message_ai.go b/object/message_ai.go index 37767ce..1b7ec90 100644 --- a/object/message_ai.go +++ b/object/message_ai.go @@ -27,7 +27,7 @@ func GetRefinedQuestion(knowledge string, question string) string { Now, please answer the following question based on the provided information: -Question: %s (Please answer directly, without using phrases like "the answer is" or "the question is") +%s -Important Note: The content may be in a different language from the question, so make sure to understand the context and provide your response in the language of the question.`, knowledge, question) +(Please answer directly in the questioner's language without using phrases like "the answer is" or "the question is."")`, knowledge, question) }