File tree Expand file tree Collapse file tree 3 files changed +69
-0
lines changed
Expand file tree Collapse file tree 3 files changed +69
-0
lines changed Original file line number Diff line number Diff line change 1+ import 'dotenv/config' ;
2+ import { Langbase } from 'langbase' ;
3+
4+ const langbase = new Langbase ( {
5+ apiKey : process . env . LANGBASE_API_KEY ! ,
6+ } ) ;
7+
8+ async function main ( ) {
9+ // Message 1: Tell something to the LLM.
10+ const response1 = await langbase . pipe . run ( {
11+ name : 'summary' ,
12+ messages : [ { role : 'user' , content : 'My company is called Langbase' } ] ,
13+ } ) ;
14+
15+ console . log ( response1 . completion ) ;
16+
17+ // Message 2: Ask something about the first message.
18+ // Continue the conversation in the same thread by sending
19+ // `threadId` from the second message onwards.
20+ const response2 = await langbase . pipe . run ( {
21+ name : 'summary' ,
22+ threadId : response1 . threadId ! ,
23+ messages : [ { role : 'user' , content : 'Tell me the name of my company?' } ] ,
24+ } ) ;
25+
26+ console . log ( response2 . completion ) ;
27+ // You'll see any LLM will know the company is `Langbase`
28+ // since it's the same chat thread. This is how you can
29+ // continue a conversation in the same thread.
30+ }
31+
32+ main ( ) ;
Original file line number Diff line number Diff line change 1+ import 'dotenv/config' ;
2+ import { Langbase , getRunner } from 'langbase' ;
3+
4+ const langbase = new Langbase ( {
5+ apiKey : process . env . LANGBASE_API_KEY ! ,
6+ } ) ;
7+
8+ // Message 1: Tell something to the LLM.
9+ const response1 = await langbase . pipe . run ( {
10+ name : 'summary' ,
11+ stream : true ,
12+ messages : [ { role : 'user' , content : 'My company is called Langbase' } ] ,
13+ } ) ;
14+
15+ const runner1 = getRunner ( response1 . stream ) ;
16+
17+ runner1 . on ( 'content' , content => {
18+ process . stdout . write ( content ) ;
19+ } ) ;
20+
21+ // Message 2: Ask something about the first message.
22+ // Continue the conversation in the same thread by sending
23+ // `threadId` from the second message onwards.
24+ const response2 = await langbase . pipe . run ( {
25+ name : 'summary' ,
26+ stream : true ,
27+ threadId : response1 . threadId ! ,
28+ messages : [ { role : 'user' , content : 'Tell me the name of my company?' } ] ,
29+ } ) ;
30+
31+ const runner2 = getRunner ( response2 . stream ) ;
32+
33+ runner2 . on ( 'content' , content => {
34+ process . stdout . write ( content ) ;
35+ } ) ;
Original file line number Diff line number Diff line change 88 "scripts" : {
99 "generate-text" : " npx tsx ./examples/pipes/generate-text.ts" ,
1010 "pipe.create" : " npx tsx ./examples/pipes/pipe.create.ts" ,
11+ "pipe.run.chat" : " npx tsx ./examples/pipes/pipe.run.chat.ts" ,
12+ "pipe.run.stream.chat" : " npx tsx ./examples/pipes/pipe.run.stream.chat.ts" ,
1113 "memory.create" : " npx tsx ./examples/memory/memory.create.ts" ,
1214 "memory.list" : " npx tsx ./examples/memory/memory.list.ts" ,
1315 "memory.delete" : " npx tsx ./examples/memory/memory.delete.ts" ,
You can’t perform that action at this time.
0 commit comments