mirror of
https://github.com/MustangYM/OSXChatGpt.git
synced 2025-11-25 03:15:08 +08:00
Merge branch 'main' of github.com:MustangYM/OSXChatGpt
# Conflicts: # OSXChatGPT/OSXChatGPT/DataProvider/ChatGPTManager.swift
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
archiveVersion = 1;
|
||||
classes = {
|
||||
};
|
||||
objectVersion = 56;
|
||||
objectVersion = 50;
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -4,7 +4,9 @@
|
||||
//
|
||||
// Created by MustangYM on 2023/3/11.
|
||||
//
|
||||
|
||||
/*
|
||||
https://platform.openai.com/docs/api-reference/introduction
|
||||
*/
|
||||
import AppKit
|
||||
import SwiftUI
|
||||
|
||||
|
||||
@@ -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 = ""
|
||||
|
||||
Reference in New Issue
Block a user