What is the equivalent POST request using:
for this curl shell command:
curl --request POST \
--url https://api.someservice.com/v1/ \
--header 'Authorization: Bearer TOKEN' \
--header 'Content-Type: multipart/form-data' \
--form file=@/path/to/file/audio.mp3 \
--form transformer=trans-2 \
--form format=text
I tried following the examples in "Cro::HTTP::Client" without success...
(See the example starting with my $resp = await Cro::HTTP::Client.post: 'we.love.pand.as/pandas',)
Here is a working example using the answer of @jja that requires to:
Have an OpenAI (account and) authorization key
Download one of the MP3 files from here
use HTTP::Tiny;
my $fileName = $*HOME ~ '/Downloads/HelloRaccoonsEN.mp3';
say .<content>.decode given HTTP::Tiny.post: 'https://api.openai.com/v1/audio/transcriptions',
headers => { authorization => "Bearer {%*ENV<OPENAI_API_KEY>}" },
content => {
file => $fileName.IO,
model => 'whisper-1',
format => 'text'
};
Here is the expected result:
# {"text":"Raku practitioners around the world, eat more onions!"}
It would have been helpful to know what you attempted in order to work out how to correct it. Anyway, I'd expect the example request to look something like this in Cro:
my $resp = await Cro::HTTP::Client.post: 'https://api.someservice.com/v1/',
headers => [ Authorization => 'Bearer TOKEN' ],
content-type => 'multipart/form-data',
body => [
transformer => 'trans-2',
format => 'text',
Cro::HTTP::Body::MultiPartFormData::Part.new(
headers => [Cro::HTTP::Header.new(
name => 'Content-type',
value => 'audio/mpeg'
)],
name => 'file',
filename => 'audio.mp3',
body-blob => slurp('/path/to/file/audio.mp3', :bin)
)
];
I'm not sure exactly what mime type curl goes with, so it may slightly differ from what curl does in that regard.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With