-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d444439
commit a38b2bc
Showing
5 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
"@clack/prompts": minor | ||
--- | ||
|
||
Adds `stream` API which provides the same methods as `log`, but for iterable (even async) message streams. This is particularly useful for AI responses which are dynamically generated by LLMs. | ||
|
||
```ts | ||
import * as p from '@clack/prompts'; | ||
|
||
await p.stream.step((async function* () { | ||
yield* generateLLMResponse(question); | ||
})()) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { setTimeout } from 'node:timers/promises'; | ||
import * as p from '@clack/prompts'; | ||
import color from 'picocolors'; | ||
|
||
async function main() { | ||
console.clear(); | ||
|
||
await setTimeout(1000); | ||
|
||
p.intro(`${color.bgCyan(color.black(' create-app '))}`); | ||
|
||
await p.stream.step((async function* () { | ||
for (const line of lorem) { | ||
for (const word of line.split(' ')) { | ||
yield word; | ||
yield ' '; | ||
await setTimeout(200); | ||
} | ||
yield '\n'; | ||
if (line !== lorem.at(-1)) { | ||
await setTimeout(1000); | ||
} | ||
} | ||
})()) | ||
|
||
p.outro(`Problems? ${color.underline(color.cyan('https://example.com/issues'))}`); | ||
} | ||
|
||
const lorem = [ | ||
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.', | ||
'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.', | ||
] | ||
|
||
main().catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters