File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import 'dotenv/config' ;
2+ import { Langbase , getToolsFromRun , getToolsFromRunStream } from 'langbase' ;
3+
4+ const langbase = new Langbase ( {
5+ apiKey : process . env . LANGBASE_API_KEY ! ,
6+ } ) ;
7+
8+ async function main ( ) {
9+ const userMsg = "What's the weather in SF" ;
10+
11+ const response = await langbase . pipe . run ( {
12+ messages : [
13+ {
14+ role : 'user' ,
15+ content : userMsg ,
16+ } ,
17+ ] ,
18+ stream : true ,
19+ name : 'summary' ,
20+ tools : [
21+ {
22+ type : 'function' ,
23+ function : {
24+ name : 'get_current_weather' ,
25+ description : 'Get the current weather of a given location' ,
26+ parameters : {
27+ type : 'object' ,
28+ required : [ 'location' ] ,
29+ properties : {
30+ unit : {
31+ enum : [ 'celsius' , 'fahrenheit' ] ,
32+ type : 'string' ,
33+ } ,
34+ location : {
35+ type : 'string' ,
36+ description :
37+ 'The city and state, e.g. San Francisco, CA' ,
38+ } ,
39+ } ,
40+ } ,
41+ } ,
42+ } ,
43+ ] ,
44+ } ) ;
45+
46+ const tools = await getToolsFromRunStream ( response ) ;
47+
48+ if ( tools . length ) {
49+ // handle the tool calls
50+ console . log ( 'Tools:' , tools ) ;
51+ } else {
52+ // handle the response
53+ console . log ( 'Response:' , response ) ;
54+ }
55+ }
56+
57+ main ( ) ;
Original file line number Diff line number Diff line change 1+ import 'dotenv/config' ;
2+ import { Langbase , getToolsFromRun } from 'langbase' ;
3+
4+ const langbase = new Langbase ( {
5+ apiKey : process . env . LANGBASE_API_KEY ! ,
6+ } ) ;
7+
8+ async function main ( ) {
9+ const userMsg = "What's the weather in SF" ;
10+
11+ const response = await langbase . pipe . run ( {
12+ messages : [
13+ {
14+ role : 'user' ,
15+ content : userMsg ,
16+ } ,
17+ ] ,
18+ stream : false ,
19+ name : 'summary' ,
20+ tools : [
21+ {
22+ type : 'function' ,
23+ function : {
24+ name : 'get_current_weather' ,
25+ description : 'Get the current weather of a given location' ,
26+ parameters : {
27+ type : 'object' ,
28+ required : [ 'location' ] ,
29+ properties : {
30+ unit : {
31+ enum : [ 'celsius' , 'fahrenheit' ] ,
32+ type : 'string' ,
33+ } ,
34+ location : {
35+ type : 'string' ,
36+ description :
37+ 'The city and state, e.g. San Francisco, CA' ,
38+ } ,
39+ } ,
40+ } ,
41+ } ,
42+ } ,
43+ ] ,
44+ } ) ;
45+
46+ const tools = await getToolsFromRun ( response ) ;
47+
48+ if ( tools . length ) {
49+ // handle the tool calls
50+ console . log ( 'Tools:' , tools ) ;
51+ } else {
52+ // handle the response
53+ console . log ( 'Response:' , response ) ;
54+ }
55+ }
56+
57+ main ( ) ;
Original file line number Diff line number Diff line change 2121 "pipe.update" : " npx tsx ./examples/pipes/pipe.update.ts" ,
2222 "pipe.list" : " npx tsx ./examples/pipes/pipe.list.ts" ,
2323 "pipe.run" : " npx tsx ./examples/pipes/pipe.run.ts" ,
24+ "pipe.tool" : " npx tsx ./examples/pipes/pipe.tool.ts" ,
25+ "pipe.tool.stream" : " npx tsx ./examples/pipes/pipe.tool.stream.ts" ,
2426 "pipe.run.stream" : " npx tsx ./examples/pipes/pipe.run.stream.ts" ,
2527 "pipe.run.stream.llmkey" : " npx tsx ./examples/pipes/pipe.run.stream.llmkey.ts" ,
2628 "generate-text-generate-pipe" : " npx tsx ./examples/pipes/generate-text-generate-pipe.ts" ,
You can’t perform that action at this time.
0 commit comments