fxn 0.0.32__tar.gz → 0.0.34__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.
Files changed (47) hide show
  1. {fxn-0.0.32 → fxn-0.0.34}/PKG-INFO +1 -1
  2. {fxn-0.0.32 → fxn-0.0.34}/fxn/graph/client.py +4 -6
  3. {fxn-0.0.32 → fxn-0.0.34}/fxn/libs/macos/Function.dylib +0 -0
  4. {fxn-0.0.32 → fxn-0.0.34}/fxn/libs/windows/Function.dll +0 -0
  5. {fxn-0.0.32 → fxn-0.0.34}/fxn/services/prediction/service.py +33 -20
  6. {fxn-0.0.32 → fxn-0.0.34}/fxn/services/predictor.py +1 -1
  7. {fxn-0.0.32 → fxn-0.0.34}/fxn/version.py +1 -1
  8. {fxn-0.0.32 → fxn-0.0.34}/fxn.egg-info/PKG-INFO +1 -1
  9. {fxn-0.0.32 → fxn-0.0.34}/LICENSE +0 -0
  10. {fxn-0.0.32 → fxn-0.0.34}/README.md +0 -0
  11. {fxn-0.0.32 → fxn-0.0.34}/fxn/__init__.py +0 -0
  12. {fxn-0.0.32 → fxn-0.0.34}/fxn/cli/__init__.py +0 -0
  13. {fxn-0.0.32 → fxn-0.0.34}/fxn/cli/auth.py +0 -0
  14. {fxn-0.0.32 → fxn-0.0.34}/fxn/cli/env.py +0 -0
  15. {fxn-0.0.32 → fxn-0.0.34}/fxn/cli/misc.py +0 -0
  16. {fxn-0.0.32 → fxn-0.0.34}/fxn/cli/predict.py +0 -0
  17. {fxn-0.0.32 → fxn-0.0.34}/fxn/cli/predictors.py +0 -0
  18. {fxn-0.0.32 → fxn-0.0.34}/fxn/function.py +0 -0
  19. {fxn-0.0.32 → fxn-0.0.34}/fxn/graph/__init__.py +0 -0
  20. {fxn-0.0.32 → fxn-0.0.34}/fxn/libs/__init__.py +0 -0
  21. {fxn-0.0.32 → fxn-0.0.34}/fxn/libs/linux/__init__.py +0 -0
  22. {fxn-0.0.32 → fxn-0.0.34}/fxn/libs/macos/__init__.py +0 -0
  23. {fxn-0.0.32 → fxn-0.0.34}/fxn/libs/windows/__init__.py +0 -0
  24. {fxn-0.0.32 → fxn-0.0.34}/fxn/magic.py +0 -0
  25. {fxn-0.0.32 → fxn-0.0.34}/fxn/services/__init__.py +0 -0
  26. {fxn-0.0.32 → fxn-0.0.34}/fxn/services/environment.py +0 -0
  27. {fxn-0.0.32 → fxn-0.0.34}/fxn/services/prediction/__init__.py +0 -0
  28. {fxn-0.0.32 → fxn-0.0.34}/fxn/services/prediction/fxnc.py +0 -0
  29. {fxn-0.0.32 → fxn-0.0.34}/fxn/services/storage.py +0 -0
  30. {fxn-0.0.32 → fxn-0.0.34}/fxn/services/user.py +0 -0
  31. {fxn-0.0.32 → fxn-0.0.34}/fxn/types/__init__.py +0 -0
  32. {fxn-0.0.32 → fxn-0.0.34}/fxn/types/dtype.py +0 -0
  33. {fxn-0.0.32 → fxn-0.0.34}/fxn/types/environment.py +0 -0
  34. {fxn-0.0.32 → fxn-0.0.34}/fxn/types/prediction.py +0 -0
  35. {fxn-0.0.32 → fxn-0.0.34}/fxn/types/predictor.py +0 -0
  36. {fxn-0.0.32 → fxn-0.0.34}/fxn/types/profile.py +0 -0
  37. {fxn-0.0.32 → fxn-0.0.34}/fxn/types/storage.py +0 -0
  38. {fxn-0.0.32 → fxn-0.0.34}/fxn/types/tag.py +0 -0
  39. {fxn-0.0.32 → fxn-0.0.34}/fxn/types/user.py +0 -0
  40. {fxn-0.0.32 → fxn-0.0.34}/fxn/types/value.py +0 -0
  41. {fxn-0.0.32 → fxn-0.0.34}/fxn.egg-info/SOURCES.txt +0 -0
  42. {fxn-0.0.32 → fxn-0.0.34}/fxn.egg-info/dependency_links.txt +0 -0
  43. {fxn-0.0.32 → fxn-0.0.34}/fxn.egg-info/entry_points.txt +0 -0
  44. {fxn-0.0.32 → fxn-0.0.34}/fxn.egg-info/requires.txt +0 -0
  45. {fxn-0.0.32 → fxn-0.0.34}/fxn.egg-info/top_level.txt +0 -0
  46. {fxn-0.0.32 → fxn-0.0.34}/pyproject.toml +0 -0
  47. {fxn-0.0.32 → fxn-0.0.34}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fxn
3
- Version: 0.0.32
3
+ Version: 0.0.34
4
4
  Summary: Run on-device and cloud AI prediction functions in Python. Register at https://fxn.ai.
5
5
  Author-email: "NatML Inc." <hi@fxn.ai>
6
6
  License: Apache License
@@ -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
- raise RuntimeError(payload.get("error"))
41
- # Check error
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"]
@@ -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( # INCOMPLETE # Configuration token
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.__get_configuration_token()
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
- if prediction.type == PredictorType.Edge:
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() } # INCOMPLETE # values
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.__get_configuration_token()
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,15 @@ 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
- # Create edge prediction
147
- if prediction.type == PredictorType.Edge:
148
- predictor = self.__load(prediction)
149
- self.__cache[tag] = predictor
150
- prediction = self.__predict(tag=tag, predictor=predictor, inputs=inputs) if inputs is not None else prediction
151
- # Yield
156
+ # Check edge prediction
157
+ if prediction.type != PredictorType.Edge or raw_outputs:
158
+ yield prediction
159
+ continue
160
+ # Load edge predictor
161
+ predictor = self.__load(prediction)
162
+ self.__cache[tag] = predictor
163
+ # Create prediction
164
+ prediction = self.__predict(tag=tag, predictor=predictor, inputs=inputs) if inputs is not None else prediction
152
165
  yield prediction
153
166
 
154
167
  def to_object (
@@ -303,14 +316,14 @@ class PredictionService:
303
316
  return f"windows:{machine()}"
304
317
  raise RuntimeError(f"Function cannot make predictions on the {id} platform")
305
318
 
306
- def __get_configuration_token (self) -> Optional[str]:
319
+ def __get_configuration_id (self) -> Optional[str]:
307
320
  # Check
308
321
  if not self.__fxnc:
309
322
  return None
310
323
  # Get
311
324
  buffer = create_string_buffer(2048)
312
325
  status = self.__fxnc.FXNConfigurationGetUniqueID(buffer, len(buffer))
313
- assert status.value == FXNStatus.OK, f"Failed to create prediction configuration token with status: {status.value}"
326
+ assert status.value == FXNStatus.OK, f"Failed to create prediction configuration identifier with status: {status.value}"
314
327
  uid = buffer.value.decode("utf-8")
315
328
  # Return
316
329
  return uid
@@ -28,7 +28,7 @@ class PredictorService:
28
28
  Predictor: Predictor.
29
29
  """
30
30
  # Query
31
- response = self.client.queryfxn(f"""
31
+ response = self.client.query(f"""
32
32
  query ($input: PredictorInput!) {{
33
33
  predictor (input: $input) {{
34
34
  {PREDICTOR_FIELDS}
@@ -3,4 +3,4 @@
3
3
  # Copyright © 2024 NatML Inc. All Rights Reserved.
4
4
  #
5
5
 
6
- __version__ = "0.0.32"
6
+ __version__ = "0.0.34"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fxn
3
- Version: 0.0.32
3
+ Version: 0.0.34
4
4
  Summary: Run on-device and cloud AI prediction functions in Python. Register at https://fxn.ai.
5
5
  Author-email: "NatML Inc." <hi@fxn.ai>
6
6
  License: Apache License
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