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