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

An SSE streamer for LLM , v2 #82

Closed
sciabarracom opened this issue Dec 4, 2024 · 1 comment
Closed

An SSE streamer for LLM , v2 #82

sciabarracom opened this issue Dec 4, 2024 · 1 comment
Assignees

Comments

@sciabarracom
Copy link
Contributor

Spec for the streamer.

The streamer is available as stream.<apihost> over https.

Optionally we may have also <user>.<apihost>/stream that is acutually proxying to stream.<apihost>/<user>

An user will stream an action <package>/<action> with:

const url = "/stream/<package>/<action>"
// or "https://stream.<apihost>/<user>/<package>/<action>"
const evtSource = new EventSource(url, {
  withCredentials: true,
  // other parameters here
});
evtSource.onmessage = (event) => {
  const data = event.data
  // do something with the event data
};

The steamer once received the request, assuming it is a json post,

  • parses the json
  • opens a socket for listening in a random port
  • invoke the action <user>/<package>/<action> asynchronously passing to the data additionally in the args the extra parameters STREAM_HOST and STREAM_PORT
  • wait in the socket the user writes the content to be streamed make a buffer
  • writes the content in the strem when it arrives
  • closes the socket once done

The user will use the stremer as follows:

def main(args):
    streamer = (args.get("STREAM_HOST"), args.get("STREAM_PORT"))
    if not socket[0] or not socket[1]:
        return {"body": "pleae invoke with the stremer"}
    // invoke a call to a streaming api server like OpenAI
    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
        s.connect(streamer)
        while <there are data>:
                data = <read data>
                s.sendall(data)
    return {"body": "done"}
@d4rkstar
Copy link
Contributor

this task was completed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants