From 9b58013c649727d28fad19e151f1fb6b0f304646 Mon Sep 17 00:00:00 2001 From: Jerry <89069957+Jerry23011@users.noreply.github.com> Date: Tue, 9 Jan 2024 17:56:43 -0800 Subject: [PATCH] perf: change min version back to 11.0 --- Easydict.xcodeproj/project.pbxproj | 4 ++-- .../xcshareddata/swiftpm/Package.resolved | 4 ++-- .../Service/Gemini/GeminiService.swift | 23 ++++++++++++++----- .../EZDeviceSystemInfo/EZDeviceSystemInfo.m | 2 +- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/Easydict.xcodeproj/project.pbxproj b/Easydict.xcodeproj/project.pbxproj index 369014f64..cfd16a738 100644 --- a/Easydict.xcodeproj/project.pbxproj +++ b/Easydict.xcodeproj/project.pbxproj @@ -3068,7 +3068,7 @@ "$(inherited)", "@executable_path/../Frameworks", ); - MACOSX_DEPLOYMENT_TARGET = 12.0; + MACOSX_DEPLOYMENT_TARGET = 11.0; MARKETING_VERSION = 2.5.0; PRODUCT_BUNDLE_IDENTIFIER = "com.izual.Easydict-debug"; PRODUCT_MODULE_NAME = Easydict; @@ -3108,7 +3108,7 @@ "$(inherited)", "@executable_path/../Frameworks", ); - MACOSX_DEPLOYMENT_TARGET = 12.0; + MACOSX_DEPLOYMENT_TARGET = 11.0; MARKETING_VERSION = 2.5.0; PRODUCT_BUNDLE_IDENTIFIER = com.izual.Easydict; PRODUCT_MODULE_NAME = Easydict; diff --git a/Easydict.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Easydict.xcworkspace/xcshareddata/swiftpm/Package.resolved index ab1d2872c..e9b665a3d 100644 --- a/Easydict.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Easydict.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -68,8 +68,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/google/generative-ai-swift", "state" : { - "revision" : "fead3038a70047a72ea2cf39e96d3add71c372de", - "version" : "0.4.4" + "revision" : "5cf2aae0f4d04b77fe7b2110da1145462ff92b84", + "version" : "0.4.6" } }, { diff --git a/Easydict/Feature/Service/Gemini/GeminiService.swift b/Easydict/Feature/Service/Gemini/GeminiService.swift index 3d9eb13e0..2c510b4fc 100644 --- a/Easydict/Feature/Service/Gemini/GeminiService.swift +++ b/Easydict/Feature/Service/Gemini/GeminiService.swift @@ -75,25 +75,36 @@ public final class GeminiService: QueryService { override public func translate(_ text: String, from: Language, to: Language, completion: @escaping (EZQueryResult, Error?) -> Void) { Task { - // https://github.com/google/generative-ai-swift do { var resultString = "" 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) - // stream response - for try await outputContent in outputContentStream { + if #available(macOS 12.0, *) { + let outputContentStream = model.generateContentStream(prompt) + + // stream response + for try await outputContent in outputContentStream { + guard let line = outputContent.text else { + return + } + + print("gemini response: \(line)") + resultString += line + } + } else { + let outputContent = try await model.generateContent(prompt) guard let line = outputContent.text else { return } print("gemini response: \(line)") resultString += line - result.translatedResults = [resultString] - completion(result, nil) } + + result.translatedResults = [resultString] + completion(result, nil) } catch { print(error.localizedDescription) completion(result, error) diff --git a/Easydict/Feature/Utility/EZDeviceSystemInfo/EZDeviceSystemInfo.m b/Easydict/Feature/Utility/EZDeviceSystemInfo/EZDeviceSystemInfo.m index 148da924f..79e11eb56 100644 --- a/Easydict/Feature/Utility/EZDeviceSystemInfo/EZDeviceSystemInfo.m +++ b/Easydict/Feature/Utility/EZDeviceSystemInfo/EZDeviceSystemInfo.m @@ -57,7 +57,7 @@ + (NSString *)getDeviceModel { /// Get device UUID, 4F07896A-1580-5270-A0E8-D7FA9DFA6868 + (NSString *)getDeviceUUID { - io_service_t platformExpert = IOServiceGetMatchingService(kIOMainPortDefault, IOServiceMatching("IOPlatformExpertDevice")); + io_service_t platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice")); CFStringRef uuidString = (CFStringRef)IORegistryEntryCreateCFProperty(platformExpert, CFSTR("IOPlatformUUID"), kCFAllocatorDefault, 0); NSString *uuid = (__bridge NSString *)(uuidString); IOObjectRelease(platformExpert);