-
Notifications
You must be signed in to change notification settings - Fork 3
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
05be989
commit d39f27a
Showing
4 changed files
with
60 additions
and
5 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,18 @@ | ||
import 'dotenv/config'; | ||
import {Pipe} from 'langbase'; | ||
|
||
// STREAM: OFF | ||
console.log('STREAM-OFF: generateText()'); | ||
|
||
// 1. Initiate the Pipe. | ||
const pipeStreamOff = new Pipe({ | ||
apiKey: process.env.PIPE_LESS_WORDY!, | ||
}); | ||
|
||
// 3. Generate the text by asking a question. | ||
const result = await pipeStreamOff.generateText({ | ||
messages: [{role: 'user', content: 'Who is an AI Engineer?'}], | ||
}); | ||
|
||
// 4. Done: You got the generated completion. | ||
console.log(result.completion); |
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 |
---|---|---|
|
@@ -5,7 +5,9 @@ | |
"type": "module", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "npx tsx index.ts" | ||
"test": "npx tsx index.ts", | ||
"generate-text": "npx tsx generate-text.ts", | ||
"stream-text": "npx tsx stream-text.ts" | ||
}, | ||
"keywords": [], | ||
"author": "Ahmad Awais <[email protected]> (https://twitter.com/MrAhmadAwais)", | ||
|
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,24 @@ | ||
import 'dotenv/config'; | ||
import {Pipe} from 'langbase'; | ||
|
||
// STREAM: ON | ||
console.log('STREAM-ON: streamText()'); | ||
|
||
// 1. Initiate the Pipe. | ||
const pipeStreaming = new Pipe({ | ||
apiKey: process.env.PIPE_LESS_WORDY_STREAM!, | ||
}); | ||
|
||
// 2. Generate a stream by asking a question | ||
const stream = await pipeStreaming.streamText({ | ||
messages: [{role: 'user', content: 'Who is an AI Engineer?'}], | ||
}); | ||
|
||
// 3. Print the stream | ||
for await (const chunk of stream) { | ||
// Streaming text part — a single word or several. | ||
const textPart = chunk.choices[0]?.delta?.content || ''; | ||
|
||
// Demo: Print the stream — you can use it however. | ||
process.stdout.write(textPart); | ||
} |