@@ -32,16 +32,16 @@ yarn add langbase
3232
3333### Usage
3434
35- You can [ ` generateText ` ] ( https:// langbase.com/docs/langbase-sdk/generate-text ) or [ ` streamText ` ] ( https://langbase.com/docs/langbase- sdk/stream-text ) based on the type of a pipe .
35+ You can [ ` langbase.pipe.run() ` ] ( https://langbase.com/docs/sdk/pipe/run ) to generate or stream from a Pipe .
3636
37- Check our [ SDK documentation] ( https://langbase.com/docs/langbase- sdk/overview ) for more details.
37+ Check our [ SDK documentation] ( https://langbase.com/docs/sdk ) for more details.
3838
3939### Example projects
4040
4141Check the following examples:
4242
43- - [ Node: Generate Text] ( https://github.com/LangbaseInc/langbase-sdk/blob/main/examples/everything/generate-text .ts )
44- - [ Node: Stream Text] ( https://github.com/LangbaseInc/langbase-sdk/blob/main/examples/everything/ stream-text .ts )
43+ - [ Node: Generate Text] ( https://github.com/LangbaseInc/langbase-sdk/blob/main/examples/nodejs/examples/pipes/pipe.run .ts )
44+ - [ Node: Stream Text] ( https://github.com/LangbaseInc/langbase-sdk/blob/main/examples/nodejs/examples/pipes/pipe.run. stream.ts )
4545- [ Next.js Example] ( https://github.com/LangbaseInc/langbase-sdk/tree/main/examples/nextjs )
4646 - TypeScript code
4747 - [ React component] ( https://github.com/LangbaseInc/langbase-sdk/tree/main/examples/nextjs/components/langbase ) to display the response
@@ -52,69 +52,85 @@ Check the following examples:
5252
5353## Node.js Examples
5454
55- ### Add a ` .env ` file with your Pipe API key
55+ ### Add a ` .env ` file with your LANGBASE API key
5656
5757``` bash
5858# Add your Pipe API key here.
59- LANGBASE_PIPE_API_KEY= " pipe_12345 ` "
59+ LANGBASE_API_KEY= " your-api-key "
6060```
6161
6262---
6363
64- # ## Generate text [`generateText ()`](https://langbase.com/docs/langbase- sdk/generate-text )
64+ ### Generate text [ ` langbase.pipe.run ()` ] ( https://langbase.com/docs/sdk/pipe/run )
6565
66- For more check the API reference of [` generateText ()` ](https://langbase.com/docs/langbase-sdk/generate-text)
66+ Set the ` stream ` to ` false ` . For more, check the API reference of [ ` langbase.pipe.run ()` ] ( https://langbase.com/docs/langbase-sdk/generate-text )
6767
6868``` ts
6969import ' dotenv/config' ;
70- import {Pipe } from 'langbase';
70+ import {Langbase } from ' langbase' ;
7171
72- // 1. Initiate the Pipe.
73- const pipe = new Pipe({
74- // Make sure you have a .env file with any pipe you wanna use.
75- // As a demo we're using a pipe that has less wordy responses.
76- apiKey: process.env.LANGBASE_PIPE_API_KEY!,
72+ // 1. Initiate the Langbase.
73+ const langbase = new Langbase ({
74+ // Make sure you have a .env file with LANGBASE_API_KEY.
75+ apiKey: process .env .LANGBASE_API_KEY ! ,
7776});
7877
79- // 3. Generate the text by asking a question.
80- const result = await pipe.generateText({
81- messages: [{role: 'user', content: 'Who is an AI Engineer?'}],
82- });
78+ async function main() {
79+ // 2. Run the pipe with a question.
80+ const response = await langbase .pipe .run ({
81+ stream: false ,
82+ name: ' summary' // pipe name to run
83+ messages : [
84+ {
85+ role: ' user' ,
86+ content: ' Who is an AI Engineer?' ,
87+ },
88+ ],
89+ });
90+
91+ // 3. Print the response.
92+ console .log (' response: ' , response );
93+ }
8394
84- // 4. Done: You got the generated completion.
85- console.log(result.completion);
95+ main ();
8696```
8797
8898---
8999
90- # ## Stream text [`streamText ()`](https://langbase.com/docs/langbase- sdk/stream-text )
100+ ### Stream text [ ` langbase.pipe.run ()` ] ( https://langbase.com/docs/sdk/pipe/run )
91101
92- For more check the API reference of [` streamText ()` ](https://langbase.com/docs/langbase-sdk/stream -text)
102+ Set the ` stream ` to ` true ` . For more, check the API reference of [ ` langbase.pipe.run ()` ] ( https://langbase.com/docs/langbase-sdk/generate -text )
93103
94104``` ts
95105import ' dotenv/config' ;
96- import {Pipe } from 'langbase';
106+ import {getRunner , Langbase } from ' langbase' ;
97107
98- // 1. Initiate the Pipe.
99- const pipe = new Pipe({
100- // Make sure you have a .env file with any pipe you wanna use.
101- // As a demo we're using a pipe that has less wordy responses.
102- apiKey: process.env.LANGBASE_PIPE_API_KEY!,
108+ // 1. Initiate the Langbase.
109+ const langbase = new Langbase ({
110+ // Make sure you have a .env file with LANGBASE_API_KEY.
111+ apiKey: process .env .LANGBASE_API_KEY ! ,
103112});
104113
105- // 2. Generate a stream by asking a question
106- const stream = await pipe.streamText({
107- messages: [{role: 'user', content: 'Who is an AI Engineer?'}],
108- });
114+ async function main() {
115+ const userMsg = ' Who is an AI Engineer?' ;
109116
110- // 3. Print the stream
111- for await (const chunk of stream) {
112- // Streaming text part — a single word or several.
113- const textPart = chunk.choices[0]?.delta?.content || '';
117+ // 2. Run the pipe with a question.
118+ const {stream, threadId, rawResponse} = await langbase .pipe .run ({
119+ stream: true ,
120+ name: ' summary' , // pipe name to run
121+ messages: [{role: ' user' , content: userMsg }],
122+ });
114123
115- // Demo: Print the stream — you can use it however.
116- process.stdout.write(textPart);
124+ // 3. Get the runner and listen to the content.
125+ const runner = getRunner (stream );
126+
127+ // 4. Print the response.
128+ runner .on (' content' , content => {
129+ process .stdout .write (content );
130+ });
117131}
132+
133+ main ();
118134```
119135
120- Check out [more examples in the docs](https://langbase.com/docs/langbase- sdk/examples) →
136+ Check out [ more examples in the docs] ( https://langbase.com/docs/sdk/examples ) →
0 commit comments