11import AppKit
2+ import OpenAIService
23import Client
34import Preferences
45import SuggestionModel
@@ -8,7 +9,7 @@ final class OpenAIViewSettings: ObservableObject {
89 static let availableLocalizedLocales = Locale . availableLocalizedLocales
910 @AppStorage ( \. openAIAPIKey) var openAIAPIKey : String
1011 @AppStorage ( \. chatGPTModel) var chatGPTModel : String
11- @AppStorage ( \. chatGPTEndpoint ) var chatGPTEndpoint : String
12+ @AppStorage ( \. openAIBaseURL ) var openAIBaseURL : String
1213 @AppStorage ( \. chatGPTLanguage) var chatGPTLanguage : String
1314 @AppStorage ( \. chatGPTMaxToken) var chatGPTMaxToken : Int
1415 @AppStorage ( \. chatGPTTemperature) var chatGPTTemperature : Double
@@ -22,6 +23,7 @@ struct OpenAIView: View {
2223 string: " https://platform.openai.com/docs/models/model-endpoint-compatibility "
2324 ) !
2425 @Environment ( \. openURL) var openURL
26+ @Environment ( \. toast) var toast
2527 @StateObject var settings = OpenAIViewSettings ( )
2628 @State var maxTokenOverLimit = false
2729
@@ -39,6 +41,27 @@ struct OpenAIView: View {
3941 } . buttonStyle ( . plain)
4042 }
4143
44+ HStack {
45+ TextField (
46+ text: $settings. openAIBaseURL,
47+ prompt: Text ( " https://api.openai.com " )
48+ ) {
49+ Text ( " OpenAI Base URL " )
50+ } . textFieldStyle ( . roundedBorder)
51+
52+ Button ( " Test " ) {
53+ Task {
54+ do {
55+ let reply = try await ChatGPTService ( )
56+ . sendAndWait ( content: " Hello " , summary: nil )
57+ toast ( Text ( " ChatGPT replied: \( reply ?? " N/A " ) " ) , . info)
58+ } catch {
59+ toast ( Text ( error. localizedDescription) , . error)
60+ }
61+ }
62+ }
63+ }
64+
4265 HStack {
4366 Picker ( selection: $settings. chatGPTModel) {
4467 if !settings. chatGPTModel. isEmpty,
@@ -59,13 +82,6 @@ struct OpenAIView: View {
5982 } . buttonStyle ( . plain)
6083 }
6184
62- TextField (
63- text: $settings. chatGPTEndpoint,
64- prompt: Text ( " https://api.openai.com/v1/chat/completions " )
65- ) {
66- Text ( " ChatGPT Server " )
67- } . textFieldStyle ( . roundedBorder)
68-
6985 if #available( macOS 13 . 0 , * ) {
7086 LabeledContent ( " Reply in Language " ) {
7187 languagePicker
@@ -107,7 +123,7 @@ struct OpenAIView: View {
107123 . labelsHidden ( )
108124 . textFieldStyle ( . roundedBorder)
109125 . foregroundColor ( maxTokenOverLimit ? . red : . primary)
110-
126+
111127 if let model = ChatGPTModel ( rawValue: settings. chatGPTModel) {
112128 Text ( " Max: \( model. maxToken) " )
113129 }
0 commit comments