Giter Club home page Giter Club logo

Comments (18)

MarkHoath avatar MarkHoath commented on June 26, 2024 1

from openaiswift.

MarkHoath avatar MarkHoath commented on June 26, 2024 1

Yes the Status Code is 200 and the JSONDecode is failing, which I then did a JSONSerialization on and get the following.

["error": {
code = "";
message = "The server had an error while processing your request. Sorry about that!";
param = "";
type = "server_error";
}]

from openaiswift.

adamrushy avatar adamrushy commented on June 26, 2024 1

I think we have to monitor this and reach out to OpenAI - my gut feeling is that it's to do with some kind of rate limiting on the API or some changes they're making

from openaiswift.

adamrushy avatar adamrushy commented on June 26, 2024 1

@albertopeam I like this approach :]

from openaiswift.

albertopeam avatar albertopeam commented on June 26, 2024 1

PR opened #33
Take a look, probably I will do some improvements regarding unit tests
@adamrushy
@MarkHoath

from openaiswift.

pvieito avatar pvieito commented on June 26, 2024 1

This PR should solve this: #65

from openaiswift.

MarkHoath avatar MarkHoath commented on June 26, 2024

OK So I figured out how to edit the package and I added a JSONSerialization to the Error Response and it comes back with

["error": {
code = "";
message = "The server had an error while processing your request. Sorry about that!";
param = "";
type = "server_error";
}]

from openaiswift.

albertopeam avatar albertopeam commented on June 26, 2024

Hi!
Official Doc doesn't say nothing about optionals. It seems to not be very well documented at least the responses with/without errors.

I have created a test to try to reproduce the scenario that you have shared and the only way I have found to reproduce it is to provide a wrong auth token, example:

import XCTest
@testable import OpenAISwift

final class OpenAISwiftTests: XCTestCase {
    let fakeAuthToken = "" // wrong auth token
    
    func testCompletions() async throws {
        do {
            let sut = OpenAISwift.init(authToken: fakeAuthToken)
            
            let result = try await sut.sendCompletion(with: "Write a haiku")
           
            XCTAssertFalse(result.choices.isEmpty)
        } catch let OpenAIError.genericError(error) {
            print(error)
        } catch let OpenAIError.decodingError(error) {
            print(error)
        }
    }
}

This test output is similar to what you comment

Test Case '-[OpenAISwiftTests.OpenAISwiftTests testCompletions]' started.
keyNotFound(CodingKeys(stringValue: "object", intValue: nil), Swift.DecodingError.Context(codingPath: [], debugDescription: "No value associated with key CodingKeys(stringValue: \"object\", intValue: nil) (\"object\").", underlyingError: nil))

Said that, have you checked that your auth token is not missing and correct?
You can check it here https://platform.openai.com/account/api-keys

I hope it helps. If you can provide more info it would help to debug the exact problem

from openaiswift.

albertopeam avatar albertopeam commented on June 26, 2024

Hi!

It would be nice if you can share the statusCode of the response, I guess is possible that you get this DecodingError if the OpenAPI returns 200 and the error body that you have shared previously.

from openaiswift.

Berkay-Disli avatar Berkay-Disli commented on June 26, 2024

I'm getting the same error and haven't found a solution yet unfortunately.

from openaiswift.

albertopeam avatar albertopeam commented on June 26, 2024

Yes the Status Code is 200 and the JSONDecode is failing, which I then did a JSONSerialization on and get the following.

["error": { code = ""; message = "The server had an error while processing your request. Sorry about that!"; param = ""; type = "server_error"; }]

It looks like instead of returning a 500 for an internal error they return 200, so the body is tried to be parsed to a succesfull response, so it seems normal the DecodingError.

A possible workaround strategy is to try to parse the success response and catch the DecodingError, if it throws we can parse this error body that you have shared and then throw a new error like internalError, this can contain the message that the API returned.

It can be done easily @adamrushy, what do you think on this approach?

from openaiswift.

albertopeam avatar albertopeam commented on June 26, 2024

I will implement it then, thanks!

from openaiswift.

albertopeam avatar albertopeam commented on June 26, 2024

Hi!
Any updates on this @adamrushy? :)
#33

from openaiswift.

MarkHoath avatar MarkHoath commented on June 26, 2024

from openaiswift.

pvieito avatar pvieito commented on June 26, 2024

@adamrushy Hi!

Any update on this? We should fix the implementation on OpenAISwift. URLSession does not "auto-fail" when the status code is not 2XX-3XX, we have to implement that behavior, and retrieve the error message properly so it can be presented to the user or properly log it. To do that I would recommend following the same approach as in the official Python OpenAI API:

(Here is a very experimental implementation as an example: https://github.com/adamrushy/OpenAISwift/pull/42/files)

from openaiswift.

albertopeam avatar albertopeam commented on June 26, 2024

@adamrushy @MarkHoath
Solved conflicts, ready to review and merge!
Could you take a look @adamrushy

Take in mind that I have added unit tests to the completions endpoint. Now on you can easily add tests to sendEdits and sendChats

from openaiswift.

davidyannick86 avatar davidyannick86 commented on June 26, 2024

I have this error in my project
"2023-03-16 17:41:54.001076+0100 ChatGPT-IOS[56127:1373580] [plugin] AddInstanceForFactory: No factory registered for id <CFUUID 0x600002da68a0> F8BB1C28-BAE8-11D6-9C31-00039315CD46

decodingError(error: Swift.DecodingError.keyNotFound(CodingKeys(stringValue: "object", intValue: nil), Swift.DecodingError.Context(codingPath: [], debugDescription: "No value associated with key CodingKeys(stringValue: "object", intValue: nil) ("object").", underlyingError: nil)))"

Is is the same as you describe ?

from openaiswift.

USBA avatar USBA commented on June 26, 2024

I got the same error today. Did you found any solution @davidyannick86 ?

from openaiswift.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.