fxn 0.0.40__py3-none-any.whl → 0.0.42__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.
Files changed (54) hide show
  1. fxn/__init__.py +3 -1
  2. fxn/beta/__init__.py +6 -0
  3. fxn/beta/client.py +16 -0
  4. fxn/beta/prediction.py +16 -0
  5. fxn/beta/remote.py +207 -0
  6. fxn/c/__init__.py +7 -10
  7. fxn/c/configuration.py +114 -56
  8. fxn/c/fxnc.py +42 -22
  9. fxn/c/map.py +60 -30
  10. fxn/c/prediction.py +72 -33
  11. fxn/c/predictor.py +55 -27
  12. fxn/c/stream.py +33 -15
  13. fxn/c/value.py +215 -42
  14. fxn/cli/__init__.py +14 -12
  15. fxn/cli/auth.py +1 -1
  16. fxn/cli/misc.py +1 -1
  17. fxn/cli/{predict.py → predictions.py} +33 -36
  18. fxn/cli/predictors.py +3 -51
  19. fxn/client.py +58 -0
  20. fxn/compile/__init__.py +7 -0
  21. fxn/compile/compile.py +80 -0
  22. fxn/compile/sandbox.py +177 -0
  23. fxn/compile/signature.py +183 -0
  24. fxn/function.py +10 -6
  25. fxn/lib/__init__.py +1 -1
  26. fxn/lib/linux/arm64/libFunction.so +0 -0
  27. fxn/lib/linux/x86_64/libFunction.so +0 -0
  28. fxn/lib/macos/arm64/Function.dylib +0 -0
  29. fxn/lib/macos/x86_64/Function.dylib +0 -0
  30. fxn/lib/windows/arm64/Function.dll +0 -0
  31. fxn/lib/windows/x86_64/Function.dll +0 -0
  32. fxn/services/__init__.py +4 -4
  33. fxn/services/prediction.py +180 -351
  34. fxn/services/predictor.py +14 -187
  35. fxn/services/user.py +16 -42
  36. fxn/types/__init__.py +4 -4
  37. fxn/types/dtype.py +1 -1
  38. fxn/types/prediction.py +20 -10
  39. fxn/types/predictor.py +18 -32
  40. fxn/types/user.py +9 -15
  41. fxn/version.py +2 -2
  42. {fxn-0.0.40.dist-info → fxn-0.0.42.dist-info}/METADATA +5 -5
  43. fxn-0.0.42.dist-info/RECORD +47 -0
  44. {fxn-0.0.40.dist-info → fxn-0.0.42.dist-info}/WHEEL +1 -1
  45. fxn/api/__init__.py +0 -6
  46. fxn/api/client.py +0 -43
  47. fxn/c/dtype.py +0 -26
  48. fxn/c/status.py +0 -12
  49. fxn/c/version.py +0 -13
  50. fxn/cli/env.py +0 -40
  51. fxn-0.0.40.dist-info/RECORD +0 -44
  52. {fxn-0.0.40.dist-info → fxn-0.0.42.dist-info}/LICENSE +0 -0
  53. {fxn-0.0.40.dist-info → fxn-0.0.42.dist-info}/entry_points.txt +0 -0
  54. {fxn-0.0.40.dist-info → fxn-0.0.42.dist-info}/top_level.txt +0 -0
fxn/c/prediction.py CHANGED
@@ -1,37 +1,76 @@
1
1
  #
2
2
  # Function
3
- # Copyright © 2024 NatML Inc. All Rights Reserved.
3
+ # Copyright © 2025 NatML Inc. All Rights Reserved.
4
4
  #
5
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
6
+ from ctypes import byref, c_double, c_int32, c_void_p, create_string_buffer
7
+ from pathlib import Path
8
+ from typing import final
9
+
10
+ from .fxnc import get_fxnc, status_to_error, FXNStatus
11
+ from .map import ValueMap
12
+
13
+ @final
14
+ class Prediction:
15
+
16
+ def __init__ (self, prediction):
17
+ self.__prediction = prediction
18
+
19
+ @property
20
+ def id (self) -> str:
21
+ id = create_string_buffer(256)
22
+ status = get_fxnc().FXNPredictionGetID(self.__prediction, id, len(id))
23
+ if status == FXNStatus.OK:
24
+ return id.value.decode("utf-8")
25
+ else:
26
+ raise RuntimeError(f"Failed to get prediction id with error: {status_to_error(status)}")
27
+
28
+ @property
29
+ def latency (self) -> float:
30
+ latency = c_double()
31
+ status = get_fxnc().FXNPredictionGetLatency(self.__prediction, byref(latency))
32
+ if status == FXNStatus.OK:
33
+ return latency.value
34
+ else:
35
+ raise RuntimeError(f"Failed to get prediction latency with error: {status_to_error(status)}")
36
+
37
+ @property
38
+ def results (self) -> ValueMap | None:
39
+ map = c_void_p()
40
+ status = get_fxnc().FXNPredictionGetResults(self.__prediction, byref(map))
41
+ if status != FXNStatus.OK:
42
+ raise RuntimeError(f"Failed to get prediction results with error: {status_to_error(status)}")
43
+ map = ValueMap(map, owner=False)
44
+ return map if len(map) > 0 else None
45
+
46
+ @property
47
+ def error (self) -> str | None:
48
+ error = create_string_buffer(2048)
49
+ get_fxnc().FXNPredictionGetError(self.__prediction, error, len(error))
50
+ error = error.value.decode("utf-8")
51
+ return error if error else None
52
+
53
+ @property
54
+ def logs (self) -> str:
55
+ fxnc = get_fxnc()
56
+ log_length = c_int32()
57
+ status = fxnc.FXNPredictionGetLogLength(self.__prediction, byref(log_length))
58
+ if status != FXNStatus.OK:
59
+ raise RuntimeError(f"Failed to get prediction log length with error: {status_to_error(status)}")
60
+ logs = create_string_buffer(log_length.value + 1)
61
+ status = fxnc.FXNPredictionGetLogs(self.__prediction, logs, len(logs))
62
+ if status == FXNStatus.OK:
63
+ return logs.value.decode("utf-8")
64
+ else:
65
+ raise RuntimeError(f"Failed to get prediction logs with error: {status_to_error(status)}")
66
+
67
+ def __enter__ (self):
68
+ return self
69
+
70
+ def __exit__ (self, exc_type, exc_value, traceback):
71
+ self.__release()
72
+
73
+ def __release (self):
74
+ if self.__prediction:
75
+ get_fxnc().FXNPredictionRelease(self.__prediction)
76
+ self.__prediction = None
fxn/c/predictor.py CHANGED
@@ -1,31 +1,59 @@
1
1
  #
2
2
  # Function
3
- # Copyright © 2024 NatML Inc. All Rights Reserved.
3
+ # Copyright © 2025 NatML Inc. All Rights Reserved.
4
4
  #
5
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
6
+ from ctypes import byref, c_void_p
7
+ from typing import final
8
+
9
+ from .configuration import Configuration
10
+ from .fxnc import get_fxnc, status_to_error, FXNStatus
11
+ from .map import ValueMap
12
+ from .prediction import Prediction
13
+ from .stream import PredictionStream
14
+
15
+ @final
16
+ class Predictor:
17
+
18
+ def __init__ (self, configuration: Configuration):
19
+ predictor = c_void_p()
20
+ status = get_fxnc().FXNPredictorCreate(configuration._Configuration__configuration, byref(predictor))
21
+ if status == FXNStatus.OK:
22
+ self.__predictor = predictor
23
+ else:
24
+ raise RuntimeError(f"Failed to create predictor with error: {status_to_error(status)}")
25
+
26
+ def create_prediction (self, inputs: ValueMap) -> Prediction:
27
+ prediction = c_void_p()
28
+ status = get_fxnc().FXNPredictorCreatePrediction(
29
+ self.__predictor,
30
+ inputs._ValueMap__map,
31
+ byref(prediction)
32
+ )
33
+ if status == FXNStatus.OK:
34
+ return Prediction(prediction)
35
+ else:
36
+ raise RuntimeError(f"Failed to create prediction with error: {status_to_error(status)}")
37
+
38
+ def stream_prediction (self, inputs: ValueMap) -> PredictionStream:
39
+ stream = c_void_p()
40
+ status = get_fxnc().FXNPredictorStreamPrediction(
41
+ self.__predictor,
42
+ inputs._ValueMap__map,
43
+ byref(stream)
44
+ )
45
+ if status == FXNStatus.OK:
46
+ return PredictionStream(stream)
47
+ else:
48
+ raise RuntimeError(f"Failed to stream prediction with error: {status_to_error(status)}")
49
+
50
+ def __enter__ (self):
51
+ return self
52
+
53
+ def __exit__ (self, exc_type, exc_value, traceback):
54
+ self.__release()
55
+
56
+ def __release (self):
57
+ if self.__predictor:
58
+ get_fxnc().FXNPredictorRelease(self.__predictor)
59
+ self.__predictor = None
fxn/c/stream.py CHANGED
@@ -1,22 +1,40 @@
1
1
  #
2
2
  # Function
3
- # Copyright © 2024 NatML Inc. All Rights Reserved.
3
+ # Copyright © 2025 NatML Inc. All Rights Reserved.
4
4
  #
5
5
 
6
- from ctypes import CDLL, POINTER, Structure
7
- from .prediction import FXNPredictionRef
8
- from .status import FXNStatus
6
+ from ctypes import byref, c_void_p
7
+ from typing import final
9
8
 
10
- class FXNPredictionStream(Structure): pass
9
+ from .fxnc import get_fxnc, status_to_error, FXNStatus
10
+ from .prediction import Prediction
11
11
 
12
- FXNPredictionStreamRef = POINTER(FXNPredictionStream)
12
+ @final
13
+ class PredictionStream:
13
14
 
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
15
+ def __init__ (self, stream):
16
+ self.__stream = stream
17
+
18
+ def __iter__ (self):
19
+ return self
20
+
21
+ def __next__ (self) -> Prediction:
22
+ prediction = c_void_p()
23
+ status = get_fxnc().FXNPredictionStreamReadNext(self.__stream, byref(prediction))
24
+ if status == FXNStatus.ERROR_INVALID_OPERATION:
25
+ raise StopIteration()
26
+ elif status != FXNStatus.OK:
27
+ raise RuntimeError(f"Failed to read next prediction in stream with error: {status_to_error(status)}")
28
+ else:
29
+ return Prediction(prediction)
30
+
31
+ def __enter__ (self):
32
+ return self
33
+
34
+ def __exit__ (self, exc_type, exc_value, traceback):
35
+ self.__release()
36
+
37
+ def __release (self):
38
+ if self.__stream:
39
+ get_fxnc().FXNPredictionStreamRelease(self.__stream)
40
+ self.__stream = None
fxn/c/value.py CHANGED
@@ -1,50 +1,223 @@
1
1
  #
2
2
  # Function
3
- # Copyright © 2024 NatML Inc. All Rights Reserved.
3
+ # Copyright © 2025 NatML Inc. All Rights Reserved.
4
4
  #
5
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
6
+ from __future__ import annotations
7
+ from collections.abc import Iterable
8
+ from enum import IntFlag
9
+ from ctypes import byref, cast, c_char_p, c_int, c_int32, c_uint8, c_void_p, string_at, POINTER
10
+ from io import BytesIO
11
+ from json import dumps, loads
12
+ from numpy import array, dtype, int32, ndarray, zeros
13
+ from numpy.ctypeslib import as_array, as_ctypes_type
14
+ from PIL import Image
15
+ from typing import final, Any
9
16
 
10
- class FXNValueFlags(c_int):
17
+ from ..types import Dtype
18
+ from .fxnc import get_fxnc, status_to_error, FXNStatus
19
+
20
+ class ValueFlags (IntFlag):
11
21
  NONE = 0
12
22
  COPY_DATA = 1
13
23
 
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
24
+ @final
25
+ class Value:
26
+
27
+ def __init__ (self, value, *, owner: bool=True):
28
+ self.__value = value
29
+ self.__owner = owner
30
+
31
+ @property
32
+ def data (self):
33
+ data = c_void_p()
34
+ status = get_fxnc().FXNValueGetData(self.__value, byref(data))
35
+ if status == FXNStatus.OK:
36
+ return data
37
+ else:
38
+ raise RuntimeError(f"Failed to get value data with error: {status_to_error(status)}")
39
+
40
+ @property
41
+ def type (self) -> Dtype:
42
+ dtype = c_int()
43
+ status = get_fxnc().FXNValueGetType(self.__value, byref(dtype))
44
+ if status == FXNStatus.OK:
45
+ return _DTYPE_TO_STR.get(dtype.value)
46
+ else:
47
+ raise RuntimeError(f"Failed to get value data type with error: {status_to_error(status)}")
48
+
49
+ @property
50
+ def shape (self) -> list[int] | None:
51
+ if self.type not in _TENSOR_DTYPES:
52
+ return None
53
+ fxnc = get_fxnc()
54
+ dims = c_int32()
55
+ status = fxnc.FXNValueGetDimensions(self.__value, byref(dims))
56
+ if status != FXNStatus.OK:
57
+ raise RuntimeError(f"Failed to get value dimensions with error: {status_to_error(status)}")
58
+ shape = zeros(dims.value, dtype=int32)
59
+ status = fxnc.FXNValueGetShape(self.__value, shape.ctypes.data_as(POINTER(c_int32)), dims)
60
+ if status == FXNStatus.OK:
61
+ return shape.tolist()
62
+ else:
63
+ raise RuntimeError(f"Failed to get value shape with error: {status_to_error(status)}")
64
+
65
+ def to_object (self) -> Any:
66
+ type = self.type
67
+ if type == Dtype.null:
68
+ return None
69
+ elif type in _TENSOR_DTYPES:
70
+ ctype = as_ctypes_type(dtype(type))
71
+ tensor = as_array(cast(self.data, POINTER(ctype)), self.shape)
72
+ return tensor.item() if len(tensor.shape) == 0 else tensor.copy()
73
+ elif type == Dtype.string:
74
+ return cast(self.data, c_char_p).value.decode()
75
+ elif type in [Dtype.list, Dtype.dict]:
76
+ return loads(cast(self.data, c_char_p).value.decode())
77
+ elif type == Dtype.image:
78
+ pixel_buffer = as_array(cast(self.data, POINTER(c_uint8)), self.shape)
79
+ return Image.fromarray(pixel_buffer.squeeze()).copy()
80
+ elif type == Dtype.binary:
81
+ return BytesIO(string_at(self.data, self.shape[0]))
82
+ else:
83
+ raise RuntimeError(f"Failed to convert Function value to object because value has unsupported type: {type}")
84
+
85
+ def __enter__ (self):
86
+ return self
87
+
88
+ def __exit__ (self, exc_type, exc_value, traceback):
89
+ self.__release()
90
+
91
+ def __release (self):
92
+ if self.__value and self.__owner:
93
+ get_fxnc().FXNValueRelease(self.__value)
94
+ self.__value = None
95
+
96
+ @classmethod
97
+ def create_array (
98
+ cls,
99
+ data: ndarray,
100
+ *,
101
+ flags: ValueFlags=ValueFlags.NONE
102
+ ) -> Value:
103
+ dtype = _STR_TO_DTYPE.get(data.dtype.name)
104
+ if dtype is None:
105
+ raise RuntimeError(f"Failed to create array value because data type is not supported: {data.dtype}")
106
+ value = c_void_p()
107
+ status = get_fxnc().FXNValueCreateArray(
108
+ data.ctypes.data_as(c_void_p),
109
+ data.ctypes.shape_as(c_int32),
110
+ len(data.shape),
111
+ dtype,
112
+ flags,
113
+ byref(value)
114
+ )
115
+ if status == FXNStatus.OK:
116
+ return Value(value)
117
+ else:
118
+ raise RuntimeError(f"Failed to create array value with error: {status_to_error(status)}")
119
+
120
+ @classmethod
121
+ def create_string (cls, data: str) -> Value:
122
+ value = c_void_p()
123
+ status = get_fxnc().FXNValueCreateString(data.encode(), byref(value))
124
+ if status == FXNStatus.OK:
125
+ return Value(value)
126
+ else:
127
+ raise RuntimeError(f"Failed to create string value with error: {status_to_error(status)}")
128
+
129
+ @classmethod
130
+ def create_list (cls, data: Iterable[Any]) -> Value:
131
+ value = c_void_p()
132
+ status = get_fxnc().FXNValueCreateList(dumps(data).encode(), byref(value))
133
+ if status == FXNStatus.OK:
134
+ return Value(value)
135
+ else:
136
+ raise RuntimeError(f"Failed to create list value with error: {status_to_error(status)}")
137
+
138
+ @classmethod
139
+ def create_dict (cls, data: dict[str, Any]) -> Value:
140
+ value = c_void_p()
141
+ status = get_fxnc().FXNValueCreateDict(dumps(data).encode(), byref(value))
142
+ if status == FXNStatus.OK:
143
+ return Value(value)
144
+ else:
145
+ raise RuntimeError(f"Failed to create dict value with error: {status_to_error(status)}")
146
+
147
+ @classmethod
148
+ def create_image (cls, image: Image.Image) -> Value:
149
+ value = c_void_p()
150
+ pixel_buffer = array(image)
151
+ status = get_fxnc().FXNValueCreateImage(
152
+ pixel_buffer.ctypes.data_as(c_void_p),
153
+ image.width,
154
+ image.height,
155
+ pixel_buffer.shape[2],
156
+ ValueFlags.COPY_DATA,
157
+ byref(value)
158
+ )
159
+ if status == FXNStatus.OK:
160
+ return Value(value)
161
+ else:
162
+ raise RuntimeError(f"Failed to create image value with error: {status_to_error(status)}")
163
+
164
+ @classmethod
165
+ def create_binary (
166
+ cls,
167
+ data: memoryview,
168
+ *,
169
+ flags: ValueFlags=ValueFlags.NONE
170
+ ) -> Value:
171
+ buffer = (c_uint8 * len(data)).from_buffer(data)
172
+ value = c_void_p()
173
+ status = get_fxnc().FXNValueCreateBinary(buffer, len(data), flags, byref(value))
174
+ if status == FXNStatus.OK:
175
+ return Value(value)
176
+ else:
177
+ raise RuntimeError(f"Failed to create binary value with error: {status_to_error(status)}")
178
+
179
+ @classmethod
180
+ def create_null (cls) -> Value:
181
+ value = c_void_p()
182
+ status = get_fxnc().FXNValueCreateNull(byref(value))
183
+ if status == FXNStatus.OK:
184
+ return Value(value)
185
+ else:
186
+ raise RuntimeError(f"Failed to create null value with error: {status_to_error(status)}")
187
+
188
+
189
+ _STR_TO_DTYPE = {
190
+ Dtype.null: 0,
191
+ Dtype.float16: 1,
192
+ Dtype.float32: 2,
193
+ Dtype.float64: 3,
194
+ Dtype.int8: 4,
195
+ Dtype.int16: 5,
196
+ Dtype.int32: 6,
197
+ Dtype.int64: 7,
198
+ Dtype.uint8: 8,
199
+ Dtype.uint16: 9,
200
+ Dtype.uint32: 10,
201
+ Dtype.uint64: 11,
202
+ Dtype.bool: 12,
203
+ Dtype.string: 13,
204
+ Dtype.list: 14,
205
+ Dtype.dict: 15,
206
+ Dtype.image: 16,
207
+ Dtype.binary: 17,
208
+ }
209
+ _DTYPE_TO_STR = { value: key for key, value in _STR_TO_DTYPE.items() }
210
+ _TENSOR_DTYPES = {
211
+ Dtype.float16,
212
+ Dtype.float32,
213
+ Dtype.float64,
214
+ Dtype.int8,
215
+ Dtype.int16,
216
+ Dtype.int32,
217
+ Dtype.int64,
218
+ Dtype.uint8,
219
+ Dtype.uint16,
220
+ Dtype.uint32,
221
+ Dtype.uint64,
222
+ Dtype.bool,
223
+ }
fxn/cli/__init__.py CHANGED
@@ -1,15 +1,15 @@
1
1
  #
2
2
  # Function
3
- # Copyright © 2024 NatML Inc. All Rights Reserved.
3
+ # Copyright © 2025 NatML Inc. All Rights Reserved.
4
4
  #
5
5
 
6
6
  from typer import Typer
7
7
 
8
8
  from .auth import app as auth_app
9
- from .env import app as env_app
9
+ #from .compile import compile_predictor
10
10
  from .misc import cli_options
11
- from .predict import predict
12
- from .predictors import archive_predictor, delete_predictor, list_predictors, retrieve_predictor, search_predictors
11
+ from .predictions import create_prediction
12
+ from .predictors import retrieve_predictor
13
13
  from ..version import __version__
14
14
 
15
15
  # Define CLI
@@ -26,16 +26,18 @@ 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.")
30
29
 
31
30
  # 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)
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)
31
+ app.command(
32
+ name="predict",
33
+ help="Make a prediction.",
34
+ context_settings={ "allow_extra_args": True, "ignore_unknown_options": True }
35
+ )(create_prediction)
36
+ # app.command(
37
+ # name="compile",
38
+ # help="Create a predictor by compiling a Python function."
39
+ # )(compile_predictor)
40
+ app.command(name="retrieve", help="Retrieve a predictor.")(retrieve_predictor)
39
41
 
40
42
  # Run
41
43
  if __name__ == "__main__":
fxn/cli/auth.py CHANGED
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Function
3
- # Copyright © 2024 NatML Inc. All Rights Reserved.
3
+ # Copyright © 2025 NatML Inc. All Rights Reserved.
4
4
  #
5
5
 
6
6
  from pathlib import Path
fxn/cli/misc.py CHANGED
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Function
3
- # Copyright © 2024 NatML Inc. All Rights Reserved.
3
+ # Copyright © 2025 NatML Inc. All Rights Reserved.
4
4
  #
5
5
 
6
6
  from rich import print