blaxel 0.1.14rc48__py3-none-any.whl → 0.1.14rc50__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.
blaxel/common/internal.py CHANGED
@@ -7,21 +7,25 @@ from typing import Optional
7
7
 
8
8
  logger = getLogger(__name__)
9
9
 
10
- def get_alphanumeric_limited_hash(input_str, max_size):
11
- # Create SHA-256 hash of the input string
12
- hash_obj = hashlib.sha256(input_str.encode('utf-8'))
13
-
14
- # Get the hash digest in base64 format
15
- hash_base64 = base64.b64encode(hash_obj.digest()).decode('utf-8')
16
-
17
- # Remove non-alphanumeric characters and convert to lowercase
18
- alphanumeric = re.sub(r'[^a-zA-Z0-9]', '', hash_base64).lower()
19
-
20
- # Skip the first character to match the Node.js crypto output
21
- alphanumeric = alphanumeric[1:]
22
-
23
- # Limit to max_size characters
24
- return alphanumeric[:max_size] if len(alphanumeric) > max_size else alphanumeric
10
+ def get_alphanumeric_limited_hash(input_str, max_size=48):
11
+ """
12
+ Create an alphanumeric hash using MD5 that can be reproduced in Go, TypeScript, and Python.
13
+
14
+ Args:
15
+ input_str (str): The input string to hash
16
+ max_size (int): The maximum length of the returned hash
17
+
18
+ Returns:
19
+ str: An alphanumeric hash of the input string, limited to max_size
20
+ """
21
+ # Calculate MD5 hash and convert to hexadecimal
22
+ hash_hex = hashlib.md5(input_str.encode('utf-8')).hexdigest()
23
+
24
+ # Limit to max_size
25
+ if len(hash_hex) > max_size:
26
+ return hash_hex[:max_size]
27
+
28
+ return hash_hex
25
29
 
26
30
 
27
31
  def get_global_unique_hash(workspace: str, type: str, name: str) -> str:
blaxel/common/settings.py CHANGED
@@ -62,9 +62,14 @@ class Settings:
62
62
  @property
63
63
  def run_internal_hostname(self) -> str:
64
64
  """Get the run internal hostname."""
65
- return ''
66
- # Not working in python
67
- # return os.environ.get("BL_RUN_INTERNAL_HOSTNAME", "")
65
+ if self.generation == "":
66
+ return ""
67
+ return os.environ.get("BL_RUN_INTERNAL_HOSTNAME", "")
68
+
69
+ @property
70
+ def generation(self) -> str:
71
+ """Get the generation."""
72
+ return os.environ.get("BL_GENERATION", "")
68
73
 
69
74
  @property
70
75
  def bl_cloud(self) -> bool:
@@ -0,0 +1,55 @@
1
+ import argparse
2
+ import os
3
+ import sys
4
+ import asyncio
5
+ from typing import Any, Dict, Callable
6
+ import requests
7
+
8
+ class BlJob:
9
+ def get_arguments(self) -> Dict[str, Any]:
10
+ if not os.getenv('BL_EXECUTION_DATA_URL'):
11
+ parser = argparse.ArgumentParser()
12
+ # Parse known args, ignore unknown
13
+ args, unknown = parser.parse_known_args()
14
+ # Convert to dict and include unknown args
15
+ args_dict = vars(args)
16
+ # Add unknown args to dict
17
+ for i in range(0, len(unknown), 2):
18
+ if i + 1 < len(unknown):
19
+ key = unknown[i].lstrip('-')
20
+ args_dict[key] = unknown[i + 1]
21
+ return args_dict
22
+
23
+ response = requests.get(os.getenv('BL_EXECUTION_DATA_URL'))
24
+ data = response.json()
25
+ tasks = data.get('tasks', [])
26
+ return tasks[self.index] if self.index < len(tasks) else {}
27
+
28
+ @property
29
+ def index_key(self) -> str:
30
+ return os.getenv('BL_EXECUTION_INDEX_KEY', 'TASK_INDEX')
31
+
32
+ @property
33
+ def index(self) -> int:
34
+ index_value = os.getenv(self.index_key)
35
+ return int(index_value) if index_value else 0
36
+
37
+ def start(self, func: Callable):
38
+ """
39
+ Run a job defined in a function, it's run in the current process.
40
+ Handles both async and sync functions.
41
+ Arguments are passed as keyword arguments to the function.
42
+ """
43
+ try:
44
+ parsed_args = self.get_arguments()
45
+ if asyncio.iscoroutinefunction(func):
46
+ asyncio.run(func(**parsed_args))
47
+ else:
48
+ func(**parsed_args)
49
+ sys.exit(0)
50
+ except Exception as error:
51
+ print('Job execution failed:', error, file=sys.stderr)
52
+ sys.exit(1)
53
+
54
+ # Create a singleton instance
55
+ bl_job = BlJob()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: blaxel
3
- Version: 0.1.14rc48
3
+ Version: 0.1.14rc50
4
4
  Summary: Add your description here
5
5
  Author-email: cploujoux <cploujoux@blaxel.ai>
6
6
  License-File: LICENSE
@@ -262,14 +262,15 @@ blaxel/client/models/workspace_runtime.py,sha256=dxEpmwCFPOCRKHRKhY-iW7j6TbtL5qU
262
262
  blaxel/client/models/workspace_user.py,sha256=70CcifQWYbeWG7TDui4pblTzUe5sVK0AS19vNCzKE8g,3423
263
263
  blaxel/common/autoload.py,sha256=NFuK71-IHOY2JQyEBSjDCVfUaQ8D8PJsEUEryIdG4AU,263
264
264
  blaxel/common/env.py,sha256=wTbzPDdNgz4HMJiS2NCZmQlN0qpxy1PQEYBaZgtvhoc,1247
265
- blaxel/common/internal.py,sha256=J-etgnBzelb-ln8uBR9WIWzrEUyDds8rdT9FImjes9g,2390
265
+ blaxel/common/internal.py,sha256=PExgeKfJEmjINKreNb3r2nB5GAfG7uJhbfqHxuxBED8,2395
266
266
  blaxel/common/logger.py,sha256=emqgonfZMBIaQPowpngWOOZxWQieKP-yj_OzGZT8Oe8,1918
267
- blaxel/common/settings.py,sha256=uVM6pjcovw_JPjiNZQb9WbtvLu3RdVGy7PNBcDGzoWY,2190
267
+ blaxel/common/settings.py,sha256=S7Su64Tu9-7OL5qZIOMVfYOwQos9gs7B3XpRAvI50ho,2331
268
268
  blaxel/instrumentation/exporters.py,sha256=EoX3uaBVku1Rg49pSNXKFyHhgY5OV3Ih6UlqgjF5epw,1670
269
269
  blaxel/instrumentation/log.py,sha256=4tGyvLg6r4DbjqJfajYbbZ1toUzF4Q4H7kHVqYWFAEA,2537
270
270
  blaxel/instrumentation/manager.py,sha256=jVwVasyMI6tu0zv27DVYOaN57nXYuHFJ8QzJQKaNoK4,8880
271
271
  blaxel/instrumentation/map.py,sha256=zZoiUiQHmik5WQZ4VCWNARSa6ppMi0r7D6hlb41N-Mg,1589
272
272
  blaxel/instrumentation/span.py,sha256=X2lwfu_dyxwQTMQJT2vbXOrbVSChEhjRLc413QOxQJM,3244
273
+ blaxel/jobs/__init__.py,sha256=r4p2tYz8fCKzDGynLTq55KFSjdSIxhxjnarQf4hdMWI,1838
273
274
  blaxel/mcp/__init__.py,sha256=KednMrtuc4Y0O3lv7u1Lla54FCk8UX9c1k0USjL3Ahk,69
274
275
  blaxel/mcp/client.py,sha256=cFFXfpKXoMu8qTUly2ejF0pX2iBQkSNAxqwvDV1V6xY,4979
275
276
  blaxel/mcp/server.py,sha256=GIldtA_NgIc2dzd7ZpPvpbhpIt_7AfKu5yS_YJ0bDGg,7310
@@ -340,7 +341,7 @@ blaxel/tools/llamaindex.py,sha256=-gQ-C9V_h9a11J4ItsbWjXrCJOg0lRKsb98v9rVsNak,71
340
341
  blaxel/tools/openai.py,sha256=GuFXkj6bXEwldyVr89jEsRAi5ihZUVEVe327QuWiGNs,653
341
342
  blaxel/tools/pydantic.py,sha256=CvnNbAG_J4yBtA-XFI4lQrq3FYKjNd39hu841vZT004,1801
342
343
  blaxel/tools/types.py,sha256=YPCGJ4vZDhqR0X2H_TWtc5chQScsC32nGTQdRKJlO8Y,707
343
- blaxel-0.1.14rc48.dist-info/METADATA,sha256=V8dnLg7IzMcr9dO9vLzcHEbUYLTBtr_zh8wV2eN3A7g,11776
344
- blaxel-0.1.14rc48.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
345
- blaxel-0.1.14rc48.dist-info/licenses/LICENSE,sha256=p5PNQvpvyDT_0aYBDgmV1fFI_vAD2aSV0wWG7VTgRis,1069
346
- blaxel-0.1.14rc48.dist-info/RECORD,,
344
+ blaxel-0.1.14rc50.dist-info/METADATA,sha256=ZCoNc3i7CshGtPr2XqfSFFEPwuJAfZfuopesn5G4Zno,11776
345
+ blaxel-0.1.14rc50.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
346
+ blaxel-0.1.14rc50.dist-info/licenses/LICENSE,sha256=p5PNQvpvyDT_0aYBDgmV1fFI_vAD2aSV0wWG7VTgRis,1069
347
+ blaxel-0.1.14rc50.dist-info/RECORD,,