lmnr 0.2.4__py3-none-any.whl → 0.2.5__py3-none-any.whl

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.
@@ -1,6 +1,7 @@
1
1
  from typing import Callable, Optional
2
2
  from websockets.sync.client import connect
3
- from lmnr.types import DeregisterDebuggerRequest, NodeInput, RegisterDebuggerRequest, SDKError, ToolCall
3
+ import websockets
4
+ from lmnr.types import DeregisterDebuggerRequest, NodeInput, RegisterDebuggerRequest, SDKError, ToolCall, ToolCallError
4
5
  import uuid
5
6
  import json
6
7
  from threading import Thread
@@ -47,6 +48,9 @@ class RemoteDebugger:
47
48
  message = websocket.recv(3)
48
49
  except TimeoutError:
49
50
  continue
51
+ except websockets.exceptions.ConnectionClosedError:
52
+ print("Connection closed. Please restart the debugger.")
53
+ return
50
54
  try:
51
55
  tool_call = ToolCall.model_validate_json(message)
52
56
  except:
@@ -56,11 +60,11 @@ class RemoteDebugger:
56
60
  if tool.__name__ == tool_call.function.name
57
61
  ]
58
62
  if not matching_tools:
59
- raise SDKError(
60
- f'Tool {tool_call.function.name} not found.'
61
- ' Registered tools: '
62
- f'{", ".join([tool.__name__ for tool in self.tools])}'
63
- )
63
+ error_message = f'Tool {tool_call.function.name} not found.' +\
64
+ f' Registered tools: {", ".join([tool.__name__ for tool in self.tools])}'
65
+ e = ToolCallError(error=error_message)
66
+ websocket.send(e.model_dump_json())
67
+ continue
64
68
  tool = matching_tools[0]
65
69
  if tool.__name__ == tool_call.function.name:
66
70
  # default the arguments to an empty dictionary
@@ -69,8 +73,13 @@ class RemoteDebugger:
69
73
  arguments = json.loads(tool_call.function.arguments)
70
74
  except:
71
75
  pass
72
- response = tool(**arguments)
73
- websocket.send(json.dumps(response))
76
+ try:
77
+ response = tool(**arguments) # of type NodeInput
78
+ websocket.send(json.dumps(response))
79
+ except Exception as e:
80
+ error_message = f'Error occurred while running tool {tool.__name__}: {e}'
81
+ e = ToolCallError(error=error_message)
82
+ websocket.send(e.model_dump_json())
74
83
  websocket.send(DeregisterDebuggerRequest(debuggerSessionId=self.session, deregister=True).model_dump_json())
75
84
 
76
85
  def _generate_session_id(self) -> str:
lmnr/types.py CHANGED
@@ -39,8 +39,8 @@ class EndpointRunError(Exception):
39
39
  return super().__str__()
40
40
 
41
41
  class SDKError(Exception):
42
- def __init__(self, error_mesasge: str):
43
- super().__init__(error_mesasge)
42
+ def __init__(self, error_message: str):
43
+ super().__init__(error_message)
44
44
 
45
45
  class ToolCallRequest(pydantic.BaseModel):
46
46
  name: str
@@ -51,6 +51,10 @@ class ToolCall(pydantic.BaseModel):
51
51
  type: Optional[str]
52
52
  function: ToolCallRequest
53
53
 
54
+ ToolCallResponse = NodeInput
55
+ class ToolCallError(pydantic.BaseModel):
56
+ error: str
57
+
54
58
  # TODO: allow snake_case and manually convert to camelCase
55
59
  class RegisterDebuggerRequest(pydantic.BaseModel):
56
60
  debuggerSessionId: str
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lmnr
3
- Version: 0.2.4
3
+ Version: 0.2.5
4
4
  Summary: Python SDK for Laminar AI
5
5
  License: Apache-2.0
6
6
  Author: lmnr.ai
@@ -121,9 +121,8 @@ Example:
121
121
  from lmnr import LaminarRemoteDebugger, NodeInput
122
122
 
123
123
  # adding **kwargs is safer, in case an LLM produces more arguments than needed
124
- def my_tool(arg1: string, arg2: string, **kwargs) -> NodeInput {
124
+ def my_tool(arg1: string, arg2: string, **kwargs) -> NodeInput:
125
125
  return f'{arg1}&{arg2}'
126
- }
127
126
 
128
127
  debugger = LaminarRemoteDebugger('<YOUR_PROJECT_API_KEY>', [my_tool])
129
128
  session_id = debugger.start() # the session id will also be printed to console
@@ -184,3 +183,4 @@ print(f"RESULT:\n{res}")
184
183
  ## PROJECT_API_KEY
185
184
 
186
185
  Read more [here](https://docs.lmnr.ai/api-reference/introduction#authentication) on how to get `PROJECT_API_KEY`.
186
+
@@ -19,10 +19,10 @@ lmnr/cli/{{cookiecutter.lmnr_pipelines_dir_name}}/pipelines/{{cookiecutter.pipel
19
19
  lmnr/cli/{{cookiecutter.lmnr_pipelines_dir_name}}/pipelines/{{cookiecutter.pipeline_dir_name}}/{{cookiecutter.pipeline_dir_name}}.py,sha256=WG-ZMofPpGXCx5jdWVry3_XBzcKjqn8ZycFSiWEOBPg,2858
20
20
  lmnr/cli/{{cookiecutter.lmnr_pipelines_dir_name}}/types.py,sha256=iWuflMV7TiaBPs6-B-BlrovvWpZgHGGHK0v8rSqER7A,997
21
21
  lmnr/sdk/endpoint.py,sha256=tT6-w-mwbh4BAwnj5G0pCVE_Sz8EUzZmpBtacm_T2pE,6359
22
- lmnr/sdk/remote_debugger.py,sha256=lAL7t0DXADLMTLsh6AN3rqVYf_A-aeG_mMbyU-G2wTk,3299
23
- lmnr/types.py,sha256=Pi6R5qMmN4fiwZR0TzP4rxfSP6rFv4iouZ_OKnJsmhA,1685
24
- lmnr-0.2.4.dist-info/LICENSE,sha256=67b_wJHVV1CBaWkrKFWU1wyqTPSdzH77Ls-59631COg,10411
25
- lmnr-0.2.4.dist-info/METADATA,sha256=BUDTL9WKd18EieHeb47or0gwjGd1dkSz0nJsvx6AFiw,5494
26
- lmnr-0.2.4.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
27
- lmnr-0.2.4.dist-info/entry_points.txt,sha256=Qg7ZRax4k-rcQsZ26XRYQ8YFSBiyY2PNxYfq4a6PYXI,41
28
- lmnr-0.2.4.dist-info/RECORD,,
22
+ lmnr/sdk/remote_debugger.py,sha256=pNSmmk-KAAOUygKQAeTB1DbB3vvlpHL8JLwPBpBhBwA,3892
23
+ lmnr/types.py,sha256=Y41GGiCVemBUCTKedCwDhxjdsoO8uENr3LRwfdp9MI0,1771
24
+ lmnr-0.2.5.dist-info/LICENSE,sha256=67b_wJHVV1CBaWkrKFWU1wyqTPSdzH77Ls-59631COg,10411
25
+ lmnr-0.2.5.dist-info/METADATA,sha256=BgYsaYsxprvRZ5-RxZk8DQdSTKmF51hOvU27hg_0wn4,5492
26
+ lmnr-0.2.5.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
27
+ lmnr-0.2.5.dist-info/entry_points.txt,sha256=Qg7ZRax4k-rcQsZ26XRYQ8YFSBiyY2PNxYfq4a6PYXI,41
28
+ lmnr-0.2.5.dist-info/RECORD,,
File without changes
File without changes