Hello I'm trying to post files to OpenAI using Synapse and delphi.

The basice code to send the file and the commands are working as expected
and can be seen below.
However it seems that OpenAI expects the data to be encoded using the RFC
2388 <https://www.ietf.org/rfc/rfc2388.txt> standard which is what Curl is
also using and when i use Curl to upload the file it works fine.
But when i try using the code below the answer i get back is that the data
is invalid and according to the Curl documentation the content is encoded:
-F, --form <name=content>
(HTTP SMTP IMAP) For the HTTP protocol family, emulate a filled-in form in
which a user has pressed the submit button. This makes curl POST data using
the Content-Type multipart/form-data according to RFC 2388
<https://www.ietf.org/rfc/rfc2388.txt>.

So how do i encode the my data according to RFC-2388 standard before
posting it?

This is my synapse code:

    HTTP := THTTPSend.Create;
    try
        HTTP.Headers.Add('Authorization: Bearer ' + OPENAI_API_KEY);
        WriteStrToStream(HTTP.Document,
            '--' + Bound + CRLF +
            'Content-Disposition: form-data; name=' +
AnsiQuotedStr('model', '"') + CRLF +
            'Content-Type: text/plain' + CRLF +
            CRLF);
        WriteStrToStream(HTTP.Document, 'whisper-1');
        WriteStrToStream(HTTP.Document,
              CRLF +
              '--' + Bound + CRLF +
              'Content-Disposition: form-data; name=' +
AnsiQuotedStr('response_format', '"') + CRLF +
              'Content-Type: text/plain' + CRLF +
              CRLF);
            WriteStrToStream(HTTP.Document, 'srt');
        WriteStrToStream(HTTP.Document,
            CRLF +
            '--' + Bound + CRLF +
            'Content-Disposition: form-data; name=' + AnsiQuotedStr('file',
'"') + ';' + CRLF +
            'Content-Type: application/octet-string' + CRLF +
            CRLF);
        HTTP.Document.CopyFrom(fileStream, 0);
        WriteStrToStream(HTTP.Document,
            CRLF +
            '--' + Bound + '--' + CRLF);
        HTTP.MimeType := 'multipart/form-data; boundary=' + Bound;
        Result := HTTP.HTTPMethod('POST', '
https://api.openai.com/v1/audio/transcriptions');

Regards
Uffe Hammer




<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
Virusfri.www.avast.com
<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
_______________________________________________
synalist-public mailing list
synalist-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/synalist-public

Reply via email to