Closed AliDehbansiahkarbon closed 1 year ago
I can't remove System.JSON. And replace with, for example XSuperObject, too.
But with AddStream, you can solve something. Can you find an alternative way to add a stream to TMultipartFormData?
Sure, I already forked the repository, and I will work on these kinds of issues as soon as possible. I will inform you here at the end.
I managed to make this library work in Delphi 10.2 Tokyo, where AddStream is not available.
I made changes to these units: OpenAI.Audio, OpenAI.Files, OpenAI.Images.
Each line AddStream('file', Stream, FileName);
I replaced with simple AddFile('file', FileName);
One more thing. In TAudioTranslation, TImageEditParams, TImageVariationParams classes I added constructors like this.
constructor TAudioTranslation.Create;
begin
inherited Create(True);
Model('whisper-1');
end;
Without those constructors Audio translation, Image edit and variation didn't work. But audio transcription and Image creation worked though.
With the addition of a stream, I know the problem. But I already added the model to the constructor. although this is not required, it is only for convenience. The module can and should be specified when creating a request.
No, you didn't understand me. I added the whole constructor, not just the Model field. Constructor was missing in TAudioTranslation class. It didn't work because of this. Since TAudioTranscription had that constructor, audio transcription worked. Maybe it's only 10.2 Tokyo issue and in Delphi 11 everything works without it.
In Tokyo, is there no equivalent or way to add a stream to the request body field? If not, then you need to overload the method for Tokyo to transfer only the path to the file and you can do a PullRequest
@AndreyCh74 It's just a suggestion, if you are working on that it would be great if you try to define some compiler directives in this regard and make it efficiently compatible with more Delphi versions. You just need to indicate the compiler version and write the correct code. (https://docwiki.embarcadero.com/RADStudio/Sydney/en/Compiler_Versions)
I'm sorry but I have only 10.2 version and can't test the library on earlier versions. I also use old school classics - Delphi 7, but it's totally different.
Update the issue please.
It works perfect with Alexandria (The latest version at the time) and probably Rio, and of course, it's not mandatory but if you want to cover all Delphi versions then there should be some refinements. I couldn't compile the library properly in some earlier Delphi versions. Here is the result using XE5 and Berlin.
1- System.JSON is not available in my XE5 (maybe because of an installation fault I'm not sure) but I found this sentence in the Delphi Cookbook - Second Edition by Daniele Teti: Since version 2009, Delphi provides built-in support for JSON.
2- AddStream function is not available in the TMultipartFormData class in this unit: OpenAI.Files, tested with Berlin 10.1