MagnivOrg / prompt-layer-library

🍰 PromptLayer - Maintain a log of your prompts and OpenAI API requests. Track, debug, and replay old completions.
https://www.promptlayer.com
Apache License 2.0
503 stars 46 forks source link

Make the `promptlayer_api_call` run in the background #7

Closed Jped closed 1 year ago

Jped commented 1 year ago

Right now we wait for the call to be completed, but we dont even do anything with the response (other than warn if there was an issue), we should be doing this in the background to speed things up.

I am thinking we do some simple python threading, create a thread that runs the process in the background, and then immediately return the openAI request

abubakarsohail commented 1 year ago

@Jped the network call itself is dependent on the network call to OpenAI and since this is the last I/O bound call in the process, I think we cannot optimize this in the background. We could hack and call it in a daemon thread but that won't guarantee it's execution because from Python documentation

Daemon threads are abruptly stopped at shutdown. Their resources (such as open files, database transactions, etc.) may not be released properly. If you want your threads to stop gracefully, make them non-daemonic and use a suitable signalling mechanism such as an Event.

Even if we do this in a thread, any remaining threads block the current execution and since this is the last network call in the process, it will still block and yield no results in optimization.

Jped commented 1 year ago

Hmm I hear, lets revisit this another way then.