mirror of
https://github.com/MustangYM/OSXChatGpt.git
synced 2025-11-25 11:29:43 +08:00
Enter APIKey
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
182B437429BC5D1B00F06778 /* ViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 182B437029BC5D1B00F06778 /* ViewModel.swift */; };
|
||||
182B437529BC5D1B00F06778 /* ChatGPTManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 182B437129BC5D1B00F06778 /* ChatGPTManager.swift */; };
|
||||
182B437929BC5D6200F06778 /* OSXChatGPTApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 182B437829BC5D6200F06778 /* OSXChatGPTApp.swift */; };
|
||||
182B437B29BC5FBE00F06778 /* EnterAPIView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 182B437A29BC5FBE00F06778 /* EnterAPIView.swift */; };
|
||||
CB1DCAC629B4F09F00B1D4E1 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CB1DCAC529B4F09F00B1D4E1 /* Assets.xcassets */; };
|
||||
CB1DCAC929B4F09F00B1D4E1 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CB1DCAC829B4F09F00B1D4E1 /* Preview Assets.xcassets */; };
|
||||
CBC4B0FF29B8BF9600650296 /* OSXChatGPT.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = CBC4B0FD29B8BF9600650296 /* OSXChatGPT.xcdatamodeld */; };
|
||||
@@ -44,6 +45,7 @@
|
||||
182B437029BC5D1B00F06778 /* ViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewModel.swift; sourceTree = "<group>"; };
|
||||
182B437129BC5D1B00F06778 /* ChatGPTManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChatGPTManager.swift; sourceTree = "<group>"; };
|
||||
182B437829BC5D6200F06778 /* OSXChatGPTApp.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OSXChatGPTApp.swift; sourceTree = "<group>"; };
|
||||
182B437A29BC5FBE00F06778 /* EnterAPIView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnterAPIView.swift; sourceTree = "<group>"; };
|
||||
CB1DCABE29B4F09D00B1D4E1 /* OSXChatGPT.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = OSXChatGPT.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
CB1DCAC529B4F09F00B1D4E1 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||
CB1DCAC829B4F09F00B1D4E1 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
|
||||
@@ -93,6 +95,7 @@
|
||||
182B436229BC5C8700F06778 /* ChatRoomView.swift */,
|
||||
182B436429BC5C8700F06778 /* UserInitializeView.swift */,
|
||||
182B436129BC5C8700F06778 /* View.swift */,
|
||||
182B437A29BC5FBE00F06778 /* EnterAPIView.swift */,
|
||||
);
|
||||
path = WindowView;
|
||||
sourceTree = "<group>";
|
||||
@@ -253,6 +256,7 @@
|
||||
182B437329BC5D1B00F06778 /* CoreDataManager.swift in Sources */,
|
||||
CBC4B12729B8D28D00650296 /* UserRole+CoreDataClass.swift in Sources */,
|
||||
182B436629BC5C8700F06778 /* View.swift in Sources */,
|
||||
182B437B29BC5FBE00F06778 /* EnterAPIView.swift in Sources */,
|
||||
182B437929BC5D6200F06778 /* OSXChatGPTApp.swift in Sources */,
|
||||
182B437429BC5D1B00F06778 /* ViewModel.swift in Sources */,
|
||||
CBC4B0FF29B8BF9600650296 /* OSXChatGPT.xcdatamodeld in Sources */,
|
||||
|
||||
87
OSXChatGPT/OSXChatGPT/WindowView/EnterAPIView.swift
Normal file
87
OSXChatGPT/OSXChatGPT/WindowView/EnterAPIView.swift
Normal file
@@ -0,0 +1,87 @@
|
||||
//
|
||||
// EnterAPIView.swift
|
||||
// OSXChatGPT
|
||||
//
|
||||
// Created by MustangYM on 2023/3/11.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct EnterAPIView: View {
|
||||
@Environment(\.presentationMode) var presentationMode
|
||||
@State var apiKey: String = ""
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 20) {
|
||||
Text("Enter Your OpenAI API Key:")
|
||||
.font(.title)
|
||||
.fontWeight(.bold)
|
||||
.frame(maxWidth: .infinity, alignment: .center)
|
||||
.padding(.top, 20)
|
||||
|
||||
Text("You need a working OpenAI Api Key in order to use OSXChatGPT")
|
||||
.foregroundColor(.gray)
|
||||
.frame(maxWidth: .infinity, alignment: .center)
|
||||
.padding(.horizontal, 20)
|
||||
|
||||
Button(action: {
|
||||
if let url = URL(string: "https://platform.openai.com/account/api-keys") {
|
||||
NSWorkspace.shared.open(url)
|
||||
}
|
||||
}) {
|
||||
Text("->Get your API key from Open AI dashboard")
|
||||
.foregroundColor(.blue)
|
||||
.frame(maxWidth: .infinity, alignment: .center)
|
||||
.padding(.horizontal, 20)
|
||||
}
|
||||
.buttonStyle(BorderlessButtonStyle())//删除背景色
|
||||
|
||||
TextField("Enter your API key", text: $apiKey)
|
||||
.textFieldStyle(RoundedBorderTextFieldStyle())
|
||||
.frame(width: 400, height: 50)
|
||||
|
||||
HStack(spacing: 50, content: {
|
||||
Button(action: {
|
||||
self.presentationMode.wrappedValue.dismiss()
|
||||
}) {
|
||||
Text("Cancel")
|
||||
.foregroundColor(.white)
|
||||
.padding(.vertical, 8)
|
||||
.padding(.horizontal, 20)
|
||||
}
|
||||
.frame(width: 100, height: 40) // 设置按钮大小
|
||||
.background(Color.gray)
|
||||
.cornerRadius(10)
|
||||
.buttonStyle(BorderlessButtonStyle())
|
||||
|
||||
Button(action: {
|
||||
// TODO: save the API key
|
||||
self.presentationMode.wrappedValue.dismiss()
|
||||
}) {
|
||||
Text("Save")
|
||||
.foregroundColor(.white)
|
||||
.padding(.vertical, 8)
|
||||
.padding(.horizontal, 20)
|
||||
}
|
||||
.frame(width: 100, height: 40) // 设置按钮大小
|
||||
.background(Color.blue)
|
||||
.cornerRadius(10)
|
||||
.buttonStyle(BorderlessButtonStyle())
|
||||
})
|
||||
.frame(maxWidth: .infinity, alignment: .center)
|
||||
.padding(.top, 0)
|
||||
|
||||
Text("The app will connect to OpenAI API server to check if your API Key is working properly.")
|
||||
.font(.footnote)
|
||||
.fontWeight(.bold)
|
||||
.frame(maxWidth: .infinity, alignment: .center)
|
||||
}
|
||||
.frame(width: 500, height: 300)
|
||||
}
|
||||
}
|
||||
|
||||
struct EnterAPIView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
EnterAPIView()
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import SwiftUI
|
||||
import AppKit
|
||||
/// main View
|
||||
struct MainContentView: View {
|
||||
@State var openArgumentsSeet: Bool = false
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
SessionsView()
|
||||
|
||||
@@ -8,6 +8,8 @@ import Colorful
|
||||
import SwiftUI
|
||||
|
||||
struct UserInitializeView: View {
|
||||
@State var openArgumentSeet: Bool = false
|
||||
|
||||
var body: some View {
|
||||
ColorfulView(colors: [.accentColor], colorCount: 4)
|
||||
.ignoresSafeArea()
|
||||
@@ -40,7 +42,7 @@ struct UserInitializeView: View {
|
||||
|
||||
// 添加API密钥按钮
|
||||
Button(action: {
|
||||
// apiKeyTapped.toggle()
|
||||
openArgumentSeet.toggle()
|
||||
}) {
|
||||
HStack(spacing: 8) {
|
||||
Image(systemName: "key.radiowaves.forward.fill")
|
||||
@@ -54,11 +56,16 @@ struct UserInitializeView: View {
|
||||
}
|
||||
.buttonStyle(PlainButtonStyle()) // 隐藏按钮的默认样式
|
||||
}
|
||||
.sheet(isPresented: $openArgumentSeet) {
|
||||
EnterAPIView()
|
||||
}
|
||||
|
||||
}
|
||||
.padding(.top,100)
|
||||
.padding(.bottom,300)
|
||||
.padding(.leading,200)
|
||||
.padding(.trailing,200)
|
||||
|
||||
|
||||
VStack {
|
||||
Spacer()
|
||||
|
||||
Reference in New Issue
Block a user