adamrushy / OpenAISwift

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

Not getting any responses from API #130

Open Momeks opened 5 months ago

Momeks commented 5 months ago

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
    }
}
mak8484 commented 5 months ago

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.

Momeks commented 5 months ago

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

mak8484 commented 5 months ago

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