jaseci 1.4.2.5__py3-none-any.whl → 2.0.0__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.

Potentially problematic release.


This version of jaseci might be problematic. Click here for more details.

Files changed (186) hide show
  1. jaseci/__init__.py +3 -37
  2. jaseci-2.0.0.dist-info/METADATA +65 -0
  3. jaseci-2.0.0.dist-info/RECORD +4 -0
  4. {jaseci-1.4.2.5.dist-info → jaseci-2.0.0.dist-info}/WHEEL +1 -2
  5. jaseci/VERSION +0 -1
  6. jaseci/cli_tools/__init__.py +0 -0
  7. jaseci/cli_tools/book_tools.py +0 -457
  8. jaseci/cli_tools/jsctl.py +0 -500
  9. jaseci/cli_tools/tests/__init__.py +0 -0
  10. jaseci/cli_tools/tests/test_jsctl.py +0 -556
  11. jaseci/extens/__init__.py +0 -0
  12. jaseci/extens/act_lib/__init__.py +0 -0
  13. jaseci/extens/act_lib/date.py +0 -117
  14. jaseci/extens/act_lib/elastic.py +0 -87
  15. jaseci/extens/act_lib/file.py +0 -76
  16. jaseci/extens/act_lib/file_handler.py +0 -189
  17. jaseci/extens/act_lib/internal.py +0 -18
  18. jaseci/extens/act_lib/jaseci.py +0 -61
  19. jaseci/extens/act_lib/mail.py +0 -10
  20. jaseci/extens/act_lib/maths.py +0 -168
  21. jaseci/extens/act_lib/net.py +0 -191
  22. jaseci/extens/act_lib/rand.py +0 -82
  23. jaseci/extens/act_lib/regex.py +0 -85
  24. jaseci/extens/act_lib/request.py +0 -169
  25. jaseci/extens/act_lib/std.py +0 -235
  26. jaseci/extens/act_lib/storage.py +0 -53
  27. jaseci/extens/act_lib/stripe.py +0 -337
  28. jaseci/extens/act_lib/task.py +0 -13
  29. jaseci/extens/act_lib/tests/__init__.py +0 -0
  30. jaseci/extens/act_lib/tests/std_test_code.py +0 -37
  31. jaseci/extens/act_lib/tests/test_date.py +0 -26
  32. jaseci/extens/act_lib/tests/test_elastic.py +0 -159
  33. jaseci/extens/act_lib/tests/test_file.py +0 -116
  34. jaseci/extens/act_lib/tests/test_file_lib.py +0 -40
  35. jaseci/extens/act_lib/tests/test_mail_lib.py +0 -33
  36. jaseci/extens/act_lib/tests/test_maths.py +0 -147
  37. jaseci/extens/act_lib/tests/test_net_lib.py +0 -62
  38. jaseci/extens/act_lib/tests/test_regex.py +0 -61
  39. jaseci/extens/act_lib/tests/test_std.py +0 -51
  40. jaseci/extens/act_lib/tests/test_std_lib.py +0 -36
  41. jaseci/extens/act_lib/tests/test_url.py +0 -32
  42. jaseci/extens/act_lib/tests/test_vector.py +0 -36
  43. jaseci/extens/act_lib/tests/test_webtool.py +0 -44
  44. jaseci/extens/act_lib/tests/test_zlib.py +0 -24
  45. jaseci/extens/act_lib/url.py +0 -79
  46. jaseci/extens/act_lib/vector.py +0 -157
  47. jaseci/extens/act_lib/webtool.py +0 -28
  48. jaseci/extens/act_lib/zip.py +0 -33
  49. jaseci/extens/api/__init__.py +0 -0
  50. jaseci/extens/api/actions_api.py +0 -170
  51. jaseci/extens/api/alias_api.py +0 -139
  52. jaseci/extens/api/architype_api.py +0 -196
  53. jaseci/extens/api/config_api.py +0 -129
  54. jaseci/extens/api/global_api.py +0 -84
  55. jaseci/extens/api/graph_api.py +0 -167
  56. jaseci/extens/api/health_api.py +0 -20
  57. jaseci/extens/api/interface.py +0 -268
  58. jaseci/extens/api/jac_api.py +0 -171
  59. jaseci/extens/api/jsorc_api.py +0 -316
  60. jaseci/extens/api/logger_api.py +0 -89
  61. jaseci/extens/api/master_api.py +0 -133
  62. jaseci/extens/api/object_api.py +0 -101
  63. jaseci/extens/api/prometheus_api.py +0 -74
  64. jaseci/extens/api/queue_api.py +0 -140
  65. jaseci/extens/api/sentinel_api.py +0 -270
  66. jaseci/extens/api/super_api.py +0 -64
  67. jaseci/extens/api/tests/__init__.py +0 -0
  68. jaseci/extens/api/tests/test_architype_api.py +0 -66
  69. jaseci/extens/api/tests/test_global_api.py +0 -179
  70. jaseci/extens/api/tests/test_graph_api.py +0 -64
  71. jaseci/extens/api/tests/test_logger_api.py +0 -43
  72. jaseci/extens/api/tests/test_object_api.py +0 -20
  73. jaseci/extens/api/tests/test_sentinel_api.py +0 -66
  74. jaseci/extens/api/tests/test_uncommon.py +0 -107
  75. jaseci/extens/api/tests/test_user_api.py +0 -32
  76. jaseci/extens/api/tests/test_walker_api.py +0 -316
  77. jaseci/extens/api/user_api.py +0 -144
  78. jaseci/extens/api/walker_api.py +0 -298
  79. jaseci/extens/api/webhook_api.py +0 -74
  80. jaseci/extens/svc/__init__.py +0 -0
  81. jaseci/extens/svc/elastic_svc.py +0 -366
  82. jaseci/extens/svc/kube_svc.py +0 -432
  83. jaseci/extens/svc/mail_svc.py +0 -156
  84. jaseci/extens/svc/prome_svc.py +0 -378
  85. jaseci/extens/svc/redis_svc.py +0 -63
  86. jaseci/extens/svc/storage_svc.py +0 -193
  87. jaseci/extens/svc/stripe_svc.py +0 -51
  88. jaseci/extens/svc/task_svc.py +0 -155
  89. jaseci/extens/svc/tasks.py +0 -302
  90. jaseci/jac/__init__.py +0 -0
  91. jaseci/jac/interpreter/__init__.py +0 -0
  92. jaseci/jac/interpreter/architype_interp.py +0 -214
  93. jaseci/jac/interpreter/interp.py +0 -1783
  94. jaseci/jac/interpreter/sentinel_interp.py +0 -257
  95. jaseci/jac/interpreter/tests/__init__.py +0 -0
  96. jaseci/jac/interpreter/tests/test_interp.py +0 -42
  97. jaseci/jac/interpreter/walker_interp.py +0 -248
  98. jaseci/jac/ir/__init__.py +0 -0
  99. jaseci/jac/ir/ast.py +0 -73
  100. jaseci/jac/ir/ast_builder.py +0 -249
  101. jaseci/jac/ir/jac_code.py +0 -152
  102. jaseci/jac/ir/passes/__init__.py +0 -6
  103. jaseci/jac/ir/passes/ast_prune_pass.py +0 -9
  104. jaseci/jac/ir/passes/codegen_pass.py +0 -244
  105. jaseci/jac/ir/passes/ir_pass.py +0 -29
  106. jaseci/jac/ir/passes/printer_pass.py +0 -23
  107. jaseci/jac/ir/passes/pt_prune_pass.py +0 -29
  108. jaseci/jac/ir/passes/schedule.py +0 -23
  109. jaseci/jac/ir/passes/stats_pass.py +0 -16
  110. jaseci/jac/jac.g4 +0 -450
  111. jaseci/jac/jac_parse/__init__.py +0 -0
  112. jaseci/jac/jac_parse/jacLexer.py +0 -809
  113. jaseci/jac/jac_parse/jacListener.py +0 -853
  114. jaseci/jac/jac_parse/jacParser.py +0 -9192
  115. jaseci/jac/jac_set.py +0 -119
  116. jaseci/jac/jsci_vm/__init__.py +0 -0
  117. jaseci/jac/jsci_vm/disasm.py +0 -94
  118. jaseci/jac/jsci_vm/inst_ptr.py +0 -31
  119. jaseci/jac/jsci_vm/machine.py +0 -188
  120. jaseci/jac/jsci_vm/op_codes.py +0 -82
  121. jaseci/jac/jsci_vm/tests/__init__.py +0 -0
  122. jaseci/jac/jsci_vm/tests/test_codegen.py +0 -31
  123. jaseci/jac/machine/__init__.py +0 -0
  124. jaseci/jac/machine/jac_scope.py +0 -85
  125. jaseci/jac/machine/jac_value.py +0 -226
  126. jaseci/jac/machine/machine_state.py +0 -383
  127. jaseci/jac/tests/__init__.py +0 -0
  128. jaseci/jac/tests/book_code.py +0 -624
  129. jaseci/jac/tests/test_book.py +0 -380
  130. jaseci/jac/tests/test_lang_14.py +0 -49
  131. jaseci/jsorc/__init__.py +0 -7
  132. jaseci/jsorc/jsorc.py +0 -642
  133. jaseci/jsorc/jsorc_settings.py +0 -211
  134. jaseci/jsorc/jsorc_utils.py +0 -298
  135. jaseci/jsorc/live_actions.py +0 -364
  136. jaseci/jsorc/manifests/__init__.py +0 -0
  137. jaseci/jsorc/manifests/database.yaml +0 -109
  138. jaseci/jsorc/manifests/elastic.yaml +0 -6024
  139. jaseci/jsorc/manifests/prometheus.yaml +0 -1383
  140. jaseci/jsorc/manifests/redis.yaml +0 -64
  141. jaseci/jsorc/memory.py +0 -258
  142. jaseci/jsorc/redis.py +0 -139
  143. jaseci/jsorc/remote_actions.py +0 -157
  144. jaseci/jsorc/tests/__init__.py +0 -0
  145. jaseci/jsorc/tests/test_actions.py +0 -542
  146. jaseci/jsorc/tests/test_jsorc.py +0 -112
  147. jaseci/prim/__init__.py +0 -0
  148. jaseci/prim/ability.py +0 -93
  149. jaseci/prim/architype.py +0 -89
  150. jaseci/prim/edge.py +0 -172
  151. jaseci/prim/element.py +0 -233
  152. jaseci/prim/graph.py +0 -26
  153. jaseci/prim/master.py +0 -64
  154. jaseci/prim/node.py +0 -532
  155. jaseci/prim/obj_mixins.py +0 -235
  156. jaseci/prim/sentinel.py +0 -281
  157. jaseci/prim/super_master.py +0 -31
  158. jaseci/prim/walker.py +0 -261
  159. jaseci/svc/__init__.py +0 -0
  160. jaseci/tests/__init__.py +0 -0
  161. jaseci/tests/infer.py +0 -39
  162. jaseci/tests/jac_test_code.py +0 -1293
  163. jaseci/tests/jac_test_progs.py +0 -774
  164. jaseci/tests/test_core.py +0 -153
  165. jaseci/tests/test_jac.py +0 -824
  166. jaseci/tests/test_node.py +0 -89
  167. jaseci/tests/test_progs.py +0 -702
  168. jaseci/tests/test_stack.py +0 -220
  169. jaseci/tests/test_stripe.py +0 -225
  170. jaseci/utils/__init__.py +0 -0
  171. jaseci/utils/actions/__init__.py +0 -0
  172. jaseci/utils/actions/actions_manager.py +0 -254
  173. jaseci/utils/actions/actions_optimizer.py +0 -516
  174. jaseci/utils/actions/actions_state.py +0 -95
  175. jaseci/utils/file_handler.py +0 -171
  176. jaseci/utils/gprof2dot.py +0 -3786
  177. jaseci/utils/id_list.py +0 -168
  178. jaseci/utils/json_handler.py +0 -70
  179. jaseci/utils/log_utils.py +0 -57
  180. jaseci/utils/test_core.py +0 -62
  181. jaseci/utils/utils.py +0 -387
  182. jaseci-1.4.2.5.dist-info/LICENSE +0 -21
  183. jaseci-1.4.2.5.dist-info/METADATA +0 -39
  184. jaseci-1.4.2.5.dist-info/RECORD +0 -184
  185. jaseci-1.4.2.5.dist-info/entry_points.txt +0 -3
  186. jaseci-1.4.2.5.dist-info/top_level.txt +0 -1
@@ -1,36 +0,0 @@
1
- from jaseci.utils.test_core import CoreTest
2
-
3
-
4
- class StdLibTest(CoreTest):
5
- fixture_src = __file__
6
-
7
- def test_clear_report(self):
8
- ret = self.call(
9
- self.mast,
10
- ["sentinel_register", {"code": self.load_jac("general.jac")}],
11
- )
12
- ret = self.call(self.mast, ["walker_run", {"name": "report_clearing"}])
13
- self.assertEqual(len(ret["report"]), 1)
14
- self.assertEqual(ret["report"][0], 7)
15
-
16
- def test_internal_lib(self):
17
- ret = self.call(
18
- self.mast,
19
- ["sentinel_register", {"code": self.load_jac("general.jac")}],
20
- )
21
- ret = self.call(self.mast, ["walker_run", {"name": "internal_lib"}])
22
- self.assertEqual(len(ret["report"]), 1)
23
- self.assertTrue(
24
- ret["report"][0]["calls"].startswith(
25
- "ncalls,tottime,percall,cumtime,percall,"
26
- )
27
- )
28
-
29
- def test_rand_float_round(self):
30
- ret = self.call(
31
- self.mast,
32
- ["sentinel_register", {"code": self.load_jac("general.jac")}],
33
- )
34
- ret = self.call(self.mast, ["walker_run", {"name": "rand_float_round"}])
35
- self.assertEqual(ret["report"][0], 2.313)
36
- self.assertEqual(ret["report"][1], 2.847)
@@ -1,32 +0,0 @@
1
- from jaseci.utils.test_core import CoreTest, jac_testcase
2
-
3
-
4
- class UrlTest(CoreTest):
5
- fixture_src = __file__
6
-
7
- @jac_testcase("url.jac", "is_valid_test")
8
- def test_is_valid(self, ret):
9
- self.assertEqual(
10
- ret["report"],
11
- [True, False, False],
12
- )
13
-
14
- @jac_testcase("url.jac", "ping_test")
15
- def test_ping(self, ret):
16
- self.assertEqual(
17
- ret["report"],
18
- [True, False, False, False],
19
- )
20
-
21
- @jac_testcase("url.jac", "download_text_test")
22
- def test_download_text(self, ret):
23
- # Download the jaseci homepage as a test
24
- self.assertGreater(abs(len(ret["report"][0])), 0)
25
-
26
- @jac_testcase("url.jac", "download_b64_test")
27
- def test_download_b64(self, ret):
28
- # Jaseci white paper is 2,034,680 bytes in base64
29
- self.assertEqual(
30
- len(ret["report"][0]),
31
- 2034680,
32
- )
@@ -1,36 +0,0 @@
1
- from jaseci.utils.test_core import CoreTest, jac_testcase
2
-
3
-
4
- class VectorTest(CoreTest):
5
- """UnitTest for Vector Module"""
6
-
7
- fixture_src = __file__
8
-
9
- @jac_testcase("vector.jac", "get_centroid_test")
10
- def test_get_centroid(self, ret):
11
- ret = [ret["report"][0][0], round(ret["report"][0][1], 3)]
12
- self.assertEqual(ret, [[1.0, 2.0, 3.5], 0.998])
13
-
14
- @jac_testcase("vector.jac", "softmax_test")
15
- def test_softmax(self, ret):
16
- ret = [round(num, 2) for num in ret["report"][0]]
17
- self.assertEqual(ret, [0.09, 0.24, 0.67])
18
-
19
- @jac_testcase("vector.jac", "dot_product_test")
20
- def test_dot_product(self, ret):
21
- self.assertEqual(ret["report"][0], 17)
22
-
23
- @jac_testcase("vector.jac", "cosine_similarity_test")
24
- def test_cosine_similarity_single(self, ret):
25
- ret = round(ret["report"][0], 3)
26
- self.assertEqual(ret, 0.991)
27
-
28
- @jac_testcase("vector.jac", "cosine_similarity_batch_test")
29
- def test_cosine_similarity_batch(self, ret):
30
- ret = [round(num, 2) for num in ret["report"][0]]
31
- self.assertEqual(ret, [0.99, 1.0])
32
-
33
- @jac_testcase("vector.jac", "dimensionality_reduction_test")
34
- def test_dimensionality_reduction(self, ret):
35
- ret = len(ret["report"][0][0])
36
- self.assertEqual(ret, 2)
@@ -1,44 +0,0 @@
1
- from jaseci.utils.test_core import CoreTest, jac_testcase
2
-
3
-
4
- class WebtoolTest(CoreTest):
5
- """UnitTest for Webtool"""
6
-
7
- fixture_src = __file__
8
-
9
- @jac_testcase("webtool.jac", "get_meta_valid")
10
- def test_get_meta_valid(self, ret):
11
- self.assertTrue(ret["success"])
12
- expected_tags = set(["og:image", "og:type", "og:title"])
13
- tags = set(
14
- [
15
- meta["property"] if "property" in meta else ""
16
- for meta in ret["report"][0]
17
- ]
18
- )
19
- self.assertTrue(tags.issuperset(expected_tags))
20
-
21
- @jac_testcase("webtool.jac", "get_meta_need_auth")
22
- def test_get_meta_need_auth(self, ret):
23
- self.assertTrue(ret["success"])
24
- self.assertTrue(len(ret["report"][0]) > 0)
25
-
26
- @jac_testcase("webtool.jac", "get_meta_invalid")
27
- def test_get_meta_invalid(self, ret):
28
- self.assertTrue("Failed at getting metadata" in ret["report"][0])
29
-
30
- @jac_testcase("webtool.jac", "get_meta_timeout")
31
- def test_get_meta_timeout(self, ret):
32
- self.assertTrue("Failed at getting metadata" in ret["report"][0])
33
-
34
- @jac_testcase("webtool.jac", "get_meta_need_header")
35
- def test_get_meta_need_header(self, ret):
36
- self.assertTrue(ret["success"])
37
- expected_tags = set(["og:image", "og:type", "og:title"])
38
- tags = set(
39
- [
40
- meta["property"] if "property" in meta else ""
41
- for meta in ret["report"][0]
42
- ]
43
- )
44
- self.assertTrue(tags.issuperset(expected_tags))
@@ -1,24 +0,0 @@
1
- from jaseci.utils.test_core import CoreTest, jac_testcase
2
-
3
-
4
- class ZlibTest(CoreTest):
5
- fixture_src = __file__
6
-
7
- data_uncompressed = "iVBORw0KGgoAAAANSUhEUgAAAAgAAAAIAQMAAAD+wSzIAAAABlBMVEX///+/v7+jQ3Y5AAAADklEQVQI12P4AIX8EAgALgAD/aNpbtEAAAAASUVORK5CYII="
8
- data_compressed = "eJzrDPBz5+WS4mJgYOD19HAJAtIcIMzIDCT/HdQ5AaTYAnxCXP///79///7FzmWWQBE+TxfHEI7ryT8YWv8IcDDoMTD/XZyZdxEow+Dp6ueyzimhCQDLCRkd"
9
-
10
- @jac_testcase("zlib.jac", "compress_test", True)
11
- def test_compress(self, ret):
12
- print(ret["report"])
13
- self.assertEqual(
14
- ret["report"][0],
15
- self.data_compressed,
16
- )
17
-
18
- @jac_testcase("zlib.jac", "decompress_test")
19
- def test_decompress(self, ret):
20
- print(ret["report"])
21
- self.assertEqual(
22
- ret["report"][0],
23
- self.data_uncompressed,
24
- )
@@ -1,79 +0,0 @@
1
- """Built in actions for Jaseci"""
2
- from jaseci.jsorc.live_actions import jaseci_action
3
- from fastapi import HTTPException
4
- import base64
5
- import requests
6
- import urllib
7
- import validators
8
-
9
-
10
- @jaseci_action()
11
- def is_valid(url: str = ""):
12
- """
13
- Checks that a string is a valid url in its format
14
- Param 1 - url string
15
-
16
- Return - True if valid, False if not
17
- """
18
- try:
19
- url_response = validators.url(url)
20
- if isinstance(url_response, validators.ValidationError):
21
- return False
22
- except:
23
- return False
24
-
25
- return True
26
-
27
-
28
- @jaseci_action()
29
- def ping(url: str = ""):
30
- """
31
- Make sure that a url returns an error code in the 200s when pinged upon success
32
- Param 1 - url string
33
-
34
- Return - True if error code is in 200s, False if not
35
- """
36
- try:
37
- response = requests.get(url)
38
- except:
39
- return False
40
-
41
- return response.status_code in range(200, 299)
42
-
43
-
44
- @jaseci_action()
45
- def download_text(url: str = ""):
46
- """
47
- Downloaded html from a url
48
- Param 1 - url string
49
-
50
- Return - string containing html
51
- """
52
- try:
53
- response = urllib.request.urlopen(url)
54
- except:
55
- raise HTTPException(status_code=404, detail="Invalid URL")
56
-
57
- html_bytes = response.read()
58
- html_str = html_bytes.decode("UTF-8")
59
- print(len(html_str))
60
- return html_str
61
-
62
-
63
- @jaseci_action()
64
- def download_b64(url: str = ""):
65
- """
66
- Downlaod the get response from a url and return it in base64
67
- Param 1 - url string
68
-
69
- Return - base64 string representing the get response
70
- """
71
- try:
72
- response = requests.get(url)
73
- except:
74
- raise HTTPException(status_code=404, detail="Invalid URL")
75
-
76
- response_bytes = response.content
77
- response_b64_bytes = base64.b64encode(response_bytes)
78
- response_b64 = response_b64_bytes.decode("ascii")
79
- return response_b64
@@ -1,157 +0,0 @@
1
- """Built in actions for Jaseci"""
2
- import numpy as np
3
- from operator import itemgetter
4
- import pickle, base64
5
-
6
- from jaseci.jsorc.live_actions import jaseci_action
7
-
8
-
9
- def check_nested_list(lst):
10
- return all(isinstance(el, list) for el in lst)
11
-
12
-
13
- @jaseci_action(aliases=["cos_sim"])
14
- def cosine_sim(vec_a: list, vec_b: list):
15
- """
16
- Caculate the cosine similarity score of two given vectors
17
- Param 1 - First vector
18
- Param 2 - Second vector
19
-
20
- Return - float between 0 and 1
21
- """
22
- vec_a_nested = check_nested_list(vec_a)
23
- vec_b_nested = check_nested_list(vec_b)
24
- if vec_a_nested or vec_b_nested:
25
- vec_a_np = np.array(vec_a) if vec_a_nested else np.array([vec_a] * len(vec_b))
26
- vec_b_np = np.array(vec_b) if vec_b_nested else np.array([vec_b] * len(vec_a))
27
- sim = np.dot(vec_a_np, vec_b_np.T) / (
28
- np.linalg.norm(vec_a_np, axis=1)[:, None] * np.linalg.norm(vec_b_np, axis=1)
29
- )
30
- return sim.diagonal().tolist()
31
-
32
- result = np.dot(vec_a, vec_b) / (np.linalg.norm(vec_a) * np.linalg.norm(vec_b))
33
- return float(result.astype(float))
34
-
35
-
36
- @jaseci_action()
37
- def dot_product(vec_a: list, vec_b: list):
38
- """
39
- Caculate the dot product of two given vectors
40
- Param 1 - First vector
41
- Param 2 - Second vector
42
-
43
- Return - float between 0 and 1
44
- """
45
-
46
- return np.inner(vec_a, vec_b).tolist()
47
-
48
-
49
- @jaseci_action()
50
- def get_centroid(vec_list: list):
51
- """
52
- Calculate the centroid of the given list of vectors
53
- Param 1 - List of vectors
54
-
55
- Return - (centroid vector, cluster tightness)
56
- """
57
- centroid = np.mean(vec_list, axis=0)
58
- tightness = np.mean([cosine_sim(vec, centroid) for vec in vec_list]).astype(float)
59
- return [centroid.tolist(), tightness]
60
-
61
-
62
- @jaseci_action()
63
- def softmax(vec_list: list):
64
- """
65
- Calculate the centroid of the given list of vectors
66
- Param 1 - List of vectors
67
-
68
- Return - (centroid vector, cluster tightness)
69
- """
70
- e_x = np.exp(vec_list - np.max(vec_list))
71
- return list(e_x / e_x.sum())
72
-
73
-
74
- @jaseci_action()
75
- def sort_by_key(data: dict, reverse=False, key_pos=None):
76
- """
77
- Sort the given list. Optionally by specific key
78
- Param 1 - List of items
79
- Param 2 - if Reverse
80
- Param 3 (Optional) - Index of the key to be used for sorting
81
- if param 1 is a list of tuples.
82
-
83
- Deprecated
84
- """
85
- if key_pos is not None:
86
- return sorted(data, key=itemgetter(key_pos), reverse=reverse)
87
- else:
88
- return sorted(data, reverse=reverse)
89
-
90
-
91
- @jaseci_action()
92
- def dim_reduce_fit(data: list, dim=2):
93
- """
94
- Dimensionally reduce a list of vectors using incremental PCA
95
- Param 1 - List of vectors
96
- Param 2 - Dimension to reduce to
97
-
98
- Return - base64 encoded string of the model
99
- """
100
- data_arr = np.array(data)
101
- ipca = IncrementalPCA(n_components=dim)
102
- ipca = ipca.fit(data_arr)
103
- return base64.b64encode(pickle.dumps(ipca)).decode("utf-8")
104
-
105
-
106
- @jaseci_action()
107
- def dim_reduce_apply(data: list, model: str):
108
- """
109
- Dimensionally reduce a list of vectors using incremental PCA
110
- Param 1 - List of vectors
111
- Param 2 - base64 encoded string of the model
112
-
113
- Return - List of reduced vectors
114
- """
115
- data_arr = np.array(data)
116
- # reshaping the data if it is a single vector
117
- if len(data_arr.shape) == 1:
118
- data_arr = data_arr.reshape(1, -1)
119
- ipca = pickle.loads(base64.b64decode(model))
120
- return ipca.transform(data_arr).tolist()
121
-
122
-
123
- class IncrementalPCA:
124
- def __init__(self, n_components):
125
- self.n_components = n_components
126
- self.mean_ = None
127
- self.components_ = None
128
- self.n_samples_seen_ = 0
129
-
130
- def fit(self, X):
131
- if self.mean_ is None:
132
- self.mean_ = np.zeros(X.shape[1], dtype=np.float64)
133
- if self.components_ is None:
134
- self.components_ = np.zeros(
135
- (self.n_components, X.shape[1]), dtype=np.float64
136
- )
137
-
138
- # update mean
139
- col_mean = np.mean(X, axis=0)
140
- total_n_samples = self.n_samples_seen_ + X.shape[0]
141
- self.mean_ = (
142
- self.n_samples_seen_ * self.mean_ + X.shape[0] * col_mean
143
- ) / total_n_samples
144
-
145
- # update components
146
- X_centered = X - self.mean_
147
- U, S, V = np.linalg.svd(X_centered, full_matrices=False)
148
- explained_variance = S**2 / (X.shape[0] - 1)
149
- explained_variance_ratio = explained_variance / np.sum(explained_variance)
150
- self.components_ = V[: self.n_components]
151
- self.n_samples_seen_ = total_n_samples
152
-
153
- return self
154
-
155
- def transform(self, X):
156
- X_centered = X - self.mean_
157
- return np.dot(X_centered, self.components_.T)
@@ -1,28 +0,0 @@
1
- """Built in actions for Jaseci"""
2
- import requests
3
- from jaseci.jsorc.live_actions import jaseci_action
4
- from bs4 import BeautifulSoup
5
-
6
-
7
- @jaseci_action()
8
- def get_page_meta(url: str, timeout: int = 3, parser: str = "lxml", headers: dict = {}):
9
- """
10
- Util to parse metadata out of urls and html documents
11
- Parser option: lxml (default), html5lib, html.parser
12
- Comparison between parsers: https://www.crummy.com/software/BeautifulSoup/bs4/doc/#installing-a-parser
13
- """
14
- try:
15
- webpage = requests.get(
16
- url,
17
- timeout=timeout,
18
- headers=headers,
19
- )
20
- soup = BeautifulSoup(webpage.content, features=parser)
21
- meta = soup.find_all("meta")
22
- meta_list = []
23
- for tag in meta:
24
- meta_list.append(dict(tag.attrs))
25
- return meta_list
26
- except Exception as e:
27
- print("Failed")
28
- return f"Failed at getting metadata for {url}: {str(e)}"
@@ -1,33 +0,0 @@
1
- """Built in actions for Jaseci"""
2
- from jaseci.jsorc.live_actions import jaseci_action
3
- from jaseci.utils.utils import print_stack_to_log
4
- from base64 import b64decode, b64encode
5
- import zlib
6
-
7
-
8
- @jaseci_action()
9
- def compress(data_b64: str = ""):
10
- """
11
- Compress data
12
- Param 1 - data in base64
13
-
14
- Return - compressed data in base64
15
- """
16
- data_bytes = b64decode(data_b64.encode("ascii"))
17
- data_compressed_bytes = zlib.compress(data_bytes)
18
- data_compressed_b64 = b64encode(data_compressed_bytes).decode("ascii")
19
- return data_compressed_b64
20
-
21
-
22
- @jaseci_action()
23
- def decompress(data_b64: str = ""):
24
- """
25
- Decompress data
26
- Param 1 - data in base64
27
-
28
- Return - decompressed data in base64
29
- """
30
- data_bytes = b64decode(data_b64.encode("ascii"))
31
- data_decompressed_bytes = zlib.decompress(data_bytes)
32
- data_decompressed_b64 = b64encode(data_decompressed_bytes).decode("ascii")
33
- return data_decompressed_b64
File without changes
@@ -1,170 +0,0 @@
1
- """
2
- Admin Global api functions as a mixin
3
- """
4
- from jaseci.extens.api.interface import Interface
5
- import jaseci.jsorc.live_actions as lact
6
- import json
7
-
8
-
9
- class ActionsApi:
10
- """
11
- APIs to manage actions
12
-
13
- This set action APIs enable the manual management of Jaseci actions and action
14
- libraries/sets. Action libraries can be loaded locally into the running instance of
15
- the python program, or as a remote container linked action library. In this mode,
16
- action libraries operate as micro-services. Jaseci will be able to dynamically
17
- and automatically make this decision for the user based on online monitoring and
18
- performance profiling.
19
- """
20
-
21
- @Interface.admin_api(cli_args=["file"])
22
- def actions_load_local(self, file: str, ctx: dict = {}):
23
- """
24
- Hot load a python module and assimilate any Jaseci Actions
25
-
26
- This API will dynamically load a module based on a python file. The module
27
- is loaded directly into the running Jaseci python instance. This API also
28
- makes an attempt to auto detect and hot load any python package dependencies
29
- the file may reference via python's relative imports. This file is assumed to
30
- have the necessary annotations and decorations required by Jaseci to recognize
31
- its actions.
32
-
33
- :param file: The python file with full to load actions from.
34
- (i.e., ~/local/myact.py)
35
- """
36
- success = lact.load_local_actions(file, ctx=ctx)
37
- if success:
38
- cur_config = self.config_get("ACTION_SETS")
39
- if cur_config and (not isinstance(cur_config, list)):
40
- config = json.loads(cur_config)
41
- if file not in config["local"]:
42
- config["local"].append(file)
43
- self.config_set("ACTION_SETS", json.dumps(config))
44
- else:
45
- self.config_set(
46
- "ACTION_SETS",
47
- json.dumps({"local": [file], "remote": [], "module": []}),
48
- )
49
- return {"success": success}
50
-
51
- @Interface.admin_api(cli_args=["url"])
52
- def actions_load_remote(self, url: str, ctx: dict = {}):
53
- """
54
- Hot link to a container linked action library
55
-
56
- This API will dynamically load a set of actions that are present on a remote
57
- server/micro-service. This server must be configured to interact with Jaseci
58
- properly. This is easily achieved using the same decorators used for local
59
- action libraries. Remote actions allow for higher flexibility in the languages
60
- supported for action libraries. If an library writer would like to use another
61
- language, the main hook REST api simply needs to be implemented. Please
62
- refer to documentation on creating action libraries for more details.
63
-
64
- :param url: The url of the API server supporting Jaseci actions.
65
- """
66
- success = lact.load_remote_actions(url, ctx=ctx)
67
- if success:
68
- cur_config = self.config_get("ACTION_SETS")
69
- if cur_config and (not isinstance(cur_config, list)):
70
- config = json.loads(cur_config)
71
- if url not in config["remote"]:
72
- config["remote"].append(url)
73
- self.config_set("ACTION_SETS", json.dumps(config))
74
- else:
75
- self.config_set(
76
- "ACTION_SETS",
77
- json.dumps({"local": [], "remote": [url], "module": []}),
78
- )
79
- return {"success": success}
80
-
81
- @Interface.admin_api(cli_args=["mod"])
82
- def actions_load_module(self, mod: str, ctx: dict = {}):
83
- """
84
- Hot load a python module and assimilate any Jaseci Actions
85
-
86
- This API will dynamically load a module using python's module import format.
87
- This is particularly useful for pip installed action libraries as the developer
88
- can directly reference the module using the same format as a regular python
89
- import. As with load local, the module will be loaded directly into the running
90
- Jaseci python instance.
91
-
92
- :param mod: The import style module to load actions from.
93
- (i.e., jaseci_ai_kit.bi_enc)
94
- """
95
- success = lact.load_module_actions(mod, ctx=ctx)
96
- if success:
97
- cur_config = self.config_get("ACTION_SETS")
98
- if cur_config and (not isinstance(cur_config, list)):
99
- config = json.loads(cur_config)
100
- if mod not in config["module"]:
101
- config["module"].append(mod)
102
- self.config_set("ACTION_SETS", json.dumps(config))
103
- else:
104
- self.config_set(
105
- "ACTION_SETS",
106
- json.dumps({"local": [], "remote": [], "module": [mod]}),
107
- )
108
- return {"success": success}
109
-
110
- # @interface.admin_api()
111
- # def actions_get(self, name: str, value: str):
112
- # """
113
- # """
114
-
115
- @Interface.admin_api()
116
- def actions_list(self, name: str = ""):
117
- """
118
- List a set of or all loaded jaseci actions
119
-
120
- This API is used to list the loaded actions active in Jaseci. These actions
121
- include all types of loaded actions whether it be local modules or remote
122
- containers. A particular set of actions can be viewed using the name parameter.
123
-
124
- :param name: The name for a library for which to filter the view of shown
125
- actions. If left blank all actions from all loaded sets will be shown.
126
- """
127
- actions = list(lact.live_actions.keys())
128
- if len(name):
129
- actions = list(filter(lambda a: a.startswith(name), actions))
130
- return actions
131
-
132
- @Interface.admin_api()
133
- def actions_module_list(self, detailed: bool = False):
134
- """
135
- List all modules loaded for actions
136
- """
137
- if not detailed:
138
- action_mods = list(lact.live_action_modules.keys())
139
- else:
140
- action_mods = lact.live_action_modules
141
- return action_mods
142
-
143
- @Interface.admin_api(cli_args=["name"])
144
- def actions_unload_module(self, name: str):
145
- """
146
- Unload modules loaded for actions
147
- """
148
- return {"success": lact.unload_module(name)}
149
-
150
- @Interface.admin_api(cli_args=["name"])
151
- def actions_unload_action(self, name: str):
152
- """
153
- Unload modules loaded for actions
154
- """
155
- return {"success": lact.unload_action(name)}
156
-
157
- @Interface.admin_api(cli_args=["name"])
158
- def actions_unload_actionset(self, name: str):
159
- """
160
- Unload modules loaded for actions
161
- """
162
- return {"success": lact.unload_actionset(name)}
163
-
164
- @Interface.admin_api(cli_args=["name"])
165
- def actions_call(self, name: str, ctx: dict = {}):
166
- """
167
- Call an action by name
168
- """
169
- ret, sucess = lact.call_action(name, ctx=ctx)
170
- return {"success": sucess, "result": ret}