@lmnr-ai/lmnr 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,22 +1,34 @@
1
1
  # Typescript SDK for Laminar AI
2
2
 
3
+ ## Quickstart
4
+
5
+ ```sh
6
+ npm install @lmnr-ai/lmnr
7
+ ```
8
+
9
+ ## Features
10
+
11
+ - Make Laminar endpoint calls from your JS code
12
+ - Make Laminar endpoint calls that can run your own functions as tools from your NodeJS code
13
+ - `LaminarRemoteDebugger` to execute your own functions while you test your flows in workshop
14
+
15
+ ## Making Laminar endpoint calls
16
+
17
+ After you are ready to use your pipeline in your code, deploy it in Laminar following the [docs](https://docs.lmnr.ai/pipeline/run-save-deploy#deploying-a-pipeline-version).
18
+
19
+ Once your pipeline is deployed, you can call it from JS in just a few lines.
20
+
3
21
  Example use:
4
22
 
5
23
  ```typescript
6
24
  import { Laminar, NodeInput } from '@lmnr-ai/lmnr';
7
25
 
8
- const myTool = ({arg1, arg2}: {arg1: string, arg2: number}): NodeInput => {
9
- // this tool teaches LLMs the beauty of JavaScript!
10
- return arg1 + arg2;
11
- }
12
-
13
26
  const l = new Laminar('<YOUR_PROJECT_API_KEY>');
14
27
  const result = await l.run({
15
28
  endpoint: 'my_endpoint_name',
16
29
  inputs: {'input': [{'role': 'user', 'content': 'hello'}]},
17
30
  env: {'OPENAI_API_KEY': 'sk-some-key'}, // optional
18
31
  metadata: {'session_id': 'your_custom_session_id'}, // optional
19
- tools: [myTool], // optional
20
32
  });
21
33
  ```
22
34
 
@@ -30,9 +42,86 @@ Resulting in:
30
42
  }
31
43
  ```
32
44
 
45
+ ### Making calls to pipelines that run your own logic
46
+
47
+ If your pipeline contains tool call nodes, they will be able to call your local code.
48
+ The only difference is that you need to pass references
49
+ to the functions you want to call right into our SDK.
50
+
33
51
  Tools must be functions that take in one object argument and perform
34
- the ES5+ object destructuring magic. Tools must return
52
+ the ES5+ object destructuring magic, e.g. `foo({a, b})`. Tools must return
35
53
  either a string or a list of chat messages
36
54
 
37
55
  Please note that, if you specify tools, a bi-directional communication to Laminar API will be established.
38
- This only works in Node execution context; browser context is not supported.
56
+ This only works in Node execution context; browser context is not supported.
57
+
58
+ Example use:
59
+
60
+ ```typescript
61
+ import { Laminar, NodeInput } from '@lmnr-ai/lmnr';
62
+
63
+ const myTool = ({arg1, arg2}: {arg1: string, arg2: number}): NodeInput => {
64
+ // this tool teaches LLMs the beauty of JavaScript!
65
+ return arg1 + arg2;
66
+ }
67
+
68
+ const l = new Laminar('<YOUR_PROJECT_API_KEY>');
69
+ const result = await l.run({
70
+ endpoint: 'my_endpoint_name',
71
+ inputs: {'input': [{'role': 'user', 'content': 'hello'}]},
72
+ env: {'OPENAI_API_KEY': 'sk-some-key'}, // optional
73
+ metadata: {'session_id': 'your_custom_session_id'}, // optional
74
+ // specify as many tools as needed,
75
+ // Each tool name must match tool node name in the pipeline
76
+ tools: [myTool],
77
+ });
78
+ ```
79
+
80
+ ### LaminarRemoteDebugger
81
+
82
+ If your pipeline contains tool call nodes, they will be able to call your local code.
83
+ If you want to test them from the Laminar workshop in your browser, you can attach to your
84
+ locally running debugger.
85
+
86
+ ### Step by step instructions to use `LaminarRemoteDebugger`:
87
+
88
+ #### 1. Create your pipeline with tool call nodes
89
+
90
+ Add tool calls to your pipeline; node names must match the functions you want to call.
91
+
92
+ #### 2. Start LaminarRemoteDebugger in your code
93
+
94
+ Example:
95
+
96
+ ```js
97
+ import { LaminarRemoteDebugger } from '@lmnr-ai/lmnr';
98
+
99
+ const myTool = ({arg1, arg2}: {arg1: string, arg2: number}): NodeInput => {
100
+ // this tool teaches LLMs the beauty of JavaScript!
101
+ return arg1 + arg2;
102
+ }
103
+
104
+ debugger = LaminarRemoteDebugger('<YOUR_PROJECT_API_KEY>', [my_tool]);
105
+ debugger.start();
106
+ // the session id will be printed to console.
107
+ // It is also returned from this promise, but you may not want to `await` it
108
+ ```
109
+
110
+ This will establish a connection with Laminar API and allow for the pipeline execution
111
+ to call your local functions.
112
+
113
+ #### 3. Link lmnr.ai workshop to your debugger
114
+
115
+ Set up `DEBUGGER_SESSION_ID` environment variable in your pipeline.
116
+
117
+ #### 4. Run and experiment
118
+
119
+ You can run as many sessions as you need, experimenting with your flows.
120
+
121
+ #### 5. Stop the debugger
122
+
123
+ In order to stop the session, do
124
+
125
+ ```js
126
+ debugger.stop()
127
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lmnr-ai/lmnr",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "TypeScript SDK for Laminar AI",
5
5
  "main": "src/index.ts",
6
6
  "repository": {
package/src/index.ts CHANGED
@@ -14,8 +14,7 @@ export class Laminar {
14
14
  constructor(projectApiKey: string) {
15
15
  this.projectApiKey = projectApiKey;
16
16
  this.url = 'https://api.lmnr.ai/v2/endpoint/run'
17
- // this.ws_url = 'wss://api.lmnr.ai/v2/endpoint/ws'
18
- this.ws_url = 'ws://localhost:8000/v2/endpoint/ws'
17
+ this.ws_url = 'wss://api.lmnr.ai/v2/endpoint/ws'
19
18
  }
20
19
 
21
20
  public async run(request: EndpointRunRequest): Promise<EndpointRunResponse> {