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;
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.
triggers here, even with code 200 and valid SRT text in the response text