Skip to content

Conversation

@jamesrochabrun
Copy link
Owner

Following @lzell AiProxy suggestion, this will help make SwiftOpenAI more friendly to different providers.

Decodables should all have optional properties. Why? We don't want to fail decoding in live apps if the provider changes something out from under us (which can happen purposefully due to deprecations, or by accident due to regressions). If we use non-optionals in decodable definitions, then a provider removing a field, changing the type of a field, or removing an enum case would cause decoding to fail.

You may think this isn't too bad, since the JSONDecoder throws anyway, and therefore client code will already be wrapped in a do/catch. However, we always want to give the best chance that decodable succeeds for the properties that the client actually uses. That is, if the provider changes out the enum case of a property unused by the client, we want the client application to continue functioning correctly, not to throw an error and enter the catch branch of the client's call site.

@jamesrochabrun jamesrochabrun merged commit 8bb0ffc into main Feb 12, 2025
@jamesrochabrun jamesrochabrun deleted the jroch-optional-properties branch February 12, 2025 05:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant