Hey all, I am absolutely brand new to Swift/SwiftUI
I'm working on a little project to access GPT-3, and long story short, I can't for the life of me get the text output to update when I call the API. The console shows that the API is indeed being called and it returns a response, but the text displayed does not update.
Any help would be greatly appreciated!
Here's my code (Warning its probably pretty ugly):
// OpenAIApp.swift
// OpenAI
//
// Created by Max Micklitsch on 9/27/22.
//
import SwiftUI
@main
struct OpenAIApp: App {
@State var input: String = ""
@State public var output: String = "Test"
var body: some Scene {
MenuBarExtra(input, systemImage: "brain.head.profile") {
ScrollView{
VStack(alignment: .leading){
Text("GPT-3 Interface:")
.font(.caption)
.padding(EdgeInsets(top: 10, leading: 10, bottom: 0, trailing: 0))
TextField(
"Prompt",
text: $input
)
.disableAutocorrection(true)
.textFieldStyle(.roundedBorder)
.padding()
}
HStack{
Button("Quit") {
NSApplication.shared.terminate(nil)
}
Button("Go", action: { process() })
}
Divider()
VStack(alignment: .leading){
Text("Output: \(output)")
.padding(EdgeInsets(top: 10, leading: 10, bottom: 0, trailing: 0))
}
}
}
.menuBarExtraStyle(.window)
}
func process() {
output = ai.processPrompt(prompt: input) ?? "Error"
}
}