From 3cd1a6f850e1d039687fbdd3bf0f07c69c2ad1bf Mon Sep 17 00:00:00 2001 From: Jerry Date: Thu, 4 Jan 2024 12:57:43 -0800 Subject: [PATCH] refractor: define static property for translation prompt Co-Authored-By: Kyle --- Easydict/Feature/Service/Gemini/GeminiService.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Easydict/Feature/Service/Gemini/GeminiService.swift b/Easydict/Feature/Service/Gemini/GeminiService.swift index 5cfa988b0..6041e4c89 100644 --- a/Easydict/Feature/Service/Gemini/GeminiService.swift +++ b/Easydict/Feature/Service/Gemini/GeminiService.swift @@ -60,6 +60,8 @@ public final class GeminiService: QueryService { } } + private static let translationPrompt = "You are a translation expert proficient in various languages that can only translate text and cannot interpret it. You are able to accurately understand the meaning of proper nouns, idioms, metaphors, allusions or other obscure words in sentences and translate them into appropriate words by combining the context and language environment. The result of the translation should be natural and fluent, you can only return the translated text, do not show additional information and notes." + override public func autoConvertTraditionalChinese() -> Bool { true } @@ -69,7 +71,7 @@ public final class GeminiService: QueryService { // https://github.com/google/generative-ai-swift do { var resultString = "" - let prompt = "You are a translation expert proficient in various languages that can only translate text and cannot interpret it. You are able to accurately understand the meaning of proper nouns, idioms, metaphors, allusions or other obscure words in sentences and translate them into appropriate words by combining the context and language environment. The result of the translation should be natural and fluent, you can only return the translated text, do not show additional information and notes. Translate the following \(from.rawValue) text into \(to.rawValue): \(text)" + let prompt = GeminiService.translationPrompt + "Translate the following \(from.rawValue) text into \(to.rawValue): \(text)" print("gemini prompt: \(prompt)") let model = GenerativeModel(name: "gemini-pro", apiKey: apiKey) let outputContentStream = model.generateContentStream(prompt)