Merge branch 'main' of github.com:MustangYM/OSXChatGpt

# Conflicts:
#	OSXChatGPT/OSXChatGPT/DataProvider/ChatGPTManager.swift
This commit is contained in:
陈连辰
2023-03-23 23:32:37 +08:00
4 changed files with 19 additions and 6 deletions

View File

@@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 56;
objectVersion = 50;
objects = {
/* Begin PBXBuildFile section */

View File

@@ -7,14 +7,14 @@
import Foundation
private let OSXChatGPTKEY = "OSXChatGPT_apiKey_key"
class ChatGPTManager {
static let shared = ChatGPTManager()
private let saveApi_key: String = "OSXChatGPT_apiKey_key"
private var messagesDict: [String:[Message]] = [:]
private let httpClient: HTTPClient = HTTPClient()
private lazy var apiKey : String = {
let key = UserDefaults.standard.value(forKey: saveApi_key) as? String
let key = UserDefaults.standard.value(forKey: OSXChatGPTKEY) as? String
return key ?? ""
}()
private var askContextCount: Int = 3
@@ -32,11 +32,12 @@ extension ChatGPTManager {
return
}
self.apiKey = apiKey
UserDefaults.standard.set(apiKey, forKey: saveApi_key)
UserDefaults.standard.set(apiKey, forKey: OSXChatGPTKEY)
}
func getApiKey() -> String {
let key = String(self.apiKey)
return key
}
func getMaskApiKey() -> String {
var key = String(self.apiKey)

View File

@@ -4,7 +4,9 @@
//
// Created by MustangYM on 2023/3/11.
//
/*
https://platform.openai.com/docs/api-reference/introduction
*/
import AppKit
import SwiftUI

View File

@@ -27,6 +27,8 @@ struct ChatRoomView: View {
@State private var scrollID = UUID()
@State private var isOnAppear: Bool = false
@State var apiKey: String = ChatGPTManager.shared.getMaskApiKey()
@State var openArgumentSeet: Bool = false
init(conversation: Conversation?) {
self.conversation = conversation
@@ -120,6 +122,11 @@ struct ChatRoomView: View {
.onAppear {
print("View appeared!")
if apiKey.count < 10 {
}
KeyboardMonitor.shared.startMonitorPasteboard()
KeyboardMonitor.shared.startMonitorShiftKey()
viewModel.currentConversation = conversation
@@ -137,6 +144,9 @@ struct ChatRoomView: View {
self.isOnAppear = false
}
.sheet(isPresented: $openArgumentSeet) {
EnterAPIView(apiKey: $apiKey)
}
}
@@ -179,7 +189,7 @@ struct ChatRoomView: View {
private func sendMessage(scrollView: ScrollViewProxy?, text: String) {
guard !newMessageText.isEmpty else { return }
let msg = String(text)
let msg = String(newMessageText.dropLast())
let replaceStr = msg.replacingOccurrences(of: " ", with: "")
if replaceStr.count == 0 {
newMessageText = ""