sashirestela / simple-openai

A Java library to use the OpenAI Api in the simplest possible way.
MIT License
182 stars 17 forks source link

Assistant Message is not handling null Audio objects #208

Closed nullquery closed 5 days ago

nullquery commented 1 week ago

It looks like somebody decided to implement audio support for chat messages without properly testing their code or double-checking the OpenAI documentation. 😮

I am now getting errors from OpenAI because an audio object is being sent without an ID.

The offending piece of code is here: https://github.com/sashirestela/simple-openai/blob/f4b78c1223ece13c1f80e894753dbb34686986ba/src/main/java/io/github/sashirestela/openai/domain/chat/ChatMessage.java#L123

The fix is not to create the audio object if there is no audio ID. The value is supposed to remain null in that case.

E.x.,

this.audio = audioId == null || audioId.isEmpty() ? null : new Audio(audioId); 

For the moment, I'm able to work around this by using reflection to set the field to null.

sashirestela commented 5 days ago

The fix has been deployed as part of the release 3.9.1