Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 28 additions & 0 deletions Easydict/App/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -3599,6 +3599,34 @@
}
}
},
"ollama_rephrase" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Ollama Rephrase"
}
},
"sk" : {
"stringUnit" : {
"state" : "translated",
"value" : "Ollama Rephrase"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "Ollama 改写"
}
},
"zh-Hant" : {
"stringUnit" : {
"state" : "translated",
"value" : "Ollama 改寫"
}
}
}
},
"open_app_settings" : {
"extractionState" : "manual",
"localizations" : {
Expand Down
1 change: 1 addition & 0 deletions Easydict/Swift/Service/Model/QueryServiceFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ final class QueryServiceFactory: NSObject {
(.builtInAI, BuiltInAIService.self),
(.gemini, GeminiService.self),
(.ollama, OllamaService.self),
(.ollamaRephrase, OllamaRephraseService.self),
(.polishing, PolishingService.self),
(.summary, SummaryService.self),
(.customOpenAI, CustomOpenAIService.self),
Expand Down
48 changes: 48 additions & 0 deletions Easydict/Swift/Service/Ollama/OllamaService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,51 @@ class OllamaService: BaseOpenAIService {
return try await dataTask.value
}
}

// MARK: - OllamaRephraseService

@objc(EZOllamaRephraseService)
class OllamaRephraseService: OllamaService {
override var isSentenceEnabledByDefault: Bool {
false
}

override var isDictionaryEnabledByDefault: Bool {
false
}

override func name() -> String {
NSLocalizedString("ollama_rephrase", comment: "")
}

override func serviceType() -> ServiceType {
.ollamaRephrase
}

override func configurationListItems() -> Any {
StreamConfigurationView(
service: self,
showAPIKeySection: false,
showTranslationToggle: false,
showSentenceToggle: false,
showDictionaryToggle: false
)
}

override func chatMessageDicts(_ chatQuery: ChatQueryParam) -> [ChatMessage] {
if enableCustomPrompt {
return super.chatMessageDicts(chatQuery)
}

// Default Rephrase Prompts
let (text, sourceLanguage, _, _, _) = chatQuery.unpack()
let prompt = "Rephrase the following \(sourceLanguage.queryLanguageName) text to make it more natural and fluent: \"\"\"\(text)\"\"\""

let systemPrompt = "You are a writing assistant. Your task is to rephrase the provided text to improve its flow, vocabulary, and overall quality while keeping the original meaning intact. Only return the rephrased text."

return [
.init(role: .system, content: systemPrompt),
.init(role: .user, content: prompt),
]
}
}
1 change: 1 addition & 0 deletions Easydict/objc/Service/Model/EZEnumTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ FOUNDATION_EXPORT EZServiceType const EZServiceTypeGroq;
FOUNDATION_EXPORT EZServiceType const EZServiceTypeZhipu;
FOUNDATION_EXPORT EZServiceType const EZServiceTypeGitHub;
FOUNDATION_EXPORT EZServiceType const EZServiceTypeDoubao;
FOUNDATION_EXPORT EZServiceType const EZServiceTypeOllamaRephrase;

FOUNDATION_EXPORT NSString *const EZQueryTextTypeKey;
FOUNDATION_EXPORT NSString *const EZIntelligentQueryTextTypeKey;
Expand Down
1 change: 1 addition & 0 deletions Easydict/objc/Service/Model/EZEnumTypes.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
NSString *const EZServiceTypeZhipu = @"Zhipu";
NSString *const EZServiceTypeGitHub = @"GitHub";
NSString *const EZServiceTypeDoubao = @"Doubao";
NSString *const EZServiceTypeOllamaRephrase = @"OllamaRephrase";

NSString *const EZQueryTextTypeKey = @"QueryTextType";
NSString *const EZIntelligentQueryTextTypeKey = @"IntelligentQueryTextType";
Expand Down
Loading