Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add new models for gemini translation #571

Merged
merged 36 commits into from
Jun 5, 2024
Merged
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
b189683
perf: update gemini package
Jerry23011 May 28, 2024
9661e35
feat: add new models for gemini translation
Jerry23011 May 28, 2024
6d2e66b
fix: type in openai service
Jerry23011 May 28, 2024
93fd77b
fix: type in ezconstkey annotation
Jerry23011 May 28, 2024
e32fa30
fix: type in a few files
Jerry23011 May 28, 2024
659fa9c
perf: update chatgpt link
Jerry23011 May 28, 2024
930e7e5
fix: build error
Jerry23011 May 28, 2024
a9b784e
perf: remove gemini keys in ezschemeparser
Jerry23011 May 28, 2024
53f7ada
format: add back empty line
Jerry23011 May 28, 2024
a13034a
Merge branch 'openai-type-fix' into gemini-update
Jerry23011 May 28, 2024
8df4ebb
perf: rename opanaiusagestatus to serviceusagestatus
Jerry23011 May 28, 2024
a0d3fa7
perf: remove queryTextType since gemini supports all type
Jerry23011 May 28, 2024
cff774a
perf: update xcstring state
Jerry23011 May 28, 2024
cc78117
perf: enable LLMStreamService to change models quickly
tisfeng May 28, 2024
8446f11
fix: typo in gemini service
Jerry23011 May 28, 2024
2d5b9ae
perf: support dictionary and sentence query
Jerry23011 May 28, 2024
e65b2f7
perf: implement results handle for gemini
Jerry23011 May 28, 2024
cbbda54
docs: update sponsor list
tisfeng May 29, 2024
6cd291e
Merge branch 'dev' into gemini-update
tisfeng May 29, 2024
7e6c7a6
perf: remove unused annotation
Jerry23011 May 29, 2024
ad879a4
perf: remove unused code
Jerry23011 May 29, 2024
fcde137
perf: implement systemInstruction and role/model prompt
Jerry23011 May 30, 2024
f6e92b7
perf: remove redundant code
Jerry23011 May 30, 2024
f26ec5c
fix: gemini stream ui
Jerry23011 May 30, 2024
b8bbbcd
Merge branch 'dev' into gemini-update
tisfeng May 31, 2024
e68b614
Merge branch 'dev' into gemini-update
tisfeng May 31, 2024
74d919d
perf: move promptContent to extension GeminiService
Jerry23011 Jun 2, 2024
f0c9bb2
Merge branch 'dev' into gemini-update
Jerry23011 Jun 2, 2024
9c8c34b
perf: optimize usage of handleResult
Jerry23011 Jun 2, 2024
adff638
perf: add bool argument to opt out LLM systemPrompt
Jerry23011 Jun 2, 2024
19c31d4
Merge branch 'dev' into gemini-update
tisfeng Jun 2, 2024
5c0082d
fix: use dict system prompt when querying a word
tisfeng Jun 3, 2024
6301f08
perf: add dynamic variable for gemini available models
Jerry23011 Jun 4, 2024
a6dcd5d
refactor: replace all AI const stored keys with dynamic variables
tisfeng Jun 4, 2024
22bf492
fix: gemini-1.0-pro model cannot use system instruction
tisfeng Jun 4, 2024
67a63f1
perf: change system prompt to user prompt for gemini-1.0-pro model
tisfeng Jun 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: use dict system prompt when querying a word
tisfeng committed Jun 3, 2024
commit 5c0082d3a0307c388d48a23252e6259afd8d6be1
3 changes: 2 additions & 1 deletion Easydict/Swift/Service/Gemini/GeminiService.swift
Original file line number Diff line number Diff line change
@@ -40,7 +40,8 @@ public final class GeminiService: LLMStreamService {

let queryType = queryType(text: text, from: from, to: to)
let translationPrompt = promptContent(queryType: queryType, text: text, from: from, to: to)
let systemInstruction = LLMStreamService.translationSystemPrompt
let systemInstruction = queryType == .dictionary ? LLMStreamService.dictSystemPrompt : LLMStreamService
.translationSystemPrompt
let model = GenerativeModel(
name: model,
apiKey: apiKey,
10 changes: 5 additions & 5 deletions Easydict/Swift/Service/OpenAI/Prompt.swift
Original file line number Diff line number Diff line change
@@ -15,6 +15,10 @@ extension LLMStreamService {
You are a translation expert proficient in various languages, focusing solely on translating text without interpretation. You accurately understand the meanings of proper nouns, idioms, metaphors, allusions, and other obscure words in sentences, translating them appropriately based on the context and language environment. The translation should be natural and fluent. Only return the translated text, without including redundant quotes or additional notes.
"""

static let dictSystemPrompt = """
You are a word search assistant skilled in multiple languages and knowledgeable in etymology. You can help search for words, phrases, slang, abbreviations, and other information. Prioritize queries from authoritative dictionary databases, such as the Oxford Dictionary, Cambridge Dictionary, and Wikipedia. If a word or abbreviation has multiple meanings, look up the most commonly used ones.
"""

func translationPrompt(text: String, from sourceLanguage: Language, to targetLanguage: Language) -> String {
"Translate the following \(sourceLanguage.queryLanguageName) text into \(targetLanguage.queryLanguageName) text: \"\"\"\(text)\"\"\""
}
@@ -537,10 +541,6 @@ extension LLMStreamService {

let sourceLanguageString = sourceLanguage.rawValue

let dictSystemPrompt = """
You are a word search assistant skilled in multiple languages and knowledgeable in etymology. You can help search for words, phrases, slang, abbreviations, and other information. Prioritize queries from authoritative dictionary databases, such as the Oxford Dictionary, Cambridge Dictionary, and Wikipedia. For Chinese words, use Baidu Baike. If a word or abbreviation has multiple meanings, look up the most commonly used ones.
"""

let answerLanguagePrompt = "Using \(answerLanguage.rawValue): \n"
prompt.append(answerLanguagePrompt)

@@ -842,7 +842,7 @@ extension LLMStreamService {
if systemPrompt {
[[
"role": "system",
"content": LLMStreamService.translationSystemPrompt,
"content": LLMStreamService.dictSystemPrompt,
]]
} else {
[]