AIChatInfoManager.swift 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //
  2. // AIChatInfoManager.swift
  3. // PDF Reader Pro Edition
  4. //
  5. // Created by Niehaoyu on 2024/4/18.
  6. //
  7. import Cocoa
  8. class AIChatInfoModel: NSObject {
  9. var chateModelID: String = ""
  10. var aiConfigType: AIConfigType = .none
  11. var infoType: AIChatInfoType = .none
  12. var filePath: String = "" //使用的文件路径
  13. var uploadContent: String = "" //用户输入的内容
  14. var chatResult: String = "" //AI返回的结果
  15. var chatInfoState: AIChatInfoState = .stateNone
  16. var translateFromLanguage: String = ""
  17. var translateToLanguage: String = ""
  18. var creditsValid: Bool = false
  19. var costCredits: Int = 0
  20. var totalChart: Int = 0
  21. var infoDict: [String : String] = [:]
  22. override init() {
  23. super.init()
  24. self.chateModelID = self.tagString()
  25. self.creditsValid = true
  26. }
  27. func updateTagID() {
  28. self.chateModelID = self.tagString()
  29. }
  30. @objc func tagString() -> String {
  31. let dateFormatter = DateFormatter.init()
  32. dateFormatter.dateFormat = "yyyyMMddHHmmss"
  33. let dateString = dateFormatter.string(from: NSDate() as Date)
  34. return String(format: "%@%d", dateString, arc4random()%10000)
  35. }
  36. }
  37. @objcMembers class AIChatInfoManager: NSObject {
  38. public static let defaultManager = AIChatInfoManager.init()
  39. var modelsArrM: [AIChatInfoModel] = []
  40. var currentFilePath: String = ""
  41. var isAILoading: Bool = false
  42. override init() {
  43. super.init()
  44. let defaultChatModel = AIChatInfoModel.init()
  45. defaultChatModel.aiConfigType = .none
  46. defaultChatModel.infoType = .defaultTip
  47. self.modelsArrM.append(defaultChatModel)
  48. }
  49. func clearData() {
  50. self.modelsArrM.removeAll()
  51. let defaultChatModel = AIChatInfoModel.init()
  52. defaultChatModel.aiConfigType = .none
  53. defaultChatModel.infoType = .defaultTip
  54. self.modelsArrM.append(defaultChatModel)
  55. }
  56. }