Skip to content

Commit

Permalink
1. delete Gemini; 2. extend max chat rounds
Browse files Browse the repository at this point in the history
  • Loading branch information
sakeven committed Feb 26, 2025
1 parent c413b20 commit aae4ccb
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 117 deletions.
4 changes: 0 additions & 4 deletions Selected.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
38CC18B62B9C7B7C0023DF18 /* PopBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38CC18B52B9C7B7C0023DF18 /* PopBarView.swift */; };
38CC554C2BA9B6E900069553 /* RunCommandAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38CC554B2BA9B6E900069553 /* RunCommandAction.swift */; };
38DEBE322B9D67F800CD2A35 /* OpenAI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38DEBE312B9D67F800CD2A35 /* OpenAI.swift */; };
38DEBE342B9DD7CA00CD2A35 /* Gemini.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38DEBE332B9DD7CA00CD2A35 /* Gemini.swift */; };
38DEBE372B9DD80300CD2A35 /* GoogleGenerativeAI in Frameworks */ = {isa = PBXBuildFile; productRef = 38DEBE362B9DD80300CD2A35 /* GoogleGenerativeAI */; };
38DEBE392B9DDD0500CD2A35 /* AI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38DEBE382B9DDD0500CD2A35 /* AI.swift */; };
38DF1D4A2BB7A3BC0063A879 /* Option.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38DF1D492BB7A3BC0063A879 /* Option.swift */; };
Expand Down Expand Up @@ -168,7 +167,6 @@
38CC18B52B9C7B7C0023DF18 /* PopBarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PopBarView.swift; sourceTree = "<group>"; };
38CC554B2BA9B6E900069553 /* RunCommandAction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RunCommandAction.swift; sourceTree = "<group>"; };
38DEBE312B9D67F800CD2A35 /* OpenAI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpenAI.swift; sourceTree = "<group>"; };
38DEBE332B9DD7CA00CD2A35 /* Gemini.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Gemini.swift; sourceTree = "<group>"; };
38DEBE382B9DDD0500CD2A35 /* AI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AI.swift; sourceTree = "<group>"; };
38DF1D492BB7A3BC0063A879 /* Option.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Option.swift; sourceTree = "<group>"; };
38DF1D4C2BB94DCD0063A879 /* ApplicationSettingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApplicationSettingView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -380,7 +378,6 @@
isa = PBXGroup;
children = (
38DEBE312B9D67F800CD2A35 /* OpenAI.swift */,
38DEBE332B9DD7CA00CD2A35 /* Gemini.swift */,
38DEBE382B9DDD0500CD2A35 /* AI.swift */,
38230CA22BA1DBA8002A52E9 /* Utils.swift */,
38E20A4A2BB5A7E20035A3AA /* TTS.swift */,
Expand Down Expand Up @@ -602,7 +599,6 @@
3860106F2C425CD600EB9AE7 /* Claude.swift in Sources */,
3860105A2C2FA07600EB9AE7 /* MessageViewModel.swift in Sources */,
386010682C3AE24000EB9AE7 /* Template.swift in Sources */,
38DEBE342B9DD7CA00CD2A35 /* Gemini.swift in Sources */,
3888D8032BA8615900A7B75D /* IconImage.swift in Sources */,
38049D632B9DF8EA00E02ECA /* FloatingPanel.swift in Sources */,
386AD74E2B8F7A16008C346D /* MenuItemView.swift in Sources */,
Expand Down
12 changes: 2 additions & 10 deletions Selected/Service/AI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@ struct Translation {
let OpenAITrans2Chinese = OpenAIPrompt(prompt:"你是一位精通简体中文的专业翻译。翻译指定的内容到中文。规则:请直接回复翻译后的内容。内容为:{selected.text}", model: Defaults[.openAITranslationModel])
await OpenAITrans2Chinese.chatOne(selectedText: content, completion: completion)
}
case "Gemini":
if isWord(str: content) {
await GeminiWordTrans.chatOne(selectedText: content, completion: completion)
} else {
await GeminiTrans2Chinese.chatOne(selectedText: content, completion: completion)
}
case "Claude":
if isWord(str: content) {
await ClaudeWordTrans.chatOne(selectedText: content, completion: completion)
Expand All @@ -78,8 +72,6 @@ struct Translation {
case "OpenAI":
let OpenAITrans2English = OpenAIPrompt(prompt:"You are a professional translator proficient in English. Translate the following content into English. Rule: reply with the translated content directly. The content is:{selected.text}", model: Defaults[.openAITranslationModel])
await OpenAITrans2English.chatOne(selectedText: content, completion: completion)
case "Gemini":
await GeminiTrans2English.chatOne(selectedText: content, completion: completion)
case "Claude":
await ClaudeTrans2English.chatOne(selectedText: content, completion: completion)
default:
Expand All @@ -99,8 +91,6 @@ struct ChatService: AIChatService{
switch Defaults[.aiService] {
case "OpenAI":
chatService = OpenAIService(prompt: prompt, options: options)
case "Gemini":
chatService = GeminiPrompt(prompt: prompt, options: options)
case "Claude":
chatService = ClaudeService(prompt: prompt, options: options)
default:
Expand Down Expand Up @@ -241,3 +231,5 @@ func openSVGInBrowser(svgData: String) -> Bool {
return false
}
}

let MAX_CHAT_ROUNDS = 20
4 changes: 2 additions & 2 deletions Selected/Service/Claude.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class ClaudeService: AIChatService{
completion(newIndex, message)
return
}
if newIndex-index >= 10 {
if newIndex-index >= MAX_CHAT_ROUNDS {
newIndex += 1
let localMsg = NSLocalizedString("Too much rounds, please start a new chat", comment: "system info")
let message = ResponseMessage(message: localMsg, role: .system, new: true, status:.failure)
Expand All @@ -133,7 +133,7 @@ class ClaudeService: AIChatService{
completion(index, message)
return
}
if index >= 10 {
if index >= MAX_CHAT_ROUNDS {
index += 1
let localMsg = NSLocalizedString("Too much rounds, please start a new chat", comment: "system info")
let message = ResponseMessage(message: localMsg, role: .system, new: true, status:.failure)
Expand Down
78 changes: 0 additions & 78 deletions Selected/Service/Gemini.swift

This file was deleted.

4 changes: 2 additions & 2 deletions Selected/Service/OpenAI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ struct OpenAIPrompt {
completion(index, message)
return
}
if index >= 10 {
if index >= MAX_CHAT_ROUNDS {
index += 1
let localMsg = NSLocalizedString("Too much rounds, please start a new chat", comment: "system info")
let message = ResponseMessage(message: localMsg, role: .system, new: true, status: .failure)
Expand All @@ -225,7 +225,7 @@ struct OpenAIPrompt {
completion(newIndex, message)
return
}
if newIndex-index >= 10 {
if newIndex-index >= MAX_CHAT_ROUNDS {
newIndex += 1
let localMsg = NSLocalizedString("Too much rounds, please start a new chat", comment: "system info")
let message = ResponseMessage(message: localMsg, role: .system, new: true, status: .failure)
Expand Down
44 changes: 24 additions & 20 deletions Selected/View/ClipView/ClipView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import PDFKit

struct ClipDataView: View {
var data: ClipHistoryData

var body: some View {
VStack(alignment: .leading){
let item = data.getItems().first!
Expand All @@ -31,17 +31,17 @@ struct ClipDataView: View {
} else if data.plainText != nil {
TextView(text: data.plainText!)
}

Spacer()
Divider()

HStack {
Text("Application:")
Spacer()
getIcon(data.application!)
Text(getAppName(data.application!))
}.frame(height: 17)

HStack {
Text("Content type:")
Spacer()
Expand All @@ -52,13 +52,13 @@ struct ClipDataView: View {
Text(NSLocalizedString(str, comment: ""))
}
}.frame(height: 17)

HStack {
Text("Date:")
Spacer()
Text("\(format(data.firstCopiedAt!))")
}.frame(height: 17)

if data.numberOfCopies > 1 {
HStack {
Text("Last copied:")
Expand All @@ -71,7 +71,7 @@ struct ClipDataView: View {
Text("\(data.numberOfCopies) times")
}.frame(height: 17)
}

if let url = data.url {
if type == .fileURL {
let url = URL(string: String(decoding: item.data!, as: UTF8.self))!
Expand All @@ -92,14 +92,18 @@ struct ClipDataView: View {
}
}.padding().frame(width: 550)
}

private func getAppName(_ bundleID: String) -> String {
let bundleURL = NSWorkspace.shared.urlForApplication(withBundleIdentifier: bundleID)!
guard let bundleURL = NSWorkspace.shared.urlForApplication(withBundleIdentifier: bundleID) else {
return "Unknown"
}
return FileManager.default.displayName(atPath: bundleURL.path)
}

private func getIcon(_ bundleID: String) -> some View {
let bundleURL = NSWorkspace.shared.urlForApplication(withBundleIdentifier: bundleID)!
guard let bundleURL = NSWorkspace.shared.urlForApplication(withBundleIdentifier: bundleID) else{
return AnyView(EmptyView())
}
return AnyView(
Image(nsImage: NSWorkspace.shared.icon(forFile: bundleURL.path)).resizable().aspectRatio(contentMode: .fit).frame(width: 15, height: 15)
)
Expand All @@ -117,11 +121,11 @@ func isValidHttpUrl(_ string: String) -> Bool {
guard let url = URL(string: string) else {
return false
}

guard let scheme = url.scheme, scheme == "http" || scheme == "https" else {
return false
}

return url.host != nil
}

Expand All @@ -135,14 +139,14 @@ class ClipViewModel: ObservableObject {

struct ClipView: View {
@Environment(\.managedObjectContext) private var viewContext

// 维护一个 FetchRequest 实例
@FetchRequest(
sortDescriptors: [NSSortDescriptor(keyPath: \ClipHistoryData.lastCopiedAt, ascending: false)],
animation: .default)
private var clips: FetchedResults<ClipHistoryData>


// 默认选择第一条,必须同时设置 List 和 NavigationLink 的 selection
// @State var selected : ClipData?
@ObservedObject var viewModel = ClipViewModel.shared
Expand Down Expand Up @@ -217,12 +221,12 @@ struct ClipView: View {
}
}.frame(width: 800, height: 400)
}

func delete(_ clipData: ClipHistoryData) {
if let selectedItem = viewModel.selectedItem {
let selectedItemIdx = clips.firstIndex(of: selectedItem)!
let idx = clips.firstIndex(of: clipData)!

// 计算删除后,需要选中的新条目的索引
let newIndexAfterDeletion: Int?
if selectedItem == clipData {
Expand All @@ -238,9 +242,9 @@ struct ClipView: View {
} else {
newIndexAfterDeletion = selectedItemIdx
}

PersistenceController.shared.delete(item: clipData)

// 在删除后更新选中项
DispatchQueue.main.async {
if let newIndex = newIndexAfterDeletion, clips.indices.contains(newIndex) {
Expand Down
2 changes: 1 addition & 1 deletion Selected/View/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct SettingsView: View {
@Environment(\.colorScheme) var colorScheme

@Default(.aiService) var aiService
let aiServicePickerValues = ["OpenAI", "Claude", "Gemini"]
let aiServicePickerValues = ["OpenAI", "Claude"]


@Default(.openAIAPIKey) var openAIAPIKey
Expand Down

0 comments on commit aae4ccb

Please sign in to comment.