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 Polishing and Summary Features #609

Merged
merged 22 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c2b92c7
perf: add icons for polishing and grammar
Jerry23011 Jul 10, 2024
69cea17
fix: wrong icon placement
Jerry23011 Jul 10, 2024
b642f00
perf: setup base for grammar and polishing
Jerry23011 Jul 10, 2024
b915b16
Merge branch 'dev' into polishing-and-grammar
Jerry23011 Jul 11, 2024
cb76796
fix: missing files
Jerry23011 Jul 11, 2024
5c686a2
fix: wrong service name for summary
Jerry23011 Jul 11, 2024
5572131
perf: add LLMDerivService as the base of LLMDerivs
Jerry23011 Jul 12, 2024
fa6805e
feat: implement polishing and summary features
Jerry23011 Jul 12, 2024
f9e08ff
refactor: make AIToolService override method chatMessageDicts()
tisfeng Jul 12, 2024
0dfec44
perf: rename LLM Derivatives to AI Tools
Jerry23011 Jul 12, 2024
c4550ef
perf: remove unused code
Jerry23011 Jul 12, 2024
7d3518d
perf: improve prompts for text summary
Jerry23011 Jul 13, 2024
b145bfb
fix: extraneous prompt
Jerry23011 Jul 13, 2024
57cf75e
fix: use first preferred langauge to summarize text
tisfeng Jul 13, 2024
91ca4c0
feat: set AI tool service usage status to alway off by default
tisfeng Jul 13, 2024
0208daa
fix: add missing en localization
tisfeng Jul 14, 2024
593c934
Merge branch 'dev' into polishing-and-grammar
tisfeng Jul 14, 2024
881f9f0
fix: icon size for polishing and grammar service
Jerry23011 Jul 15, 2024
72ccb48
Merge branch 'polishing-and-grammar' of https://github.com/Jerry23011…
Jerry23011 Jul 15, 2024
b92453f
fix: format fewShots to conform to original prompt
Jerry23011 Jul 15, 2024
ab714a2
Merge branch 'dev' into polishing-and-grammar
tisfeng Jul 15, 2024
3931445
perf(UI): add new icon for summary service
Jerry23011 Jul 16, 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
20 changes: 20 additions & 0 deletions Easydict.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,10 @@
C415C0AD2B450D4800A9D231 /* GeminiService.swift in Sources */ = {isa = PBXBuildFile; fileRef = C415C0AC2B450D4800A9D231 /* GeminiService.swift */; };
C477BF912C0E2C61006A3F27 /* InfoPlist.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = C477BF902C0E2C61006A3F27 /* InfoPlist.xcstrings */; };
C490BF722BE910B70021E40A /* AdvancedTabItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C490BF712BE910B70021E40A /* AdvancedTabItemView.swift */; };
C4A512BE2C414A2400F00F33 /* AIToolService.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4A512BD2C414A2400F00F33 /* AIToolService.swift */; };
C4BFDD7A2BE61F550094026B /* Vortex in Frameworks */ = {isa = PBXBuildFile; productRef = C4BFDD792BE61F550094026B /* Vortex */; };
C4CCDAA32C407A0D00AC88BA /* SummaryService.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4CCDAA22C407A0D00AC88BA /* SummaryService.swift */; };
C4CCDAA52C407A4100AC88BA /* PolishingService.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4CCDAA42C407A4100AC88BA /* PolishingService.swift */; };
C4DD01E92B12B3C80025EE8E /* TencentService.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4DD01E82B12B3C80025EE8E /* TencentService.swift */; };
C4DD01EB2B12BA250025EE8E /* TencentResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4DD01EA2B12BA250025EE8E /* TencentResponse.swift */; };
C4DD01ED2B12BE9B0025EE8E /* TencentTranslateType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4DD01EC2B12BE9B0025EE8E /* TencentTranslateType.swift */; };
Expand Down Expand Up @@ -792,6 +795,9 @@
C415C0AC2B450D4800A9D231 /* GeminiService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeminiService.swift; sourceTree = "<group>"; };
C477BF902C0E2C61006A3F27 /* InfoPlist.xcstrings */ = {isa = PBXFileReference; lastKnownFileType = text.json.xcstrings; path = InfoPlist.xcstrings; sourceTree = "<group>"; };
C490BF712BE910B70021E40A /* AdvancedTabItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = AdvancedTabItemView.swift; path = Easydict/Swift/View/AdvancedTabItemView.swift; sourceTree = SOURCE_ROOT; };
C4A512BD2C414A2400F00F33 /* AIToolService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AIToolService.swift; sourceTree = "<group>"; };
C4CCDAA22C407A0D00AC88BA /* SummaryService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SummaryService.swift; sourceTree = "<group>"; };
C4CCDAA42C407A4100AC88BA /* PolishingService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PolishingService.swift; sourceTree = "<group>"; };
C4DD01E82B12B3C80025EE8E /* TencentService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TencentService.swift; sourceTree = "<group>"; };
C4DD01EA2B12BA250025EE8E /* TencentResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TencentResponse.swift; sourceTree = "<group>"; };
C4DD01EC2B12BE9B0025EE8E /* TencentTranslateType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TencentTranslateType.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1204,6 +1210,7 @@
0A9AFBA92B7F8D6A0064C9A8 /* CustomOpenAI */,
C415C0AB2B450C4500A9D231 /* Gemini */,
03792EA02C3830E60074A145 /* Ollama */,
C4D1ADE12C3F340500A19D02 /* AITool */,
C4DD01E72B12B3B00025EE8E /* Tencent */,
2746AEBF2AF95040005FE0A1 /* Caiyun */,
62E2BF462B4082BA00E42D38 /* Ali */,
Expand Down Expand Up @@ -2295,6 +2302,16 @@
name = "Recovered References";
sourceTree = "<group>";
};
C4D1ADE12C3F340500A19D02 /* AITool */ = {
isa = PBXGroup;
children = (
C4A512BD2C414A2400F00F33 /* AIToolService.swift */,
C4CCDAA42C407A4100AC88BA /* PolishingService.swift */,
C4CCDAA22C407A0D00AC88BA /* SummaryService.swift */,
);
path = AITool;
sourceTree = "<group>";
};
C4DD01E72B12B3B00025EE8E /* Tencent */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -2777,6 +2794,7 @@
962B9ACE2BFA03270080F4D4 /* EZAppModel.m in Sources */,
03BDA7C42A26DA280079D04F /* NSDictionary+RubyDescription.m in Sources */,
62ED29A22B15F1F500901F51 /* EZWrapView.m in Sources */,
C4CCDAA32C407A0D00AC88BA /* SummaryService.swift in Sources */,
C4DD01EB2B12BA250025EE8E /* TencentResponse.swift in Sources */,
036A0DB82AD8403A006E6D4F /* NSString+EZHandleInputText.m in Sources */,
03BDA7C12A26DA280079D04F /* XPMArgumentParser.m in Sources */,
Expand All @@ -2791,6 +2809,7 @@
03D0435A2928C4C800E7559E /* EZWindowManager.m in Sources */,
6295DE342A84EF76006145F4 /* EZBingLookupModel.m in Sources */,
03FD68BE2B1E151A00FD388E /* String+EncryptAES.swift in Sources */,
C4A512BE2C414A2400F00F33 /* AIToolService.swift in Sources */,
03B0230729231FA6001C7E63 /* EZCommonView.m in Sources */,
03B0233329231FA6001C7E63 /* MMLog.m in Sources */,
0AC8A8352B6641A7006DA5CC /* TencentService+ConfigurableService.swift in Sources */,
Expand Down Expand Up @@ -2853,6 +2872,7 @@
03E02A2629250D1D00A10260 /* EZEventMonitor.m in Sources */,
03B0233429231FA6001C7E63 /* MMConsoleLogFormatter.m in Sources */,
037852B9295D49F900D0E2CF /* EZTableRowView.m in Sources */,
C4CCDAA52C407A4100AC88BA /* PolishingService.swift in Sources */,
03779F0E2BB256A7008D3C42 /* OpenAIService.swift in Sources */,
033363A6293C4AFA00FED9C8 /* PrintBeautifulLog.m in Sources */,
039CC914292FB3180037B91E /* EZPopUpButton.m in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"images" : [
{
"filename" : "Polishing.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"images" : [
{
"filename" : "Grammar.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions Easydict/App/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -2002,6 +2002,22 @@
}
}
},
"polishing_service" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Polishing"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "润色"
}
}
}
},
"present_participle" : {
"localizations" : {
"en" : {
Expand Down Expand Up @@ -3834,6 +3850,16 @@
}
}
},
"summary_service" : {
"localizations" : {
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "总结"
tisfeng marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
},
"superlative" : {
"localizations" : {
"en" : {
Expand Down
36 changes: 36 additions & 0 deletions Easydict/Swift/Service/AITool/AIToolService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// AIToolService.swift
// Easydict
//
// Created by Jerry on 2024-07-12.
// Copyright © 2024 izual. All rights reserved.
//

import Defaults
import Foundation

/// A class used for AI Tools such as summary and polishing
class AIToolService: BuiltInAIService {
// MARK: Public

public override func configurationListItems() -> Any {
StreamConfigurationView(
service: self,
showNameSection: false,
showAPIKeySection: false,
showEndpointSection: false,
showSupportedModelsSection: false,
showUsedModelSection: false,
showTranslationToggle: false,
showSentenceToggle: false,
showDictionaryToggle: false,
showUsageStatusPicker: true
)
}

// MARK: Internal

override var serviceUsageStatusKey: Defaults.Key<ServiceUsageStatus> {
serviceDefaultsKey(.serviceUsageStatus, defaultValue: .alwaysOff)
}
}
29 changes: 29 additions & 0 deletions Easydict/Swift/Service/AITool/PolishingService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// PolishingService.swift
// Easydict
//
// Created by Jerry on 2024-07-11.
// Copyright © 2024 izual. All rights reserved.
//

import Foundation
import OpenAI

@objc(EZPolishingService)
class PolishingService: AIToolService {
// MARK: Public

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

public override func serviceType() -> ServiceType {
.polishing
}

// MARK: Internal

override func chatMessageDicts(_ chatQuery: ChatQueryParam) -> [[String: String]] {
polishingMessages(chatQuery)
}
}
29 changes: 29 additions & 0 deletions Easydict/Swift/Service/AITool/SummaryService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// SummaryService.swift
// Easydict
//
// Created by Jerry on 2024-07-11.
// Copyright © 2024 izual. All rights reserved.
//

import Foundation
import OpenAI

@objc(EZSummaryService)
class SummaryService: AIToolService {
// MARK: Public

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

public override func serviceType() -> ServiceType {
.summary
}

// MARK: Internal

override func chatMessageDicts(_ chatQuery: ChatQueryParam) -> [[String: String]] {
summaryMessages(chatQuery)
}
}
12 changes: 12 additions & 0 deletions Easydict/Swift/Service/OpenAI/LLMStreamService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,18 @@ public class LLMStreamService: QueryService {
fatalError(mustOverride)
}

func chatMessageDicts(_ chatQuery: ChatQueryParam)
-> [[String: String]] {
switch chatQuery.queryType {
case .dictionary:
dictMessages(chatQuery)
case .sentence:
sentenceMessages(chatQuery)
default:
translationMessages(chatQuery)
}
}

func getFinalResultText(_ text: String) -> String {
var resultText = text.trim()

Expand Down
Loading