Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenAI.Audio.CreateTranscription with SRT format causes OpenAIExceptionInvalidResponse #34

Open
Himeko7 opened this issue Nov 27, 2023 · 1 comment

Comments

@Himeko7
Copy link

Himeko7 commented Nov 27, 2023

When using the transcription functionality, if you request SRT format in the response, even though valid data is returned, it results in an OpenAIExceptionInvalidResponse exception. The problem is the returned data from the API is plain text SRT, not JSON data.

procedure TMainUI.Button3Click(Sender: TObject);
Var OpenAI: IOpenAI;
    AIT: TAudioTranscription;
    AIR: TAudioText;
begin
  OpenAI := TOpenAI.Create('***');

  AIR := TAudioText.Create;
  Try
  AIR := OpenAI.Audio.CreateTranscription(
    procedure(Params: TAudioTranscription)
    begin
      Params.&File('D:\test.mp4');
      Params.ResponseFormat('srt');
      Params.Language('en');
    end);
  Except
  on E: OpenAIExceptionInvalidResponse do
    Memo2.Lines.Add('OpenAI Error: ' + E.Message + ' - ' + E.Code.ToString);
  End;
    Memo2.Lines.Add(AIR.Text);

  AIR.Free;
end;

triggers here, even with code 200 and valid SRT text in the response text

function TOpenAIAPI.ParseResponse<T>(const Code: Int64; const ResponseText: string): T;
begin
  case Code of
    200..299:
      try
        Result := TJson.JsonToObject<T>(ResponseText);
      except
        Result := nil;
      end;
  else
    ParseError(Code, ResponseText);
  end;
  if not Assigned(Result) then
    raise OpenAIExceptionInvalidResponse.Create('Empty or invalid response:', '', '', Code);
end;
@HemulGM
Copy link
Owner

HemulGM commented Nov 27, 2023

Oh thanks. I'll take a look and fix it soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants