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

Can OpenAI.Chat.Create works asynchronously? #26

Closed
alanccw opened this issue Nov 3, 2023 · 2 comments
Closed

Can OpenAI.Chat.Create works asynchronously? #26

alanccw opened this issue Nov 3, 2023 · 2 comments
Assignees
Labels
question Further information is requested

Comments

@alanccw
Copy link

alanccw commented Nov 3, 2023

Hi,

I try to use the following statement to send a prompt to OpenAI. However, it usually takes about 38s to get a response, during this period. The application is blocked. Is there a way to send the prompt asynchronously so that the function will return immediately and when the response is back, a callback function can be notified?

var Chat := OpenAI.Chat.Create(
  procedure(Params: TChatParams)
  begin
    Params.Messages([TChatMessageBuild.Create(TMessageRole.User, Text)]);
    Params.MaxTokens(1024);
  end);

Thank you.

@HemulGM
Copy link
Owner

HemulGM commented Nov 3, 2023

Just use Tasks (System.Threading). The library is thread safe

@alanccw
Copy link
Author

alanccw commented Nov 3, 2023

Thank you so much. Just check that and it seems TTask is a simplified version of TThread that does not require me to inherit a class and implement Execute. Much simpler. Thank you.

@HemulGM HemulGM self-assigned this Nov 3, 2023
@HemulGM HemulGM added the question Further information is requested label Nov 3, 2023
@HemulGM HemulGM closed this as completed Nov 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants