leafo / lua-openai

OpenAI API bindings for Lua
MIT License
52 stars 5 forks source link

Make _request response more useful when stream: true #6

Open johnd0e opened 6 months ago

johnd0e commented 6 months ago

(On top of #10)

This PR is created to discuss possible OpenAI\_request refactoring.

What's changed:

Reasoning:

  1. I argue that a simple plain-text return value proves to be quite ineffective when dealing with multiple SSE events. Consequently, it is more beneficial to allow the callback function to procure the entirety of the parsed data.
  2. Despite this, receiving integrated data as a return value might still be quite convenient. Use Case: The callback function primarily serves to display streaming output to the user. However, after this process, it becomes simpler to handle the integrated data.

The 1st one is most important, and I consider it as necessity. And I would like to know your opinion on the 2nd one.

To be done:

johnd0e commented 6 months ago

Done in the last commit. Cases where n>1 have also been tested.