forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAzureView.swift
More file actions
70 lines (62 loc) · 2.16 KB
/
AzureView.swift
File metadata and controls
70 lines (62 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import AppKit
import Client
import OpenAIService
import Preferences
import SuggestionModel
import SwiftUI
final class AzureViewSettings: ObservableObject {
@AppStorage(\.azureOpenAIAPIKey) var azureOpenAIAPIKey: String
@AppStorage(\.azureOpenAIBaseURL) var azureOpenAIBaseURL: String
@AppStorage(\.azureChatGPTDeployment) var azureChatGPTDeployment: String
init() {}
}
struct AzureView: View {
@Environment(\.toast) var toast
@State var isTesting = false
@StateObject var settings = AzureViewSettings()
var body: some View {
Form {
SecureField(text: $settings.azureOpenAIAPIKey, prompt: Text("")) {
Text("OpenAI Service API Key")
}
.textFieldStyle(.roundedBorder)
TextField(
text: $settings.azureOpenAIBaseURL,
prompt: Text("https://XXXXXX.openai.azure.com")
) {
Text("OpenAI Service Base URL")
}.textFieldStyle(.roundedBorder)
HStack {
TextField(
text: $settings.azureChatGPTDeployment,
prompt: Text("")
) {
Text("Chat Model Deployment Name")
}.textFieldStyle(.roundedBorder)
Button("Test") {
Task { @MainActor in
isTesting = true
defer { isTesting = false }
do {
let reply = try await ChatGPTService(designatedProvider: .azureOpenAI)
.sendAndWait(content: "Hello", summary: nil)
toast(Text("ChatGPT replied: \(reply ?? "N/A")"), .info)
} catch {
toast(Text(error.localizedDescription), .error)
}
}
}
.disabled(isTesting)
}
}
}
}
struct AzureView_Previews: PreviewProvider {
static var previews: some View {
VStack(alignment: .leading, spacing: 8) {
AzureView()
}
.frame(height: 800)
.padding(.all, 8)
}
}