fxn 0.0.35__tar.gz → 0.0.36__tar.gz
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.
- {fxn-0.0.35 → fxn-0.0.36}/PKG-INFO +26 -28
- {fxn-0.0.35 → fxn-0.0.36}/README.md +23 -23
- fxn-0.0.36/fxn/c/__init__.py +16 -0
- fxn-0.0.36/fxn/c/configuration.py +60 -0
- fxn-0.0.36/fxn/c/dtype.py +26 -0
- fxn-0.0.36/fxn/c/fxnc.py +28 -0
- fxn-0.0.36/fxn/c/map.py +34 -0
- fxn-0.0.36/fxn/c/prediction.py +37 -0
- fxn-0.0.36/fxn/c/predictor.py +31 -0
- fxn-0.0.36/fxn/c/status.py +12 -0
- fxn-0.0.36/fxn/c/stream.py +22 -0
- fxn-0.0.36/fxn/c/value.py +50 -0
- fxn-0.0.36/fxn/c/version.py +13 -0
- {fxn-0.0.35 → fxn-0.0.36}/fxn/cli/__init__.py +8 -8
- {fxn-0.0.35 → fxn-0.0.36}/fxn/cli/auth.py +1 -1
- {fxn-0.0.35 → fxn-0.0.36}/fxn/cli/predict.py +3 -4
- {fxn-0.0.35 → fxn-0.0.36}/fxn/cli/predictors.py +1 -40
- {fxn-0.0.35 → fxn-0.0.36}/fxn/function.py +10 -11
- fxn-0.0.36/fxn/lib/macos/arm64/Function.dylib +0 -0
- fxn-0.0.36/fxn/lib/macos/x86_64/Function.dylib +0 -0
- fxn-0.0.36/fxn/lib/windows/arm64/Function.dll +0 -0
- fxn-0.0.36/fxn/lib/windows/x86_64/Function.dll +0 -0
- {fxn-0.0.35 → fxn-0.0.36}/fxn/services/environment.py +1 -1
- fxn-0.0.36/fxn/services/prediction.py +456 -0
- {fxn-0.0.35 → fxn-0.0.36}/fxn/services/predictor.py +3 -70
- {fxn-0.0.35 → fxn-0.0.36}/fxn/services/storage.py +3 -4
- {fxn-0.0.35 → fxn-0.0.36}/fxn/services/user.py +1 -1
- {fxn-0.0.35 → fxn-0.0.36}/fxn/types/__init__.py +2 -3
- {fxn-0.0.35 → fxn-0.0.36}/fxn/types/prediction.py +0 -4
- {fxn-0.0.35 → fxn-0.0.36}/fxn/types/predictor.py +15 -22
- {fxn-0.0.35 → fxn-0.0.36}/fxn/version.py +1 -1
- {fxn-0.0.35 → fxn-0.0.36}/fxn.egg-info/PKG-INFO +26 -28
- {fxn-0.0.35 → fxn-0.0.36}/fxn.egg-info/SOURCES.txt +20 -13
- {fxn-0.0.35 → fxn-0.0.36}/fxn.egg-info/requires.txt +0 -2
- {fxn-0.0.35 → fxn-0.0.36}/pyproject.toml +3 -7
- fxn-0.0.35/fxn/libs/linux/__init__.py +0 -4
- fxn-0.0.35/fxn/libs/macos/Function.dylib +0 -0
- fxn-0.0.35/fxn/libs/macos/__init__.py +0 -4
- fxn-0.0.35/fxn/libs/windows/Function.dll +0 -0
- fxn-0.0.35/fxn/libs/windows/__init__.py +0 -4
- fxn-0.0.35/fxn/services/prediction/__init__.py +0 -6
- fxn-0.0.35/fxn/services/prediction/fxnc.py +0 -312
- fxn-0.0.35/fxn/services/prediction/service.py +0 -512
- fxn-0.0.35/fxn/types/value.py +0 -22
- {fxn-0.0.35 → fxn-0.0.36}/LICENSE +0 -0
- {fxn-0.0.35 → fxn-0.0.36}/fxn/__init__.py +0 -0
- {fxn-0.0.35/fxn/graph → fxn-0.0.36/fxn/api}/__init__.py +0 -0
- {fxn-0.0.35/fxn/graph → fxn-0.0.36/fxn/api}/client.py +0 -0
- {fxn-0.0.35 → fxn-0.0.36}/fxn/cli/env.py +0 -0
- {fxn-0.0.35 → fxn-0.0.36}/fxn/cli/misc.py +0 -0
- {fxn-0.0.35/fxn/libs → fxn-0.0.36/fxn/lib}/__init__.py +0 -0
- {fxn-0.0.35 → fxn-0.0.36}/fxn/magic.py +0 -0
- {fxn-0.0.35 → fxn-0.0.36}/fxn/services/__init__.py +0 -0
- {fxn-0.0.35 → fxn-0.0.36}/fxn/types/dtype.py +0 -0
- {fxn-0.0.35 → fxn-0.0.36}/fxn/types/environment.py +0 -0
- {fxn-0.0.35 → fxn-0.0.36}/fxn/types/profile.py +0 -0
- {fxn-0.0.35 → fxn-0.0.36}/fxn/types/storage.py +0 -0
- {fxn-0.0.35 → fxn-0.0.36}/fxn/types/tag.py +0 -0
- {fxn-0.0.35 → fxn-0.0.36}/fxn/types/user.py +0 -0
- {fxn-0.0.35 → fxn-0.0.36}/fxn.egg-info/dependency_links.txt +0 -0
- {fxn-0.0.35 → fxn-0.0.36}/fxn.egg-info/entry_points.txt +0 -0
- {fxn-0.0.35 → fxn-0.0.36}/fxn.egg-info/top_level.txt +0 -0
- {fxn-0.0.35 → fxn-0.0.36}/setup.cfg +0 -0
@@ -1,7 +1,7 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: fxn
|
3
|
-
Version: 0.0.
|
4
|
-
Summary: Run
|
3
|
+
Version: 0.0.36
|
4
|
+
Summary: Run prediction functions locally in Python. Register at https://fxn.ai.
|
5
5
|
Author-email: "NatML Inc." <hi@fxn.ai>
|
6
6
|
License: Apache License
|
7
7
|
Version 2.0, January 2004
|
@@ -213,11 +213,9 @@ Classifier: License :: OSI Approved :: Apache Software License
|
|
213
213
|
Classifier: Operating System :: OS Independent
|
214
214
|
Classifier: Topic :: Scientific/Engineering :: Image Recognition
|
215
215
|
Classifier: Topic :: Software Development :: Libraries
|
216
|
-
Requires-Python: >=3.
|
216
|
+
Requires-Python: >=3.10
|
217
217
|
Description-Content-Type: text/markdown
|
218
218
|
License-File: LICENSE
|
219
|
-
Requires-Dist: aiohttp
|
220
|
-
Requires-Dist: magika
|
221
219
|
Requires-Dist: numpy
|
222
220
|
Requires-Dist: pillow
|
223
221
|
Requires-Dist: pydantic>=2.0
|
@@ -231,52 +229,52 @@ Requires-Dist: typer
|
|
231
229
|
|
232
230
|
[](https://fxn.ai/community)
|
233
231
|
|
234
|
-
Run
|
232
|
+
Run prediction functions (a.k.a "predictors") locally in your Python apps, with full GPU acceleration and zero dependencies. In a few steps:
|
235
233
|
|
236
234
|
## Installing Function
|
237
235
|
Function is distributed on PyPi. This distribution contains both the Python client and the command line interface (CLI). To install, open a terminal and run the following command:
|
238
236
|
```sh
|
239
|
-
|
237
|
+
# Install Function
|
238
|
+
$ pip install --upgrade fxn
|
240
239
|
```
|
241
240
|
|
242
241
|
> [!NOTE]
|
243
242
|
> Function requires Python 3.9+
|
244
243
|
|
245
|
-
##
|
246
|
-
|
244
|
+
## Retrieving your Access Key
|
245
|
+
Head over to [fxn.ai](https://fxn.ai) to create an account by logging in. Once you do, generate an access key:
|
246
|
+
|
247
|
+

|
247
248
|
|
248
|
-
|
249
|
-
Run the following Python script:
|
249
|
+
## Making a Prediction
|
250
|
+
Let's run the [`@fxn/greeting`](https://fxn.ai/@fxn/greeting) predictor which accepts a `name` and returns a congenial greeting. Run the following Python script:
|
250
251
|
```py
|
251
252
|
from fxn import Function
|
252
253
|
|
253
254
|
# Create the Function client
|
254
|
-
fxn = Function()
|
255
|
+
fxn = Function(access_key="<Function access key>")
|
255
256
|
# Create a prediction
|
256
257
|
prediction = fxn.predictions.create(
|
257
|
-
tag="@
|
258
|
-
inputs={
|
259
|
-
"prompt": "An astronaut riding a horse on Mars"
|
260
|
-
}
|
258
|
+
tag="@fxn/greeting",
|
259
|
+
inputs={ "name": "Peter" }
|
261
260
|
)
|
262
|
-
#
|
263
|
-
|
264
|
-
image.show()
|
261
|
+
# Print the returned greeting
|
262
|
+
print(prediction.results[0])
|
265
263
|
```
|
266
264
|
|
267
|
-
|
265
|
+
> [!TIP]
|
266
|
+
> Explore public predictors [on Function](https://fxn.ai/explore) or [create your own](https://fxn.ai/waitlist).
|
267
|
+
r
|
268
|
+
## Using the Function CLI
|
268
269
|
Open up a terminal and run the following command:
|
269
270
|
|
270
271
|
```sh
|
271
|
-
|
272
|
-
|
272
|
+
# Login to Function
|
273
|
+
fxn auth login <ACCESS KEY>
|
273
274
|
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
## Creating a Predictor
|
279
|
-
At some point, you might want to create your own predictor. With Function, you don't have to deal with GitHub repos, Dockerfiles, or weird YAMLs. All you need is a Jupyter Notebook with a `predict` function. See our [samples project](https://github.com/fxnai/samples) for more.
|
275
|
+
# Make a prediction using the Function CLI
|
276
|
+
fxn predict @fxn/greeting --name Peter
|
277
|
+
```
|
280
278
|
|
281
279
|
___
|
282
280
|
|
@@ -4,52 +4,52 @@
|
|
4
4
|
|
5
5
|
[](https://fxn.ai/community)
|
6
6
|
|
7
|
-
Run
|
7
|
+
Run prediction functions (a.k.a "predictors") locally in your Python apps, with full GPU acceleration and zero dependencies. In a few steps:
|
8
8
|
|
9
9
|
## Installing Function
|
10
10
|
Function is distributed on PyPi. This distribution contains both the Python client and the command line interface (CLI). To install, open a terminal and run the following command:
|
11
11
|
```sh
|
12
|
-
|
12
|
+
# Install Function
|
13
|
+
$ pip install --upgrade fxn
|
13
14
|
```
|
14
15
|
|
15
16
|
> [!NOTE]
|
16
17
|
> Function requires Python 3.9+
|
17
18
|
|
18
|
-
##
|
19
|
-
|
19
|
+
## Retrieving your Access Key
|
20
|
+
Head over to [fxn.ai](https://fxn.ai) to create an account by logging in. Once you do, generate an access key:
|
21
|
+
|
22
|
+

|
20
23
|
|
21
|
-
|
22
|
-
Run the following Python script:
|
24
|
+
## Making a Prediction
|
25
|
+
Let's run the [`@fxn/greeting`](https://fxn.ai/@fxn/greeting) predictor which accepts a `name` and returns a congenial greeting. Run the following Python script:
|
23
26
|
```py
|
24
27
|
from fxn import Function
|
25
28
|
|
26
29
|
# Create the Function client
|
27
|
-
fxn = Function()
|
30
|
+
fxn = Function(access_key="<Function access key>")
|
28
31
|
# Create a prediction
|
29
32
|
prediction = fxn.predictions.create(
|
30
|
-
tag="@
|
31
|
-
inputs={
|
32
|
-
"prompt": "An astronaut riding a horse on Mars"
|
33
|
-
}
|
33
|
+
tag="@fxn/greeting",
|
34
|
+
inputs={ "name": "Peter" }
|
34
35
|
)
|
35
|
-
#
|
36
|
-
|
37
|
-
image.show()
|
36
|
+
# Print the returned greeting
|
37
|
+
print(prediction.results[0])
|
38
38
|
```
|
39
39
|
|
40
|
-
|
40
|
+
> [!TIP]
|
41
|
+
> Explore public predictors [on Function](https://fxn.ai/explore) or [create your own](https://fxn.ai/waitlist).
|
42
|
+
r
|
43
|
+
## Using the Function CLI
|
41
44
|
Open up a terminal and run the following command:
|
42
45
|
|
43
46
|
```sh
|
44
|
-
|
45
|
-
|
47
|
+
# Login to Function
|
48
|
+
fxn auth login <ACCESS KEY>
|
46
49
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
## Creating a Predictor
|
52
|
-
At some point, you might want to create your own predictor. With Function, you don't have to deal with GitHub repos, Dockerfiles, or weird YAMLs. All you need is a Jupyter Notebook with a `predict` function. See our [samples project](https://github.com/fxnai/samples) for more.
|
50
|
+
# Make a prediction using the Function CLI
|
51
|
+
fxn predict @fxn/greeting --name Peter
|
52
|
+
```
|
53
53
|
|
54
54
|
___
|
55
55
|
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#
|
2
|
+
# Function
|
3
|
+
# Copyright © 2024 NatML Inc. All Rights Reserved.
|
4
|
+
#
|
5
|
+
|
6
|
+
# https://github.com/fxnai/fxnc
|
7
|
+
|
8
|
+
from .status import FXNStatus
|
9
|
+
from .value import FXNDtype, FXNValueRef, FXNValueFlags
|
10
|
+
from .map import FXNValueMapRef
|
11
|
+
from .configuration import FXNConfigurationRef, FXNAcceleration
|
12
|
+
from .prediction import FXNPredictionRef
|
13
|
+
from .stream import FXNPredictionStreamRef
|
14
|
+
from .predictor import FXNPredictorRef
|
15
|
+
|
16
|
+
from .fxnc import load_fxnc
|
@@ -0,0 +1,60 @@
|
|
1
|
+
#
|
2
|
+
# Function
|
3
|
+
# Copyright © 2024 NatML Inc. All Rights Reserved.
|
4
|
+
#
|
5
|
+
|
6
|
+
from ctypes import c_char_p, c_int, c_int32, c_void_p, CDLL, POINTER, Structure
|
7
|
+
from .status import FXNStatus
|
8
|
+
|
9
|
+
class FXNAcceleration(c_int):
|
10
|
+
FXN_ACCELERATION_DEFAULT = 0
|
11
|
+
FXN_ACCELERATION_CPU = 1 << 0
|
12
|
+
FXN_ACCELERATION_GPU = 1 << 1
|
13
|
+
FXN_ACCELERATION_NPU = 1 << 2
|
14
|
+
|
15
|
+
class FXNConfiguration(Structure): pass
|
16
|
+
|
17
|
+
FXNConfigurationRef = POINTER(FXNConfiguration)
|
18
|
+
|
19
|
+
def _register_fxn_configuration (fxnc: CDLL) -> CDLL:
|
20
|
+
# FXNConfigurationGetUniqueID
|
21
|
+
fxnc.FXNConfigurationGetUniqueID.argtypes = [c_char_p, c_int32]
|
22
|
+
fxnc.FXNConfigurationGetUniqueID.restype = FXNStatus
|
23
|
+
# FXNConfigurationGetClientID
|
24
|
+
fxnc.FXNConfigurationGetClientID.argtypes = [c_char_p, c_int32]
|
25
|
+
fxnc.FXNConfigurationGetClientID.restype = FXNStatus
|
26
|
+
# FXNConfigurationCreate
|
27
|
+
fxnc.FXNConfigurationCreate.argtypes = [POINTER(FXNConfigurationRef)]
|
28
|
+
fxnc.FXNConfigurationCreate.restype = FXNStatus
|
29
|
+
# FXNConfigurationRelease
|
30
|
+
fxnc.FXNConfigurationRelease.argtypes = [FXNConfigurationRef]
|
31
|
+
fxnc.FXNConfigurationRelease.restype = FXNStatus
|
32
|
+
# FXNConfigurationGetTag
|
33
|
+
fxnc.FXNConfigurationGetTag.argtypes = [FXNConfigurationRef, c_char_p, c_int32]
|
34
|
+
fxnc.FXNConfigurationRelease.restype = FXNStatus
|
35
|
+
# FXNConfigurationSetTag
|
36
|
+
fxnc.FXNConfigurationSetTag.argtypes = [FXNConfigurationRef, c_char_p]
|
37
|
+
fxnc.FXNConfigurationSetTag.restype = FXNStatus
|
38
|
+
# FXNConfigurationGetToken
|
39
|
+
fxnc.FXNConfigurationGetToken.argtypes = [FXNConfigurationRef, c_char_p, c_int32]
|
40
|
+
fxnc.FXNConfigurationGetToken.restype = FXNStatus
|
41
|
+
# FXNConfigurationSetToken
|
42
|
+
fxnc.FXNConfigurationSetToken.argtypes = [FXNConfigurationRef, c_char_p]
|
43
|
+
fxnc.FXNConfigurationSetToken.restype = FXNStatus
|
44
|
+
# FXNConfigurationGetAcceleration
|
45
|
+
fxnc.FXNConfigurationGetAcceleration.argtypes = [FXNConfigurationRef, POINTER(FXNAcceleration)]
|
46
|
+
fxnc.FXNConfigurationGetAcceleration.restype = FXNStatus
|
47
|
+
# FXNConfigurationSetAcceleration
|
48
|
+
fxnc.FXNConfigurationSetAcceleration.argtypes = [FXNConfigurationRef, FXNAcceleration]
|
49
|
+
fxnc.FXNConfigurationSetAcceleration.restype = FXNStatus
|
50
|
+
# FXNConfigurationGetDevice
|
51
|
+
fxnc.FXNConfigurationGetDevice.argtypes = [FXNConfigurationRef, POINTER(c_void_p)]
|
52
|
+
fxnc.FXNConfigurationGetDevice.restype = FXNStatus
|
53
|
+
# FXNConfigurationSetDevice
|
54
|
+
fxnc.FXNConfigurationSetDevice.argtypes = [FXNConfigurationRef, c_void_p]
|
55
|
+
fxnc.FXNConfigurationSetDevice.restype = FXNStatus
|
56
|
+
# FXNConfigurationAddResource
|
57
|
+
fxnc.FXNConfigurationAddResource.argtypes = [FXNConfigurationRef, c_char_p, c_char_p]
|
58
|
+
fxnc.FXNConfigurationAddResource.restype = FXNStatus
|
59
|
+
# Return
|
60
|
+
return fxnc
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#
|
2
|
+
# Function
|
3
|
+
# Copyright © 2024 NatML Inc. All Rights Reserved.
|
4
|
+
#
|
5
|
+
|
6
|
+
from ctypes import c_int
|
7
|
+
|
8
|
+
class FXNDtype(c_int):
|
9
|
+
NULL = 0
|
10
|
+
FLOAT16 = 1
|
11
|
+
FLOAT32 = 2
|
12
|
+
FLOAT64 = 3
|
13
|
+
INT8 = 4
|
14
|
+
INT16 = 5
|
15
|
+
INT32 = 6
|
16
|
+
INT64 = 7
|
17
|
+
UINT8 = 8
|
18
|
+
UINT16 = 9
|
19
|
+
UINT32 = 10
|
20
|
+
UINT64 = 11
|
21
|
+
BOOL = 12
|
22
|
+
STRING = 13
|
23
|
+
LIST = 14
|
24
|
+
DICT = 15
|
25
|
+
IMAGE = 16
|
26
|
+
BINARY = 17
|
fxn-0.0.36/fxn/c/fxnc.py
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#
|
2
|
+
# Function
|
3
|
+
# Copyright © 2024 NatML Inc. All Rights Reserved.
|
4
|
+
#
|
5
|
+
|
6
|
+
from ctypes import CDLL
|
7
|
+
from pathlib import Path
|
8
|
+
from .configuration import _register_fxn_configuration
|
9
|
+
from .prediction import _register_fxn_prediction
|
10
|
+
from .stream import _register_fxn_prediction_stream
|
11
|
+
from .predictor import _register_fxn_predictor
|
12
|
+
from .value import _register_fxn_value
|
13
|
+
from .map import _register_fxn_value_map
|
14
|
+
from .version import _register_fxn_version
|
15
|
+
|
16
|
+
def load_fxnc (path: Path) -> CDLL:
|
17
|
+
# Open
|
18
|
+
fxnc = CDLL(str(path))
|
19
|
+
# Register
|
20
|
+
fxnc = _register_fxn_value(fxnc)
|
21
|
+
fxnc = _register_fxn_value_map(fxnc)
|
22
|
+
fxnc = _register_fxn_configuration(fxnc)
|
23
|
+
fxnc = _register_fxn_prediction(fxnc)
|
24
|
+
fxnc = _register_fxn_prediction_stream(fxnc)
|
25
|
+
fxnc = _register_fxn_predictor(fxnc)
|
26
|
+
fxnc = _register_fxn_version(fxnc)
|
27
|
+
# Return
|
28
|
+
return fxnc
|
fxn-0.0.36/fxn/c/map.py
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
#
|
2
|
+
# Function
|
3
|
+
# Copyright © 2024 NatML Inc. All Rights Reserved.
|
4
|
+
#
|
5
|
+
|
6
|
+
from ctypes import c_char_p, c_int32, CDLL, POINTER, Structure
|
7
|
+
from .status import FXNStatus
|
8
|
+
from .value import FXNValueRef
|
9
|
+
|
10
|
+
class FXNValueMap(Structure): pass
|
11
|
+
|
12
|
+
FXNValueMapRef = POINTER(FXNValueMap)
|
13
|
+
|
14
|
+
def _register_fxn_value_map (fxnc: CDLL) -> CDLL:
|
15
|
+
# FXNValueMapCreate
|
16
|
+
fxnc.FXNValueMapCreate.argtypes = [POINTER(FXNValueMapRef)]
|
17
|
+
fxnc.FXNValueMapCreate.restype = FXNStatus
|
18
|
+
# FXNValueMapRelease
|
19
|
+
fxnc.FXNValueMapRelease.argtypes = [FXNValueMapRef]
|
20
|
+
fxnc.FXNValueMapRelease.restype = FXNStatus
|
21
|
+
# FXNValueMapGetSize
|
22
|
+
fxnc.FXNValueMapGetSize.argtypes = [FXNValueMapRef, POINTER(c_int32)]
|
23
|
+
fxnc.FXNValueMapGetSize.restype = FXNStatus
|
24
|
+
# FXNValueMapGetKey
|
25
|
+
fxnc.FXNValueMapGetKey.argtypes = [FXNValueMapRef, c_int32, c_char_p, c_int32]
|
26
|
+
fxnc.FXNValueMapGetKey.restype = FXNStatus
|
27
|
+
# FXNValueMapGetValue
|
28
|
+
fxnc.FXNValueMapGetValue.argtypes = [FXNValueMapRef, c_char_p, POINTER(FXNValueRef)]
|
29
|
+
fxnc.FXNValueMapGetValue.restype = FXNStatus
|
30
|
+
# FXNValueMapSetValue
|
31
|
+
fxnc.FXNValueMapSetValue.argtypes = [FXNValueMapRef, c_char_p, FXNValueRef]
|
32
|
+
fxnc.FXNValueMapSetValue.restype = FXNStatus
|
33
|
+
# Return
|
34
|
+
return fxnc
|
@@ -0,0 +1,37 @@
|
|
1
|
+
#
|
2
|
+
# Function
|
3
|
+
# Copyright © 2024 NatML Inc. All Rights Reserved.
|
4
|
+
#
|
5
|
+
|
6
|
+
from ctypes import c_char_p, c_double, c_int32, CDLL, POINTER, Structure
|
7
|
+
from .status import FXNStatus
|
8
|
+
from .map import FXNValueMapRef
|
9
|
+
|
10
|
+
class FXNPrediction(Structure): pass
|
11
|
+
|
12
|
+
FXNPredictionRef = POINTER(FXNPrediction)
|
13
|
+
|
14
|
+
def _register_fxn_prediction (fxnc: CDLL) -> CDLL:
|
15
|
+
# FXNPredictionRelease
|
16
|
+
fxnc.FXNPredictionRelease.argtypes = [FXNPredictionRef]
|
17
|
+
fxnc.FXNPredictionRelease.restype = FXNStatus
|
18
|
+
# FXNPredictionGetID
|
19
|
+
fxnc.FXNPredictionGetID.argtypes = [FXNPredictionRef, c_char_p, c_int32]
|
20
|
+
fxnc.FXNPredictionGetID.restype = FXNStatus
|
21
|
+
# FXNPredictionGetLatency
|
22
|
+
fxnc.FXNPredictionGetLatency.argtypes = [FXNPredictionRef, POINTER(c_double)]
|
23
|
+
fxnc.FXNPredictionGetLatency.restype = FXNStatus
|
24
|
+
# FXNPredictionGetResults
|
25
|
+
fxnc.FXNPredictionGetResults.argtypes = [FXNPredictionRef, POINTER(FXNValueMapRef)]
|
26
|
+
fxnc.FXNPredictionGetResults.restype = FXNStatus
|
27
|
+
# FXNPredictionGetError
|
28
|
+
fxnc.FXNPredictionGetError.argtypes = [FXNPredictionRef, c_char_p, c_int32]
|
29
|
+
fxnc.FXNPredictionGetError.restype = FXNStatus
|
30
|
+
# FXNPredictionGetLogs
|
31
|
+
fxnc.FXNPredictionGetLogs.argtypes = [FXNPredictionRef, c_char_p, c_int32]
|
32
|
+
fxnc.FXNPredictionGetLogs.restype = FXNStatus
|
33
|
+
# FXNPredictionGetLogLength
|
34
|
+
fxnc.FXNPredictionGetLogLength.argtypes = [FXNPredictionRef, POINTER(c_int32)]
|
35
|
+
fxnc.FXNPredictionGetLogLength.restype = FXNStatus
|
36
|
+
# Return
|
37
|
+
return fxnc
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#
|
2
|
+
# Function
|
3
|
+
# Copyright © 2024 NatML Inc. All Rights Reserved.
|
4
|
+
#
|
5
|
+
|
6
|
+
from ctypes import CDLL, POINTER, Structure
|
7
|
+
from .configuration import FXNConfigurationRef
|
8
|
+
from .prediction import FXNPredictionRef
|
9
|
+
from .stream import FXNPredictionStreamRef
|
10
|
+
from .status import FXNStatus
|
11
|
+
from .map import FXNValueMapRef
|
12
|
+
|
13
|
+
class FXNPredictor(Structure): pass
|
14
|
+
|
15
|
+
FXNPredictorRef = POINTER(FXNPredictor)
|
16
|
+
|
17
|
+
def _register_fxn_predictor (fxnc: CDLL) -> CDLL:
|
18
|
+
# FXNPredictorCreate
|
19
|
+
fxnc.FXNPredictorCreate.argtypes = [FXNConfigurationRef, POINTER(FXNPredictorRef)]
|
20
|
+
fxnc.FXNPredictorCreate.restype = FXNStatus
|
21
|
+
# FXNPredictorRelease
|
22
|
+
fxnc.FXNPredictorRelease.argtypes = [FXNPredictorRef]
|
23
|
+
fxnc.FXNPredictorRelease.restype = FXNStatus
|
24
|
+
# FXNPredictorCreatePrediction
|
25
|
+
fxnc.FXNPredictorCreatePrediction.argtypes = [FXNPredictorRef, FXNValueMapRef, POINTER(FXNPredictionRef)]
|
26
|
+
fxnc.FXNPredictorCreatePrediction.restype = FXNStatus
|
27
|
+
# FXNPredictorStreamPrediction
|
28
|
+
fxnc.FXNPredictorStreamPrediction.argtypes = [FXNPredictionRef, FXNValueMapRef, POINTER(FXNPredictionStreamRef)]
|
29
|
+
fxnc.FXNPredictorStreamPrediction.restype = FXNStatus
|
30
|
+
# Return
|
31
|
+
return fxnc
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#
|
2
|
+
# Function
|
3
|
+
# Copyright © 2024 NatML Inc. All Rights Reserved.
|
4
|
+
#
|
5
|
+
|
6
|
+
from ctypes import CDLL, POINTER, Structure
|
7
|
+
from .prediction import FXNPredictionRef
|
8
|
+
from .status import FXNStatus
|
9
|
+
|
10
|
+
class FXNPredictionStream(Structure): pass
|
11
|
+
|
12
|
+
FXNPredictionStreamRef = POINTER(FXNPredictionStream)
|
13
|
+
|
14
|
+
def _register_fxn_prediction_stream (fxnc: CDLL) -> CDLL:
|
15
|
+
# FXNPredictionStreamRelease
|
16
|
+
fxnc.FXNPredictionStreamRelease.argtypes = [FXNPredictionStreamRef]
|
17
|
+
fxnc.FXNPredictionStreamRelease.restype = FXNStatus
|
18
|
+
# FXNPredictionStreamReadNext
|
19
|
+
fxnc.FXNPredictionStreamReadNext.argtypes = [FXNPredictionStreamRef, POINTER(FXNPredictionRef)]
|
20
|
+
fxnc.FXNPredictionStreamReadNext.restype = FXNStatus
|
21
|
+
# Return
|
22
|
+
return fxnc
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#
|
2
|
+
# Function
|
3
|
+
# Copyright © 2024 NatML Inc. All Rights Reserved.
|
4
|
+
#
|
5
|
+
|
6
|
+
from ctypes import c_char_p, c_int, c_int32, c_void_p, CDLL, POINTER, Structure
|
7
|
+
from .dtype import FXNDtype
|
8
|
+
from .status import FXNStatus
|
9
|
+
|
10
|
+
class FXNValueFlags(c_int):
|
11
|
+
NONE = 0
|
12
|
+
COPY_DATA = 1
|
13
|
+
|
14
|
+
class FXNValue(Structure): pass
|
15
|
+
|
16
|
+
FXNValueRef = POINTER(FXNValue)
|
17
|
+
|
18
|
+
def _register_fxn_value (fxnc: CDLL) -> CDLL:
|
19
|
+
# FXNValueRelease
|
20
|
+
fxnc.FXNValueRelease.argtypes = [FXNValueRef]
|
21
|
+
fxnc.FXNValueRelease.restype = FXNStatus
|
22
|
+
# FXNValueGetData
|
23
|
+
fxnc.FXNValueGetData.argtypes = [FXNValueRef, POINTER(c_void_p)]
|
24
|
+
fxnc.FXNValueGetData.restype = FXNStatus
|
25
|
+
# FXNValueGetType
|
26
|
+
fxnc.FXNValueGetType.argtypes = [FXNValueRef, POINTER(FXNDtype)]
|
27
|
+
fxnc.FXNValueGetType.restype = FXNStatus
|
28
|
+
# FXNValueGetDimensions
|
29
|
+
fxnc.FXNValueGetDimensions.argtypes = [FXNValueRef, POINTER(c_int32)]
|
30
|
+
fxnc.FXNValueGetDimensions.restype = FXNStatus
|
31
|
+
# FXNValueGetShape
|
32
|
+
fxnc.FXNValueGetShape.argtypes = [FXNValueRef, POINTER(c_int32), c_int32]
|
33
|
+
fxnc.FXNValueGetShape.restype = FXNStatus
|
34
|
+
# FXNValueCreateArray
|
35
|
+
fxnc.FXNValueCreateArray.argtypes = [c_void_p, POINTER(c_int32), c_int32, FXNDtype, FXNValueFlags, POINTER(FXNValueRef)]
|
36
|
+
fxnc.FXNValueCreateArray.restype = FXNStatus
|
37
|
+
# FXNValueCreateString
|
38
|
+
fxnc.FXNValueCreateString.argtypes = [c_char_p, POINTER(FXNValueRef)]
|
39
|
+
fxnc.FXNValueCreateString.restype = FXNStatus
|
40
|
+
# FXNValueCreateList
|
41
|
+
fxnc.FXNValueCreateList.argtypes = [c_char_p, POINTER(FXNValueRef)]
|
42
|
+
fxnc.FXNValueCreateList.restype = FXNStatus
|
43
|
+
# FXNValueCreateDict
|
44
|
+
fxnc.FXNValueCreateDict.argtypes = [c_char_p, POINTER(FXNValueRef)]
|
45
|
+
fxnc.FXNValueCreateDict.restype = FXNStatus
|
46
|
+
# FXNValueCreateImage
|
47
|
+
fxnc.FXNValueCreateImage.argtypes = [c_void_p, c_int32, c_int32, c_int32, FXNValueFlags, POINTER(FXNValueRef)]
|
48
|
+
fxnc.FXNValueCreateImage.restype = FXNStatus
|
49
|
+
# Return
|
50
|
+
return fxnc
|
@@ -0,0 +1,13 @@
|
|
1
|
+
#
|
2
|
+
# Function
|
3
|
+
# Copyright © 2024 NatML Inc. All Rights Reserved.
|
4
|
+
#
|
5
|
+
|
6
|
+
from ctypes import c_char_p, CDLL
|
7
|
+
|
8
|
+
def _register_fxn_version (fxnc: CDLL) -> CDLL:
|
9
|
+
# FXNGetVersion
|
10
|
+
fxnc.FXNGetVersion.argtypes = []
|
11
|
+
fxnc.FXNGetVersion.restype = c_char_p
|
12
|
+
# Return
|
13
|
+
return fxnc
|
@@ -9,7 +9,7 @@ from .auth import app as auth_app
|
|
9
9
|
from .env import app as env_app
|
10
10
|
from .misc import cli_options
|
11
11
|
from .predict import predict
|
12
|
-
from .predictors import archive_predictor,
|
12
|
+
from .predictors import archive_predictor, delete_predictor, list_predictors, retrieve_predictor, search_predictors
|
13
13
|
from ..version import __version__
|
14
14
|
|
15
15
|
# Define CLI
|
@@ -26,16 +26,16 @@ app.callback()(cli_options)
|
|
26
26
|
|
27
27
|
# Add subcommands
|
28
28
|
app.add_typer(auth_app, name="auth", help="Login, logout, and check your authentication status.")
|
29
|
-
app.add_typer(env_app, name="env", help="Manage predictor environment variables.")
|
29
|
+
#app.add_typer(env_app, name="env", help="Manage predictor environment variables.")
|
30
30
|
|
31
31
|
# Add top-level commands
|
32
|
-
app.command(name="create", help="Create a predictor.")(create_predictor)
|
33
|
-
app.command(name="delete", help="Delete a predictor.")(delete_predictor)
|
32
|
+
#app.command(name="create", help="Create a predictor.")(create_predictor)
|
33
|
+
#app.command(name="delete", help="Delete a predictor.")(delete_predictor)
|
34
34
|
app.command(name="predict", help="Make a prediction.", context_settings={ "allow_extra_args": True, "ignore_unknown_options": True })(predict)
|
35
|
-
app.command(name="list", help="List predictors.")(list_predictors)
|
36
|
-
app.command(name="search", help="Search predictors.")(search_predictors)
|
37
|
-
app.command(name="retrieve", help="Retrieve a predictor.")(retrieve_predictor)
|
38
|
-
app.command(name="archive", help="Archive a predictor.")(archive_predictor)
|
35
|
+
#app.command(name="list", help="List predictors.")(list_predictors)
|
36
|
+
#app.command(name="search", help="Search predictors.")(search_predictors)
|
37
|
+
#app.command(name="retrieve", help="Retrieve a predictor.")(retrieve_predictor)
|
38
|
+
#app.command(name="archive", help="Archive a predictor.")(archive_predictor)
|
39
39
|
|
40
40
|
# Run
|
41
41
|
if __name__ == "__main__":
|
@@ -15,7 +15,7 @@ app = Typer(no_args_is_help=True)
|
|
15
15
|
def login (
|
16
16
|
access_key: str=Argument(..., help="Function access key.", envvar="FXN_ACCESS_KEY")
|
17
17
|
):
|
18
|
-
fxn = Function(access_key)
|
18
|
+
fxn = Function(access_key=access_key)
|
19
19
|
user = fxn.users.retrieve()
|
20
20
|
user = user.model_dump() if user else None
|
21
21
|
_set_access_key(access_key if user is not None else None)
|
@@ -18,12 +18,11 @@ from .auth import get_access_key
|
|
18
18
|
|
19
19
|
def predict (
|
20
20
|
tag: str = Argument(..., help="Predictor tag."),
|
21
|
-
raw_outputs: bool = Option(False, "--raw-outputs", help="Output raw Function values instead of converting into plain Python values."),
|
22
21
|
context: Context = 0
|
23
22
|
):
|
24
|
-
run_async(_predict_async(tag, context=context
|
23
|
+
run_async(_predict_async(tag, context=context))
|
25
24
|
|
26
|
-
async def _predict_async (tag: str, context: Context
|
25
|
+
async def _predict_async (tag: str, context: Context):
|
27
26
|
with Progress(
|
28
27
|
SpinnerColumn(spinner_name="dots"),
|
29
28
|
TextColumn("[progress.description]{task.description}"),
|
@@ -34,7 +33,7 @@ async def _predict_async (tag: str, context: Context, raw_outputs: bool):
|
|
34
33
|
inputs = { context.args[i].replace("-", ""): _parse_value(context.args[i+1]) for i in range(0, len(context.args), 2) }
|
35
34
|
# Stream
|
36
35
|
fxn = Function(get_access_key())
|
37
|
-
async for prediction in fxn.predictions.stream(tag, inputs=inputs
|
36
|
+
async for prediction in fxn.predictions.stream(tag, inputs=inputs):
|
38
37
|
# Parse results
|
39
38
|
images = [value for value in prediction.results or [] if isinstance(value, Image.Image)]
|
40
39
|
prediction.results = [_serialize_value(value) for value in prediction.results] if prediction.results is not None else None
|
@@ -5,12 +5,10 @@
|
|
5
5
|
|
6
6
|
from rich import print_json
|
7
7
|
from rich.progress import Progress, SpinnerColumn, TextColumn
|
8
|
-
from pathlib import Path
|
9
8
|
from typer import Argument, Option
|
10
|
-
from typing import List
|
11
9
|
|
12
10
|
from ..function import Function
|
13
|
-
from ..types import
|
11
|
+
from ..types import PredictorStatus
|
14
12
|
from .auth import get_access_key
|
15
13
|
|
16
14
|
def retrieve_predictor (
|
@@ -47,43 +45,6 @@ def search_predictors (
|
|
47
45
|
predictors = [predictor.model_dump() for predictor in predictors]
|
48
46
|
print_json(data=predictors)
|
49
47
|
|
50
|
-
def create_predictor (
|
51
|
-
tag: str=Argument(..., help="Predictor tag."),
|
52
|
-
notebook: Path=Argument(..., help="Path to predictor notebook."),
|
53
|
-
type: PredictorType=Option(None, case_sensitive=False, help="Predictor type. This defaults to `cloud`."),
|
54
|
-
edge: bool=Option(False, "--edge", is_flag=True, help="Shorthand for `--type edge`."),
|
55
|
-
cloud: bool=Option(False, "--cloud", is_flag=True, help="Shorthand for `--type cloud`."),
|
56
|
-
access: AccessMode=Option(None, case_sensitive=False, help="Predictor access mode. This defaults to `private`."),
|
57
|
-
description: str=Option(None, help="Predictor description. This must be less than 200 characters long."),
|
58
|
-
media: Path=Option(None, help="Predictor image path."),
|
59
|
-
acceleration: Acceleration=Option(None, case_sensitive=False, help="Cloud predictor acceleration. This defaults to `cpu`."),
|
60
|
-
license: str=Option(None, help="Predictor license URL."),
|
61
|
-
env: List[str]=Option([], help="Specify a predictor environment variable."),
|
62
|
-
overwrite: bool=Option(None, "--overwrite", help="Overwrite any existing predictor with the same tag.")
|
63
|
-
):
|
64
|
-
with Progress(
|
65
|
-
SpinnerColumn(spinner_name="dots"),
|
66
|
-
TextColumn("[progress.description]{task.description}"),
|
67
|
-
transient=True
|
68
|
-
) as progress:
|
69
|
-
progress.add_task(description="Analyzing Function...", total=None)
|
70
|
-
fxn = Function(get_access_key())
|
71
|
-
type = PredictorType.Cloud if cloud else PredictorType.Edge if edge else type
|
72
|
-
environment = { e.split("=")[0].strip(): e.split("=")[1].strip() for e in env }
|
73
|
-
predictor = fxn.predictors.create(
|
74
|
-
tag=tag,
|
75
|
-
notebook=notebook,
|
76
|
-
type=type,
|
77
|
-
access=access,
|
78
|
-
description=description,
|
79
|
-
media=media,
|
80
|
-
acceleration=acceleration,
|
81
|
-
environment=environment,
|
82
|
-
license=license,
|
83
|
-
overwrite=overwrite
|
84
|
-
)
|
85
|
-
print_json(data=predictor.model_dump())
|
86
|
-
|
87
48
|
def delete_predictor (
|
88
49
|
tag: str=Argument(..., help="Predictor tag.")
|
89
50
|
):
|