@@ -30,42 +30,36 @@ 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: \. hashValue) { 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- }
56- . buttonStyle ( . plain)
55+ } . buttonStyle ( . plain)
5756 }
58-
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)
57+ . onChange ( of: settings. chatGPTModel) { newValue in
58+ guard let model = ChatGPTModel ( rawValue: newValue) else { return }
59+ settings. chatGPTEndpoint = model. endpoint
60+ settings. chatGPTMaxToken = model. maxToken
6761 }
68-
62+
6963 HStack {
7064 Text ( " Reply in Language " )
7165 TextField (
@@ -75,19 +69,6 @@ struct OpenAIView: View {
7569 EmptyView ( )
7670 } . textFieldStyle ( . copilot)
7771 }
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)
90- }
9172 }
9273 }
9374 }
0 commit comments