-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
PR closed due to unresolved review loop #8021
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
Changes from all commits
56d4079
1144797
e85f008
09bc47f
bb28953
d5354de
3ec643c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -21,15 +21,17 @@ async function main() { | |||||||
const data = await response.json(); | ||||||||
console.log(data); | ||||||||
// returns something like: | ||||||||
// [ | ||||||||
// { | ||||||||
// userId: 1, | ||||||||
// id: 1, | ||||||||
// title: 'sunt aut facere repellat provident occaecati excepturi optio reprehenderit', | ||||||||
// body: 'quia et suscipit\n' + | ||||||||
// 'suscipit recusandae consequuntur expedita et cum\n' + | ||||||||
// 'reprehenderit molestiae ut ut quas totam\n' + | ||||||||
// 'nostrum rerum est autem sunt rem eveniet architecto' | ||||||||
// } | ||||||||
// userId: 1, | ||||||||
// id: 1, | ||||||||
// title: 'sunt aut facere repellat provident occaecati excepturi optio reprehenderit', | ||||||||
// body: 'quia et suscipit\n' + | ||||||||
// 'suscipit recusandae consequuntur expedita et cum\n' + | ||||||||
// 'reprehenderit molestiae ut ut quas totam\n' + | ||||||||
// 'nostrum rerum est autem sunt rem eveniet architecto' | ||||||||
// } | ||||||||
// ] | ||||||||
} | ||||||||
|
||||||||
main().catch(console.error); | ||||||||
|
@@ -108,10 +110,11 @@ async function streamOllamaCompletion(prompt) { | |||||||
} | ||||||||
|
||||||||
let partial = ''; | ||||||||
|
||||||||
const decoder = new TextDecoder(); | ||||||||
|
||||||||
for await (const chunk of body) { | ||||||||
partial += decoder.decode(chunk, { stream: true }); | ||||||||
// Note: decoder.decode() with { stream: true } may buffer incomplete UTF-8 chunks. | ||||||||
console.log(partial); | ||||||||
} | ||||||||
|
||||||||
|
@@ -134,7 +137,6 @@ try { | |||||||
|
||||||||
```js | ||||||||
import { Writable } from 'stream'; | ||||||||
|
||||||||
import { stream } from 'undici'; | ||||||||
|
||||||||
async function fetchGitHubRepos() { | ||||||||
|
@@ -155,23 +157,21 @@ async function fetchGitHubRepos() { | |||||||
return new Writable({ | ||||||||
write(chunk, encoding, callback) { | ||||||||
buffer += chunk.toString(); | ||||||||
|
||||||||
callback(); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was this added? |
||||||||
}, | ||||||||
final(callback) { | ||||||||
try { | ||||||||
const json = JSON.parse(buffer); | ||||||||
console.log( | ||||||||
'Repository Names:', | ||||||||
json.map(repo => repo.name) | ||||||||
); | ||||||||
buffer = ''; | ||||||||
} catch (error) { | ||||||||
console.error('Error parsing JSON:', error); | ||||||||
} finally { | ||||||||
console.log('Stream processing completed.'); | ||||||||
callback(); | ||||||||
} | ||||||||
|
||||||||
callback(); | ||||||||
}, | ||||||||
final(callback) { | ||||||||
console.log('Stream processing completed.'); | ||||||||
callback(); | ||||||||
Comment on lines
169
to
-174
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The point of this demo is to showcase the callback, let's not change it to a try final There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agree with aviv here - sometimes we choose to show code concepts in isolation even if a production app would have far more rigor |
||||||||
}, | ||||||||
}); | ||||||||
} | ||||||||
|
@@ -181,4 +181,4 @@ async function fetchGitHubRepos() { | |||||||
} | ||||||||
|
||||||||
fetchGitHubRepos().catch(console.error); | ||||||||
``` | ||||||||
``` | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this relevant to the code snippet?