-
-
Notifications
You must be signed in to change notification settings - Fork 284
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Basic checks
- I searched existing issues - this hasn't been reported
- I can reproduce this consistently
- This is a RubyLLM bug, not my application code
What's broken?
When using MP3 files (without ActiveStorage) as attachments you get the following:
RubyLLM::ErrorMiddleware.parse_error': Invalid value: 'mpeg'. Supported values are: 'wav' and 'mp3'. (RubyLLM::BadRequestError)
How to reproduce
Run rails c
chat = RubyLLM.chat(model: 'gpt-4o-audio-preview').ask("whisper.mp3")
DEBUG -- RubyLLM: request: POST https://api.openai.com/v1/chat/completions
DEBUG -- RubyLLM: request: {"model":"gpt-4o-audio-preview","messages":[{"role":"user","content":[{"type":"text","text":"Please transcribe this audio file in vvt format."},{"type":"input_audio","input_audio":{"data":"data":"[BASE64 DATA]"","format":"mpeg"}}]}],"stream":false}
DEBUG -- RubyLLM: error: /ruby-3.4.2/gems/ruby_llm-1.6.4/lib/ruby_llm/error.rb:52:in 'RubyLLM::ErrorMiddleware.parse_error': Invalid value: 'mpeg'. Supported values are: 'wav' and 'mp3'. (RubyLLM::BadRequestError)
Expected behavior
I would expect that the file is uploaded and transcoded. It works using the OpenAI API playground
What actually happened
I expect the cause is here:
def format_audio(audio)
{
type: 'input_audio',
input_audio: {
data: audio.encoded,
format: audio.mime_type.split('/').last
}
}
end
The mime type for mp3 is:
file --mime "whisper.mp3"
whisper.mp3: audio/mpeg; charset=binary
Which sets the format to mpeg
I'm happy to take a swing at this but would need to set to mp3
if mime_type was audio/mpeg
and extension was also mp3
, otherwise fallback to the original method.
Thoughts?
Environment
- ruby-3.4.2
- ruby_llm-1.6.4
- openai
- mac os 15.6.1
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working