fxn 0.0.32__tar.gz → 0.0.33__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.32 → fxn-0.0.33}/PKG-INFO +1 -1
- {fxn-0.0.32 → fxn-0.0.33}/fxn/graph/client.py +4 -6
- {fxn-0.0.32 → fxn-0.0.33}/fxn/libs/macos/Function.dylib +0 -0
- {fxn-0.0.32 → fxn-0.0.33}/fxn/libs/windows/Function.dll +0 -0
- {fxn-0.0.32 → fxn-0.0.33}/fxn/services/prediction/service.py +32 -20
- {fxn-0.0.32 → fxn-0.0.33}/fxn/services/predictor.py +1 -1
- {fxn-0.0.32 → fxn-0.0.33}/fxn/version.py +1 -1
- {fxn-0.0.32 → fxn-0.0.33}/fxn.egg-info/PKG-INFO +1 -1
- {fxn-0.0.32 → fxn-0.0.33}/LICENSE +0 -0
- {fxn-0.0.32 → fxn-0.0.33}/README.md +0 -0
- {fxn-0.0.32 → fxn-0.0.33}/fxn/__init__.py +0 -0
- {fxn-0.0.32 → fxn-0.0.33}/fxn/cli/__init__.py +0 -0
- {fxn-0.0.32 → fxn-0.0.33}/fxn/cli/auth.py +0 -0
- {fxn-0.0.32 → fxn-0.0.33}/fxn/cli/env.py +0 -0
- {fxn-0.0.32 → fxn-0.0.33}/fxn/cli/misc.py +0 -0
- {fxn-0.0.32 → fxn-0.0.33}/fxn/cli/predict.py +0 -0
- {fxn-0.0.32 → fxn-0.0.33}/fxn/cli/predictors.py +0 -0
- {fxn-0.0.32 → fxn-0.0.33}/fxn/function.py +0 -0
- {fxn-0.0.32 → fxn-0.0.33}/fxn/graph/__init__.py +0 -0
- {fxn-0.0.32 → fxn-0.0.33}/fxn/libs/__init__.py +0 -0
- {fxn-0.0.32 → fxn-0.0.33}/fxn/libs/linux/__init__.py +0 -0
- {fxn-0.0.32 → fxn-0.0.33}/fxn/libs/macos/__init__.py +0 -0
- {fxn-0.0.32 → fxn-0.0.33}/fxn/libs/windows/__init__.py +0 -0
- {fxn-0.0.32 → fxn-0.0.33}/fxn/magic.py +0 -0
- {fxn-0.0.32 → fxn-0.0.33}/fxn/services/__init__.py +0 -0
- {fxn-0.0.32 → fxn-0.0.33}/fxn/services/environment.py +0 -0
- {fxn-0.0.32 → fxn-0.0.33}/fxn/services/prediction/__init__.py +0 -0
- {fxn-0.0.32 → fxn-0.0.33}/fxn/services/prediction/fxnc.py +0 -0
- {fxn-0.0.32 → fxn-0.0.33}/fxn/services/storage.py +0 -0
- {fxn-0.0.32 → fxn-0.0.33}/fxn/services/user.py +0 -0
- {fxn-0.0.32 → fxn-0.0.33}/fxn/types/__init__.py +0 -0
- {fxn-0.0.32 → fxn-0.0.33}/fxn/types/dtype.py +0 -0
- {fxn-0.0.32 → fxn-0.0.33}/fxn/types/environment.py +0 -0
- {fxn-0.0.32 → fxn-0.0.33}/fxn/types/prediction.py +0 -0
- {fxn-0.0.32 → fxn-0.0.33}/fxn/types/predictor.py +0 -0
- {fxn-0.0.32 → fxn-0.0.33}/fxn/types/profile.py +0 -0
- {fxn-0.0.32 → fxn-0.0.33}/fxn/types/storage.py +0 -0
- {fxn-0.0.32 → fxn-0.0.33}/fxn/types/tag.py +0 -0
- {fxn-0.0.32 → fxn-0.0.33}/fxn/types/user.py +0 -0
- {fxn-0.0.32 → fxn-0.0.33}/fxn/types/value.py +0 -0
- {fxn-0.0.32 → fxn-0.0.33}/fxn.egg-info/SOURCES.txt +0 -0
- {fxn-0.0.32 → fxn-0.0.33}/fxn.egg-info/dependency_links.txt +0 -0
- {fxn-0.0.32 → fxn-0.0.33}/fxn.egg-info/entry_points.txt +0 -0
- {fxn-0.0.32 → fxn-0.0.33}/fxn.egg-info/requires.txt +0 -0
- {fxn-0.0.32 → fxn-0.0.33}/fxn.egg-info/top_level.txt +0 -0
- {fxn-0.0.32 → fxn-0.0.33}/pyproject.toml +0 -0
- {fxn-0.0.32 → fxn-0.0.33}/setup.cfg +0 -0
@@ -32,14 +32,12 @@ class GraphClient:
|
|
32
32
|
json={ "query": query, "variables": variables },
|
33
33
|
headers={ "Authorization": f"Bearer {self.access_key}" } if self.access_key else { }
|
34
34
|
)
|
35
|
-
# Check
|
36
35
|
payload = response.json()
|
36
|
+
# Check error
|
37
37
|
try:
|
38
38
|
response.raise_for_status()
|
39
|
-
except:
|
40
|
-
|
41
|
-
|
42
|
-
if "errors" in payload:
|
43
|
-
raise RuntimeError(payload["errors"][0]["message"])
|
39
|
+
except Exception as ex:
|
40
|
+
error = payload["errors"][0]["message"] if "errors" in payload else str(ex)
|
41
|
+
raise RuntimeError(error)
|
44
42
|
# Return
|
45
43
|
return payload["data"]
|
Binary file
|
Binary file
|
@@ -44,7 +44,9 @@ class PredictionService:
|
|
44
44
|
inputs: Dict[str, Union[ndarray, str, float, int, bool, List, Dict[str, Any], Path, Image.Image, Value]] = None,
|
45
45
|
raw_outputs: bool=False,
|
46
46
|
return_binary_path: bool=True,
|
47
|
-
data_url_limit: int=None
|
47
|
+
data_url_limit: int=None,
|
48
|
+
client_id: str=None,
|
49
|
+
configuration_id: str=None
|
48
50
|
) -> Prediction:
|
49
51
|
"""
|
50
52
|
Create a prediction.
|
@@ -55,6 +57,8 @@ class PredictionService:
|
|
55
57
|
raw_outputs (bool): Skip converting output values into Pythonic types. This only applies to `CLOUD` predictions.
|
56
58
|
return_binary_path (bool): Write binary values to file and return a `Path` instead of returning `BytesIO` instance.
|
57
59
|
data_url_limit (int): Return a data URL if a given output value is smaller than this size in bytes. This only applies to `CLOUD` predictions.
|
60
|
+
client_id (str): Function client identifier. Specify this to override the current client identifier.
|
61
|
+
configuration_id (str): Configuration identifier. Specify this to override the current client configuration identifier.
|
58
62
|
|
59
63
|
Returns:
|
60
64
|
Prediction: Created prediction.
|
@@ -66,13 +70,13 @@ class PredictionService:
|
|
66
70
|
key = uuid4().hex
|
67
71
|
values = { name: self.to_value(value, name, key=key).model_dump(mode="json") for name, value in inputs.items() } if inputs is not None else { }
|
68
72
|
# Query
|
69
|
-
response = post(
|
73
|
+
response = post(
|
70
74
|
f"{self.client.api_url}/predict/{tag}?rawOutputs=true&dataUrlLimit={data_url_limit}",
|
71
75
|
json=values,
|
72
76
|
headers={
|
73
77
|
"Authorization": f"Bearer {self.client.access_key}",
|
74
|
-
"fxn-client": self.__get_client_id(),
|
75
|
-
"fxn-configuration-token": self.
|
78
|
+
"fxn-client": client_id if client_id is not None else self.__get_client_id(),
|
79
|
+
"fxn-configuration-token": configuration_id if configuration_id is not None else self.__get_configuration_id()
|
76
80
|
}
|
77
81
|
)
|
78
82
|
# Check
|
@@ -84,12 +88,14 @@ class PredictionService:
|
|
84
88
|
raise RuntimeError(error)
|
85
89
|
# Parse prediction
|
86
90
|
prediction = self.__parse_prediction(prediction, raw_outputs=raw_outputs, return_binary_path=return_binary_path)
|
91
|
+
# Check edge prediction
|
92
|
+
if prediction.type != PredictorType.Edge or raw_outputs:
|
93
|
+
return prediction
|
94
|
+
# Load edge predictor
|
95
|
+
predictor = self.__load(prediction)
|
96
|
+
self.__cache[tag] = predictor
|
87
97
|
# Create edge prediction
|
88
|
-
|
89
|
-
predictor = self.__load(prediction)
|
90
|
-
self.__cache[tag] = predictor
|
91
|
-
prediction = self.__predict(tag=tag, predictor=predictor, inputs=inputs) if inputs is not None else prediction
|
92
|
-
# Return
|
98
|
+
prediction = self.__predict(tag=tag, predictor=predictor, inputs=inputs) if inputs is not None else prediction
|
93
99
|
return prediction
|
94
100
|
|
95
101
|
async def stream (
|
@@ -100,6 +106,8 @@ class PredictionService:
|
|
100
106
|
raw_outputs: bool=False,
|
101
107
|
return_binary_path: bool=True,
|
102
108
|
data_url_limit: int=None,
|
109
|
+
client_id: str=None,
|
110
|
+
configuration_id: str=None
|
103
111
|
) -> AsyncIterator[Prediction]:
|
104
112
|
"""
|
105
113
|
Create a streaming prediction.
|
@@ -112,6 +120,8 @@ class PredictionService:
|
|
112
120
|
raw_outputs (bool): Skip converting output values into Pythonic types. This only applies to `CLOUD` predictions.
|
113
121
|
return_binary_path (bool): Write binary values to file and return a `Path` instead of returning `BytesIO` instance.
|
114
122
|
data_url_limit (int): Return a data URL if a given output value is smaller than this size in bytes. This only applies to `CLOUD` predictions.
|
123
|
+
client_id (str): Function client identifier. Specify this to override the current client identifier.
|
124
|
+
configuration_id (str): Configuration identifier. Specify this to override the current client configuration identifier.
|
115
125
|
|
116
126
|
Returns:
|
117
127
|
Prediction: Created prediction.
|
@@ -122,14 +132,14 @@ class PredictionService:
|
|
122
132
|
return
|
123
133
|
# Serialize inputs
|
124
134
|
key = uuid4().hex
|
125
|
-
values = { name: self.to_value(value, name, key=key).model_dump(mode="json") for name, value in inputs.items() }
|
135
|
+
values = { name: self.to_value(value, name, key=key).model_dump(mode="json") for name, value in inputs.items() }
|
126
136
|
# Request
|
127
137
|
url = f"{self.client.api_url}/predict/{tag}?stream=true&rawOutputs=true&dataUrlLimit={data_url_limit}"
|
128
138
|
headers = {
|
129
139
|
"Content-Type": "application/json",
|
130
140
|
"Authorization": f"Bearer {self.client.access_key}",
|
131
|
-
"fxn-client": self.__get_client_id(),
|
132
|
-
"fxn-configuration-token": self.
|
141
|
+
"fxn-client": client_id if client_id is not None else self.__get_client_id(),
|
142
|
+
"fxn-configuration-token": configuration_id if configuration_id is not None else self.__get_configuration_id()
|
133
143
|
}
|
134
144
|
async with ClientSession(headers=headers) as session:
|
135
145
|
async with session.post(url, data=dumps(values)) as response:
|
@@ -143,12 +153,14 @@ class PredictionService:
|
|
143
153
|
raise RuntimeError(error)
|
144
154
|
# Parse prediction
|
145
155
|
prediction = self.__parse_prediction(prediction, raw_outputs=raw_outputs, return_binary_path=return_binary_path)
|
146
|
-
#
|
147
|
-
if prediction.type
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
156
|
+
# Check edge prediction
|
157
|
+
if prediction.type != PredictorType.Edge or raw_outputs:
|
158
|
+
return prediction
|
159
|
+
# Load edge predictor
|
160
|
+
predictor = self.__load(prediction)
|
161
|
+
self.__cache[tag] = predictor
|
162
|
+
# Create prediction
|
163
|
+
prediction = self.__predict(tag=tag, predictor=predictor, inputs=inputs) if inputs is not None else prediction
|
152
164
|
yield prediction
|
153
165
|
|
154
166
|
def to_object (
|
@@ -303,14 +315,14 @@ class PredictionService:
|
|
303
315
|
return f"windows:{machine()}"
|
304
316
|
raise RuntimeError(f"Function cannot make predictions on the {id} platform")
|
305
317
|
|
306
|
-
def
|
318
|
+
def __get_configuration_id (self) -> Optional[str]:
|
307
319
|
# Check
|
308
320
|
if not self.__fxnc:
|
309
321
|
return None
|
310
322
|
# Get
|
311
323
|
buffer = create_string_buffer(2048)
|
312
324
|
status = self.__fxnc.FXNConfigurationGetUniqueID(buffer, len(buffer))
|
313
|
-
assert status.value == FXNStatus.OK, f"Failed to create prediction configuration
|
325
|
+
assert status.value == FXNStatus.OK, f"Failed to create prediction configuration identifier with status: {status.value}"
|
314
326
|
uid = buffer.value.decode("utf-8")
|
315
327
|
# Return
|
316
328
|
return uid
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|