spring-ai icon indicating copy to clipboard operation
spring-ai copied to clipboard

Add NotNull Validation & Add Nullable Annotation

Open hgs-study opened this issue 1 year ago • 3 comments

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.

hgs-study avatar Dec 18 '23 14:12 hgs-study

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.

markpollack avatar Dec 18 '23 17:12 markpollack

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.

markpollack avatar Dec 18 '23 18:12 markpollack

When we review the overall organization of response objects multiple AI models (not just openai) we will revisit this.

markpollack avatar Feb 29 '24 15:02 markpollack