Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

“Log probs not found” error with some models on openrouter #119

Closed
provencher opened this issue Feb 6, 2025 · 4 comments
Closed

“Log probs not found” error with some models on openrouter #119

provencher opened this issue Feb 6, 2025 · 4 comments

Comments

@provencher
Copy link

provencher commented Feb 6, 2025

A user using this model “deepseek r1:free” noticed this missing json field.

It would be good to make most fields that are not standard optional to ensure that they don’t lead to decoding errors like this. It seems like there’s a huge variety in what gets sent over openrouter.

Image
@lzell
Copy link
Contributor

lzell commented Feb 7, 2025

@jamesrochabrun FWIW I sidestep this in AIProxySwift by making (mostly) all decodable properties optional. Here's the snippet in my contribution guide justifying this somewhat unconventional approach:

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.

Sometimes I don't follow my own guidance, when I decide "if the provider doesn't return this field then the response is useless". But sticking to it as much as possible has reduced some headaches for me (even though it makes the callsite more annoying because the caller has to unwrap the optional for any property they are interested in).

@provencher
Copy link
Author

+1 I don't mind unwrapping what I need.

@provencher
Copy link
Author

Another user report for a field that didn't show up on some providers.

--
Error:
dataCouldNotBeReadMissingData(description: "Key 'choices' not found: No value associated with key CodingKeys(stringValue: "choices", intValue: nil) ("choices").codingPath: []")

@jamesrochabrun
Copy link
Owner

Thanks @lzell for the suggestion, I think this is the only option to make a package friendly for different providers https://github.com/jamesrochabrun/SwiftOpenAI/releases/tag/v4.0.3
@provencher this should be resolved 🤞

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

No branches or pull requests

3 participants