Skip to content

Commit

Permalink
refractor: define static property for translation prompt
Browse files Browse the repository at this point in the history
Co-Authored-By: Kyle <[email protected]>
  • Loading branch information
Jerry23011 and Kyle-Ye committed Jan 4, 2024
1 parent 6170b9b commit 23f5f96
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Easydict/Feature/Service/Gemini/GeminiService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
Expand Down

0 comments on commit 23f5f96

Please sign in to comment.