Skip to content

Commit

Permalink
Merge branch 'dev' into fix/fake_window
Browse files Browse the repository at this point in the history
  • Loading branch information
AkaShark authored May 9, 2024
2 parents 34de914 + f5e9ec1 commit 0908480
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ disabled_rules:
- force_cast
- force_try
- large_tuple
- todo

opt_in_rules:
- convenience_type
Expand Down Expand Up @@ -68,4 +69,4 @@ excluded:
- "**/UNTESTED_TODO"
- "vendor"
- "fastlane"
- ".build"
- ".build"
1 change: 0 additions & 1 deletion Easydict/Swift/Service/Ali/AliService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class AliService: QueryService {
}

override public func supportLanguagesDictionary() -> MMOrderedDictionary<AnyObject, AnyObject> {
// TODO: Replace MMOrderedDictionary in the API
let orderedDict = MMOrderedDictionary<AnyObject, AnyObject>()
for (key, value) in AliTranslateType.supportLanguagesDictionary {
orderedDict.setObject(value as NSString, forKey: key.rawValue as NSString)
Expand Down
1 change: 1 addition & 0 deletions Easydict/Swift/Service/Gemini/GeminiService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Defaults
import Foundation
import GoogleGenerativeAI

// TODO: add a LLM stream service base class, make both OpenAI and Gemini inherit from it.
@objc(EZGeminiService)
public final class GeminiService: QueryService {
// MARK: Public
Expand Down
14 changes: 8 additions & 6 deletions Easydict/Swift/Service/OpenAI/BaseOpenAIService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public class BaseOpenAIService: QueryService {
) {
var normalResults: [String]?
if let resultText {
normalResults = [resultText.trimmingCharacters(in: .whitespacesAndNewlines)]
normalResults = [resultText.trim()]
}

result.isStreamFinished = error != nil
Expand Down Expand Up @@ -226,16 +226,18 @@ public class BaseOpenAIService: QueryService {
}

private func getFinalResultText(text: String) -> String {
// Since it is more difficult to accurately remove redundant quotes in streaming, we wait until the end of the request to remove the quotes
let nsText = text as NSString
var resultText = nsText.tryToRemoveQuotes()
var resultText = text

// Remove last </s>, fix Groq mixtral-8x7b-32768
// Remove last </s>, fix Groq model mixtral-8x7b-32768
let stopFlag = "</s>"
if !queryModel.queryText.hasSuffix(stopFlag), resultText.hasSuffix(stopFlag) {
resultText = String(resultText.dropLast(stopFlag.count))
resultText = String(resultText.dropLast(stopFlag.count)).trim()
}

// Since it is more difficult to accurately remove redundant quotes in streaming, we wait until the end of the request to remove the quotes
let nsText = resultText as NSString
resultText = nsText.tryToRemoveQuotes()

return resultText
}
}
2 changes: 0 additions & 2 deletions Easydict/Swift/Service/Tencent/TencentService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public final class TencentService: QueryService {
}

override public func supportLanguagesDictionary() -> MMOrderedDictionary<AnyObject, AnyObject> {
// swiftlint:disable:next todo
// TODO: Replace MMOrderedDictionary in the API
let orderedDict = MMOrderedDictionary<AnyObject, AnyObject>()
for (key, value) in TencentTranslateType.supportLanguagesDictionary {
orderedDict.setObject(value as NSString, forKey: key.rawValue as NSString)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ extension String {
func truncated(_ maxLength: Int = 200) -> String {
String(prefix(maxLength))
}

func trim() -> String {
trimmingCharacters(in: .whitespacesAndNewlines)
}
}

@objc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private class CustomOpenAIViewModel: ObservableObject {
guard let availableModels else { return }

validModels = availableModels.components(separatedBy: ",")
.map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }.filter { !$0.isEmpty }
.map { $0.trim() }.filter { !$0.isEmpty }

if validModels.isEmpty {
model = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private class OpenAIServiceViewModel: ObservableObject {
guard let availableModels else { return }

validModels = availableModels.components(separatedBy: ",")
.map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }.filter { !$0.isEmpty }
.map { $0.trim() }.filter { !$0.isEmpty }

if validModels.isEmpty {
model = ""
Expand Down
23 changes: 14 additions & 9 deletions Easydict/objc/ViewController/View/Titlebar/EZTitlebar.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,15 @@ - (void)setup {
self.buttonSize = CGSizeMake(self.buttonWidth, self.buttonWidth);
self.imageSize = CGSizeMake(self.imageWidth, self.imageWidth);

[self addSubview:self.pinButton];
[self addSubview:self.stackView];

NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
[defaultCenter addObserver:self selector:@selector(updateConstraints) name:EZQuickLinkButtonUpdateNotification object:nil];
[defaultCenter addObserver:self selector:@selector(updateConstraints) name:NSNotification.languagePreferenceChanged object:nil];
[defaultCenter addObserver:self selector:@selector(updateTitlebar) name:EZQuickLinkButtonUpdateNotification object:nil];
[defaultCenter addObserver:self selector:@selector(updateTitlebar) name:NSNotification.languagePreferenceChanged object:nil];
}

//- (void)update

- (void)updateConstraints {
- (void)updateTitlebar {
/**
Fix appcenter issue, seems cannot remove self.subviews 🤔
Expand All @@ -71,16 +72,21 @@ - (void)updateConstraints {
*/

// Remove and dealloc all views to refresh UI.

[_pinButton removeFromSuperview];
[_stackView removeFromSuperview];
_stackView = nil;
_quickActionButton = nil;

[self addSubview:self.pinButton];
[self updatePinButton];
[self quickActionMenu];

[self addSubview:self.pinButton];
[self addSubview:self.stackView];

[self setNeedsUpdateConstraints:YES];
}

- (void)updateConstraints {
CGFloat margin = EZHorizontalCellSpacing_10;
CGFloat topOffset = EZTitlebarHeight_28 - self.buttonWidth;

Expand All @@ -90,7 +96,6 @@ - (void)updateConstraints {
make.top.equalTo(self).offset(topOffset);
}];

[self addSubview:self.stackView];
[self.stackView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self).offset(topOffset);
make.right.equalTo(self).offset(-margin);
Expand Down

0 comments on commit 0908480

Please sign in to comment.