question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to use stream: true?

See original GitHub issue

I’m a bit lost as to how to actually use stream: true in this library.

Example incorrect syntax:

const res = await openai.createCompletion({
  model: "text-davinci-002",
  prompt: "Say this is a test",
  max_tokens: 6,
  temperature: 0,
  stream: true,
});

res.onmessage = (event) => {
  console.log(event.data);
}

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:3
  • Comments:11

github_iconTop GitHub Comments

2reactions
smervscommented, Dec 5, 2022

@smervs your code is working for me, but it logs as

<Buffer 64 61 74 61 3a 20 7b 22 69 64 22 3a 20 22 63 6d 70 6c 2d 36 4a 6e 56 35 4d 70 4d 41 44 4f 41 61 56 74 50 64 30 56 50 72 45 42 4f 62 34 48 54 6c 22 2c ... 155 more bytes>

Do you know how to parse this response?

here

res.data.on('data', data => console.log(data.toString()))
2reactions
smervscommented, Dec 1, 2022

You can use axios stream response type. But you still need to parse the returned data.

const res = await openai.createCompletion({
  model: "text-davinci-002",
  prompt: "Say this is a test",
  max_tokens: 6,
  temperature: 0,
  stream: true,
}, { responseType: 'stream' });

res.on('data', console.log)
Read more comments on GitHub >

github_iconTop Results From Across the Web

How does requests' stream=True option streams data one ...
I've checked several SOF questions and looked at the requests library documentation, but all resources explain how to use the library to ...
Read more >
Python Requests: response.content vs stream=True - Reddit
Using stream will start writing to the file before the entire file is downloaded. Whether that's a good or bad thing depends entirely...
Read more >
requests.get(stream=True) will get incomplete data #4227
the content I get is incomplete.But when I use stream=False,I can get complete data. when I set stream=True and response.iter_content(chunk_size ...
Read more >
Advanced Usage — Requests 2.28.1 documentation
with requests.get('https://httpbin.org/get', stream=True) ...
Read more >
Streaming requests with the fetch API - Chrome Developers
This shows how you can stream data from the user to the server, and send data back that can be processed in real...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found