spring-ai
spring-ai copied to clipboard
Add NotNull Validation & Add Nullable Annotation
While looking at the OpenAiGeneration metadata class and the OpenAiRateLimit class, we found a point of concern for NPE.
- For the OpenAiGenerationMetadata.From() method, we verified this because the internal block uses id and usage.
- For OpenAiRateLimit classes, @Nullable Annotation has been added because null can be inserted into the long type from outside.
For the OpenAiReateLimit class, these values should always come back from the openai request in the headers.
https://platform.openai.com/docs/guides/rate-limits/rate-limits-in-headers
I think it is incorrect to give a developer hints that it will be null, they should always be present.
Though I can see the fact that this may change beyond our control and using @nullable is a half way approach, but then perhaps we need to use Optional<> that makes for lots of verbosity.
When we review the overall organization of response objects multiple AI models (not just openai) we will revisit this.