OpenAISwift icon indicating copy to clipboard operation
OpenAISwift copied to clipboard

Not getting any responses from API

Open Momeks opened this issue 1 year ago • 3 comments

Hello, I am having an issue with the API that suddenly stopped working. Despite having a valid token and enough credit for API usage, I am not receiving any response from the API. I was previously using the default repo model, but it seems that many models have been shut down by OpenAI. I changed it to .chat (.chatgpt) to use GPT-3 and also tested with the GPT-3 turbo model, but I still am not getting any data. This is a crucial issue for my AI-based app, and I would be grateful for any workaround. If it helps, here is my code.

@MainActor
class AIViewModel: ObservableObject {

    private var client: OpenAISwift?
    @Published var respnse = ""
    @Published var isLoading = false
    @Published var recievedError = false
    init() { client = OpenAISwift(config: .makeDefaultOpenAI(apiKey: "sk-*******")) }

    func ask(text: String) async {
        isLoading = true
        do {
            let result = try await client?.sendCompletion(
                with: text,
                model: .chat(.chatgpt),
                maxTokens: 200
            )
            let output = result?.choices?.first?.text.trimmingCharacters(in: .newlines) ?? "no answer"
            //print(output)
            self.respnse = output
        } catch {
            print(error.localizedDescription)
            recievedError = true
        }
        isLoading = false
    }
}

Momeks avatar Jan 15 '24 13:01 Momeks

I have the same issue, the request itself is successful, but the objects in the response are all nil. It started after the 8th of Jan, the same code worked before.

mak8484 avatar Jan 24 '24 13:01 mak8484

I have the same issue, the request itself is successful, but the objects in the response are all nil. It started after the 8th of Jan, the same code worked before.

This answer solved my problem: https://stackoverflow.com/a/77822982/199173

Momeks avatar Jan 24 '24 13:01 Momeks

Many thanks! I could figure it out thanks to your tip. Basically in the old code they sent an extra "id" with the message, and that is not allowed by the API

mak8484 avatar Jan 24 '24 15:01 mak8484