HemulGM / DelphiOpenAI

OpenAI API wrapper for Delphi. Use ChatGPT, DALL-E, Whisper and other products.
MIT License
242 stars 58 forks source link

How stream mode works? #7

Closed wxinix-2022 closed 1 year ago

wxinix-2022 commented 1 year ago

I don't see "stream.id" is ever used/defined - then how to continue the chat/completion stream?

HemulGM commented 1 year ago
OpenAI.Chat.CreateStream(
  procedure(Params: TChatParams)
  begin
    Params.Messages([TchatMessageBuild.User(Buf.Text)]);
    Params.MaxTokens(1024);
    Params.Stream;
  end,
  procedure(Chat: TChat; IsDone: Boolean; var Cancel: Boolean)
  begin
    if (not IsDone) and Assigned(Chat) then
      Writeln(Chat.Choices[0].Delta.Content)
    else if IsDone then
      Writeln('DONE!');
    Writeln('-------');
    Sleep(100);
  end);
HemulGM commented 1 year ago

Stream mode is another way to get a response from the server. The data is transferred as soon as it is ready.