adamrushy / OpenAISwift

This is a wrapper library around the ChatGPT and OpenAI HTTP API
MIT License
1.6k stars 242 forks source link

Cannot use instance member 'key' within property initializer; property initializers run before 'self' is available #117

Open abdalla-elnajjar opened 9 months ago

abdalla-elnajjar commented 9 months ago

I am creating chatGPT clone for my study. I am using openAISwift to connect with openAI WebAPI. I have small issue creating config object

I applied you api change but still I have error

struct MainView: View {
    @State private var chatText :String  = ""
    @State private var answers :[String]  = []

    private let key: String = "sk-"
    var openAI: OpenAISwift = OpenAISwift(config: OpenAISwift.Config.makeDefaultOpenAI(apiKey: key))
    ...
}

error Cannot use instance member 'key' within property initializer; property initializers run before 'self' is available