@@ -30,63 +30,76 @@ struct OpenAIView: View {
3030
3131 Form {
3232 HStack {
33- Text ( " OpenAI API Key " )
3433 TextField ( text: $settings. openAIAPIKey, prompt: Text ( " sk-* " ) ) {
35- EmptyView ( )
36- } . textFieldStyle ( . copilot )
34+ Text ( " OpenAI API Key " )
35+ } . textFieldStyle ( . roundedBorder )
3736 Button ( action: {
3837 openURL ( apiKeyURL)
3938 } ) {
4039 Image ( systemName: " questionmark.circle.fill " )
41- }
42- . buttonStyle ( . plain)
40+ } . buttonStyle ( . plain)
4341 }
4442
4543 HStack {
46- Text ( " ChatGPT Model " )
47- TextField ( text: $settings. chatGPTModel, prompt: Text ( " gpt-3.5-turbo " ) ) {
48- EmptyView ( )
49- } . textFieldStyle ( . copilot)
50-
44+ Picker ( selection: $settings. chatGPTModel) {
45+ ForEach ( ChatGPTModel . allCases, id: \. self) { model in
46+ Text ( model. rawValue) . tag ( model. rawValue)
47+ }
48+ } label: {
49+ Text ( " ChatGPT Model " )
50+ } . pickerStyle ( . menu)
5151 Button ( action: {
5252 openURL ( modelURL)
5353 } ) {
5454 Image ( systemName: " questionmark.circle.fill " )
55+ } . buttonStyle ( . plain)
56+ }
57+ . onChange ( of: settings. chatGPTModel) { newValue in
58+ if let model = ChatGPTModel ( rawValue: newValue) {
59+ settings. chatGPTEndpoint = model. endpoint
5560 }
56- . buttonStyle ( . plain)
5761 }
5862
59- HStack {
60- Text ( " ChatGPT Endpoint " )
61- TextField (
62- text: $settings. chatGPTEndpoint,
63- prompt: Text ( " https://api.openai.com/v1/chat/completions " )
64- ) {
65- EmptyView ( )
66- } . textFieldStyle ( . copilot)
67- }
68-
69- HStack {
63+ TextField (
64+ text: $settings. chatGPTEndpoint,
65+ prompt: Text ( " https://api.openai.com/v1/chat/completions " )
66+ ) {
67+ Text ( " ChatGPT Server " )
68+ } . textFieldStyle ( . roundedBorder)
69+
70+ Picker ( selection: $settings. chatGPTLanguage) {
71+ ForEach ( Locale . availableLocalizedLocales, id: \. self) { localizedLocales in
72+ Text ( localizedLocales) . tag ( localizedLocales)
73+ }
74+ } label: {
7075 Text ( " Reply in Language " )
71- TextField (
72- text: $settings. chatGPTLanguage,
73- prompt: Text ( " e.g. English. Leave it blank to let the bot decide. " )
74- ) {
75- EmptyView ( )
76- } . textFieldStyle ( . copilot)
77- }
78-
79- HStack {
80- Text ( " Max Token " )
81- TextField (
82- text: . init( get: {
83- String ( settings. chatGPTMaxToken)
84- } , set: { newValue in
85- settings. chatGPTMaxToken = Int ( newValue) ?? 0
86- } )
87- ) {
88- EmptyView ( )
89- } . textFieldStyle ( . copilot)
76+ } . pickerStyle ( . menu)
77+
78+ if let model = ChatGPTModel ( rawValue: settings. chatGPTModel) {
79+ let binding = Binding (
80+ get: { String ( settings. chatGPTMaxToken) } ,
81+ set: {
82+ if let selectionMaxToken = Int ( $0) {
83+ settings. chatGPTMaxToken = model. maxToken < selectionMaxToken ? model. maxToken : selectionMaxToken
84+ } else {
85+ settings. chatGPTMaxToken = 0
86+ }
87+ }
88+ )
89+ HStack {
90+ Stepper (
91+ value: $settings. chatGPTMaxToken,
92+ in: 0 ... model. maxToken,
93+ step: 1
94+ ) {
95+ Text ( " Max Token " )
96+ }
97+ TextField ( text: binding) {
98+ EmptyView ( )
99+ }
100+ . labelsHidden ( )
101+ . textFieldStyle ( . roundedBorder)
102+ }
90103 }
91104 }
92105 }
0 commit comments