lmnr 0.1.0__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.
Potentially problematic release.
This version of lmnr might be problematic. Click here for more details.
- lmnr/__init__.py +1 -0
- lmnr/endpoint.py +42 -0
- lmnr/model.py +38 -0
- lmnr-0.1.0.dist-info/LICENSE +7 -0
- lmnr-0.1.0.dist-info/METADATA +37 -0
- lmnr-0.1.0.dist-info/RECORD +7 -0
- lmnr-0.1.0.dist-info/WHEEL +4 -0
lmnr/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .endpoint import Laminar
|
lmnr/endpoint.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from pydantic.alias_generators import to_snake
|
|
3
|
+
import requests
|
|
4
|
+
from .model import EndpointRunError, EndpointRunResponse, NodeInput, EndpointRunRequest
|
|
5
|
+
|
|
6
|
+
class Laminar:
|
|
7
|
+
project_api_key: str | None = None
|
|
8
|
+
def __init__(self, project_api_key: str):
|
|
9
|
+
self.project_api_key = project_api_key
|
|
10
|
+
self.url = 'https://api.lmnr.ai/v2/endpoint/run'
|
|
11
|
+
|
|
12
|
+
def run(
|
|
13
|
+
self,
|
|
14
|
+
endpoint: str,
|
|
15
|
+
inputs: dict[str, NodeInput],
|
|
16
|
+
env: dict[str, str] = {},
|
|
17
|
+
metadata: dict[str, str] = {}
|
|
18
|
+
) -> EndpointRunResponse:
|
|
19
|
+
if self.project_api_key is None:
|
|
20
|
+
raise ValueError('Please initialize the Laminar object with your project API key')
|
|
21
|
+
try:
|
|
22
|
+
request = EndpointRunRequest(inputs = inputs, endpoint = endpoint, env = env, metadata = metadata)
|
|
23
|
+
except Exception as e:
|
|
24
|
+
raise ValueError(f'Invalid request: {e}')
|
|
25
|
+
response = requests.post(
|
|
26
|
+
self.url,
|
|
27
|
+
json=json.loads(request.model_dump_json()),
|
|
28
|
+
headers={'Authorization': f'Bearer {self.project_api_key}'}
|
|
29
|
+
)
|
|
30
|
+
if response.status_code != 200:
|
|
31
|
+
raise EndpointRunError(response)
|
|
32
|
+
try:
|
|
33
|
+
resp_json = response.json()
|
|
34
|
+
keys = list(resp_json.keys())
|
|
35
|
+
for key in keys:
|
|
36
|
+
value = resp_json[key]
|
|
37
|
+
del resp_json[key]
|
|
38
|
+
resp_json[to_snake(key)] = value
|
|
39
|
+
return EndpointRunResponse(**resp_json)
|
|
40
|
+
except:
|
|
41
|
+
raise EndpointRunError(response)
|
|
42
|
+
|
lmnr/model.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
|
|
2
|
+
import requests
|
|
3
|
+
import pydantic
|
|
4
|
+
|
|
5
|
+
class ChatMessage(pydantic.BaseModel):
|
|
6
|
+
role: str
|
|
7
|
+
content: str
|
|
8
|
+
|
|
9
|
+
type NodeInput = str | list[ChatMessage]
|
|
10
|
+
|
|
11
|
+
class EndpointRunRequest(pydantic.BaseModel):
|
|
12
|
+
inputs: dict[str, NodeInput]
|
|
13
|
+
endpoint: str
|
|
14
|
+
env: dict[str, str] = pydantic.Field(default_factory=dict)
|
|
15
|
+
metadata: dict[str, str] = pydantic.Field(default_factory=dict)
|
|
16
|
+
|
|
17
|
+
class EndpointRunResponse(pydantic.BaseModel):
|
|
18
|
+
outputs: dict[str, dict[str, NodeInput]]
|
|
19
|
+
run_id: str
|
|
20
|
+
|
|
21
|
+
class EndpointRunError(Exception):
|
|
22
|
+
error_code: str
|
|
23
|
+
error_message: str
|
|
24
|
+
|
|
25
|
+
def __init__(self, response: requests.Response):
|
|
26
|
+
try:
|
|
27
|
+
resp_json = response.json()
|
|
28
|
+
self.error_code = resp_json['error_code']
|
|
29
|
+
self.error_message = resp_json['error_message']
|
|
30
|
+
super().__init__(self.error_message)
|
|
31
|
+
except:
|
|
32
|
+
super().__init__(response.text)
|
|
33
|
+
|
|
34
|
+
def __str__(self) -> str:
|
|
35
|
+
try:
|
|
36
|
+
return str({'error_code': self.error_code, 'error_message': self.error_message})
|
|
37
|
+
except:
|
|
38
|
+
return super().__str__()
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2024 LMNR AI, Inc.
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: lmnr
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python SDK for Laminar AI
|
|
5
|
+
Author: lmnr.ai
|
|
6
|
+
Requires-Python: >=3.9,<4.0
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Requires-Dist: pydantic (>=2.7.4,<3.0.0)
|
|
13
|
+
Requires-Dist: requests (>=2.32.3,<3.0.0)
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
|
|
16
|
+
# Python SDK for Laminar AI
|
|
17
|
+
|
|
18
|
+
Example use:
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
from lmnr import Laminar
|
|
22
|
+
|
|
23
|
+
l = Laminar('<YOUR_PROJECT_API_KEY>')
|
|
24
|
+
result = l.run(
|
|
25
|
+
endpoint = 'my_endpoint_name',
|
|
26
|
+
inputs = {'input_node_name': 'some_value'},
|
|
27
|
+
env = {'OPENAI_API_KEY': 'sk-some-key'},
|
|
28
|
+
metadata = {'session_id': 'your_custom_session_id'}
|
|
29
|
+
)
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Resulting in:
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
>>> result
|
|
36
|
+
EndpointRunResponse(outputs={'output': {'value': [ChatMessage(role='user', content='hello')]}}, run_id='53b012d5-5759-48a6-a9c5-0011610e3669')
|
|
37
|
+
```
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
lmnr/__init__.py,sha256=tRL8mi54bdyEloW-Z8gSUcAtZfHDr93KtJ2qRhaV3jY,29
|
|
2
|
+
lmnr/endpoint.py,sha256=sxzOArgQjeSIkQBVyD_GeG6xcDDEu5aoSCqkORGk6Fk,1556
|
|
3
|
+
lmnr/model.py,sha256=63bPw2tuIIvR-PYKE_ibu26ekvHUUlowBi82efCu1Qg,1087
|
|
4
|
+
lmnr-0.1.0.dist-info/LICENSE,sha256=NIpts0Z2q1CItuBiZjY9t9g0fpXUGbkH4jFmsViVcqY,1061
|
|
5
|
+
lmnr-0.1.0.dist-info/METADATA,sha256=rl-u-qUeFd5gmD6tY6lshkgGgohF5B0cuwx8-tT5_PA,1009
|
|
6
|
+
lmnr-0.1.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
7
|
+
lmnr-0.1.0.dist-info/RECORD,,
|