Skip to content

Commit ba61afc

Browse files
committed
📖 DOC: Readme docs
1 parent 93d2a05 commit ba61afc

1 file changed

Lines changed: 35 additions & 9 deletions

File tree

packages/langbase/readme.md

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,57 @@ yarn add langbase
2828

2929
You can `generateText` or `streamText` based on the type of a pipe.
3030

31+
Check our [SDK documentation](https://langbase.com/docs) for more details.
32+
33+
### Example projects
34+
35+
Check the following examples:
36+
- [Node: Generate Text](https://github.com/LangbaseInc/langbase-sdk/blob/main/examples/everything/generate-text.ts)
37+
- [Node: Stream Text](https://github.com/LangbaseInc/langbase-sdk/blob/main/examples/everything/stream-text.ts)
38+
- [Next.js Example)](https://github.com/LangbaseInc/langbase-sdk/tree/main/examples/nextjs)
39+
- TypeScript code
40+
- [React component](https://github.com/LangbaseInc/langbase-sdk/tree/main/examples/nextjs/components/langbase) to display the response
41+
- [API Route handlers](https://github.com/LangbaseInc/langbase-sdk/tree/main/examples/nextjs/app/api/langbase/pipe) to send requests to ⌘ Langbase
42+
43+
### Demo code:
44+
3145
```TypeScript
3246
import 'dotenv/config';
3347
import {Pipe} from 'langbase';
3448

3549
// STREAM: OFF
36-
const pipeStreamOff = new Pipe({
50+
console.log('STREAM-OFF: generateText()');
51+
52+
// 1. Initiate the Pipe.
53+
const pipe = new Pipe({
3754
apiKey: process.env.PIPE_LESS_WORDY!,
3855
});
3956

40-
const result = await pipeStreamOff.generateText({
41-
messages: [{role: 'user', content: 'Who is Ahmad Awais?'}],
57+
// 3. Generate the text by asking a question.
58+
const result = await pipe.generateText({
59+
messages: [{role: 'user', content: 'Who is an AI Engineer?'}],
4260
});
4361

62+
// 4. Done: You got the generated completion.
4463
console.log(result.completion);
4564

65+
// ======= OR ======== //
66+
4667
// STREAM: ON
47-
const pipeStreaming = new Pipe({
48-
apiKey: process.env.PIPE_LESS_WORDY_STREAM!,
49-
});
68+
console.log('');
69+
console.log('STREAM-ON: streamText()');
5070

51-
const stream = await pipeStreaming.streamText({
52-
messages: [{role: 'user', content: 'Who is Ahmad Awais?'}],
71+
// 2. Generate a stream by asking a question
72+
const stream = await pipe.streamText({
73+
messages: [{role: 'user', content: 'Who is an AI Engineer?'}],
5374
});
5475

76+
// 3. Print the stream
5577
for await (const chunk of stream) {
56-
process.stdout.write(chunk.choices[0]?.delta?.content || '');
78+
// Streaming text part — a single word or several.
79+
const textPart = chunk.choices[0]?.delta?.content || '';
80+
81+
// Demo: Print the stream — you can use it however.
82+
process.stdout.write(textPart);
5783
}
5884
```

0 commit comments

Comments
 (0)