BuilderIO / ai-shell

A CLI that converts natural language to shell commands.
MIT License
4.08k stars 261 forks source link

Stream responses from OpenAI API #3

Closed steve8708 closed 1 year ago

steve8708 commented 1 year ago

Instead of making the user wait for the entire output of the shell code or description to be finished to see it, it would be great to stream the response word by word to the terminal like done on sites like chatgpt

steve8708 commented 1 year ago

how this can be done:

  const res = await openai.createChatCompletion({
    messages: [{ content: prompt }],
    stream: true,
  }, { responseType: "stream" });

now the response will be a text stream. we could stream the response to the CLI output with process.stdout.write

more context/examples: https://twitter.com/Steve8708/status/1644377554034503680