Comments (18)
from openaiswift.
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.
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.
@albertopeam I like this approach :]
from openaiswift.
PR opened #33
Take a look, probably I will do some improvements regarding unit tests
@adamrushy
@MarkHoath
from openaiswift.
This PR should solve this: #65
from openaiswift.
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.
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.
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.
I'm getting the same error and haven't found a solution yet unfortunately.
from openaiswift.
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.
I will implement it then, thanks!
from openaiswift.
Hi!
Any updates on this @adamrushy? :)
#33
from openaiswift.
from openaiswift.
@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:
- https://github.com/openai/openai-python/blob/94428401b4f71596e4a1331102a6beee9d8f0bc4/openai/api_requestor.py#L681
- https://github.com/openai/openai-python/blob/94428401b4f71596e4a1331102a6beee9d8f0bc4/openai/api_requestor.py#L329
(Here is a very experimental implementation as an example: https://github.com/adamrushy/OpenAISwift/pull/42/files)
from openaiswift.
@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.
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.
I got the same error today. Did you found any solution @davidyannick86 ?
from openaiswift.
Related Issues (20)
- OpenAI Token is not accepted HOT 3
- sendChat model .gpt4(.gpt4) throws Error HOT 11
- .gpt4 is not working, returning empty string HOT 1
- your code is broken. HOT 2
- authToken doesn't work in version 1.4 HOT 6
- "The operation couldn’t be completed. (OpenAISwift.OpenAIError error 2.)" HOT 2
- Always returning nil HOT 3
- OpenAIEndpointModelType that replaces the OpenAIModelType so only compatible models are available for each method
- Trying to take a sendCompletion request with gpt4 model HOT 1
- Cannot use instance member 'key' within property initializer; property initializers run before 'self' is available
- no response from openAI webAPI? HOT 3
- OpenAISwift 1.4.0 multiple errors with new Xcode 15 release HOT 1
- theres a typo for URLRequest it say inout instead of "input" HOT 1
- Stay away from this package HOT 12
- OpenAISwift - New Fork with merged Pull Requests
- Latest Models & Updates HOT 1
- 2023 Dev Conf Updates
- Is gpt-4-vision-preview model possible? HOT 1
- Not getting any responses from API HOT 3
- Updated Jan 2024 Models and Endpoints
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from openaiswift.