symbolicai 0.18.3__py3-none-any.whl → 0.19.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.
- symai/__init__.py +1 -1
- symai/backend/engines/files/engine_io.py +36 -4
- symai/components.py +18 -0
- symai/context.py +4 -0
- symai/functional.py +27 -19
- {symbolicai-0.18.3.dist-info → symbolicai-0.19.0.dist-info}/METADATA +1 -1
- {symbolicai-0.18.3.dist-info → symbolicai-0.19.0.dist-info}/RECORD +10 -9
- {symbolicai-0.18.3.dist-info → symbolicai-0.19.0.dist-info}/WHEEL +0 -0
- {symbolicai-0.18.3.dist-info → symbolicai-0.19.0.dist-info}/entry_points.txt +0 -0
- {symbolicai-0.18.3.dist-info → symbolicai-0.19.0.dist-info}/top_level.txt +0 -0
symai/__init__.py
CHANGED
|
@@ -9,10 +9,19 @@ from tika import unpack
|
|
|
9
9
|
|
|
10
10
|
from ...base import Engine
|
|
11
11
|
|
|
12
|
-
#
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
# Initialize Tika lazily to avoid spawning JVMs prematurely for all workers
|
|
13
|
+
_TIKA_INITIALIZED = False
|
|
14
|
+
|
|
15
|
+
def _ensure_tika_vm():
|
|
16
|
+
global _TIKA_INITIALIZED
|
|
17
|
+
if not _TIKA_INITIALIZED:
|
|
18
|
+
try:
|
|
19
|
+
tika.initVM()
|
|
20
|
+
except Exception:
|
|
21
|
+
# If initVM fails, we still attempt unpack.from_file which may auto-init
|
|
22
|
+
pass
|
|
23
|
+
logging.getLogger('tika').setLevel(logging.CRITICAL)
|
|
24
|
+
_TIKA_INITIALIZED = True
|
|
16
25
|
|
|
17
26
|
|
|
18
27
|
@dataclass
|
|
@@ -69,6 +78,29 @@ class FileEngine(Engine):
|
|
|
69
78
|
if os.path.getsize(file_path) <= 0:
|
|
70
79
|
return ''
|
|
71
80
|
|
|
81
|
+
# For common plain-text extensions, avoid Tika overhead
|
|
82
|
+
ext = Path(file_path).suffix.lower()
|
|
83
|
+
if ext in {'.txt', '.md', '.py', '.json', '.yaml', '.yml', '.csv', '.tsv', '.log'}:
|
|
84
|
+
try:
|
|
85
|
+
with open(file_path, 'r', encoding='utf-8', errors='ignore') as f:
|
|
86
|
+
content = f.read()
|
|
87
|
+
if content is None:
|
|
88
|
+
return None
|
|
89
|
+
# Apply slicing by lines, mirroring the Tika branch
|
|
90
|
+
lines = content.split('\n')
|
|
91
|
+
if slices_ is not None:
|
|
92
|
+
new_content = []
|
|
93
|
+
for s in slices_:
|
|
94
|
+
new_content.extend(lines[s])
|
|
95
|
+
lines = new_content
|
|
96
|
+
content = '\n'.join(lines)
|
|
97
|
+
content = content.encode('utf8', 'ignore').decode('utf8', 'ignore')
|
|
98
|
+
return content if not with_metadata else [TextContainer(id, None, content)]
|
|
99
|
+
except Exception:
|
|
100
|
+
# Fallback to Tika if plain read fails
|
|
101
|
+
pass
|
|
102
|
+
|
|
103
|
+
_ensure_tika_vm()
|
|
72
104
|
file_ = unpack.from_file(str(file_path))
|
|
73
105
|
if 'content' in file_:
|
|
74
106
|
content = file_['content']
|
symai/components.py
CHANGED
|
@@ -10,6 +10,7 @@ from pathlib import Path
|
|
|
10
10
|
from random import sample
|
|
11
11
|
from string import ascii_lowercase, ascii_uppercase
|
|
12
12
|
from threading import Lock
|
|
13
|
+
from .context import CURRENT_ENGINE_VAR
|
|
13
14
|
from typing import Callable, Dict, Iterator, List, Optional, Type, Union
|
|
14
15
|
|
|
15
16
|
import numpy as np
|
|
@@ -1256,6 +1257,7 @@ class DynamicEngine(Expression):
|
|
|
1256
1257
|
self._entered = False
|
|
1257
1258
|
self._lock = Lock()
|
|
1258
1259
|
self.engine_instance = None
|
|
1260
|
+
self._ctx_token = None
|
|
1259
1261
|
|
|
1260
1262
|
def __new__(cls, *args, **kwargs):
|
|
1261
1263
|
cls._lock = getattr(cls, '_lock', Lock())
|
|
@@ -1268,10 +1270,26 @@ class DynamicEngine(Expression):
|
|
|
1268
1270
|
def __enter__(self):
|
|
1269
1271
|
self._entered = True
|
|
1270
1272
|
self.engine_instance = self._create_engine_instance()
|
|
1273
|
+
# Set ContextVar and keep the token for proper reset
|
|
1274
|
+
try:
|
|
1275
|
+
self._ctx_token = CURRENT_ENGINE_VAR.set(self.engine_instance)
|
|
1276
|
+
except Exception:
|
|
1277
|
+
self._ctx_token = None
|
|
1271
1278
|
return self.engine_instance
|
|
1272
1279
|
|
|
1273
1280
|
def __exit__(self, exc_type, exc_value, traceback):
|
|
1274
1281
|
self._entered = False
|
|
1282
|
+
# Reset ContextVar back to previous value
|
|
1283
|
+
try:
|
|
1284
|
+
if self._ctx_token is not None:
|
|
1285
|
+
try:
|
|
1286
|
+
CURRENT_ENGINE_VAR.reset(self._ctx_token)
|
|
1287
|
+
except ValueError:
|
|
1288
|
+
# Token belongs to a different logical Context (e.g., run in anyio worker)
|
|
1289
|
+
# Fallback: clear the var in this Context to avoid leaking the engine
|
|
1290
|
+
CURRENT_ENGINE_VAR.set(None)
|
|
1291
|
+
finally:
|
|
1292
|
+
self._ctx_token = None
|
|
1275
1293
|
|
|
1276
1294
|
def _create_engine_instance(self):
|
|
1277
1295
|
"""Create an engine instance based on the model name."""
|
symai/context.py
ADDED
symai/functional.py
CHANGED
|
@@ -20,6 +20,7 @@ from .backend.base import ENGINE_UNREGISTERED, Engine
|
|
|
20
20
|
from .post_processors import PostProcessor
|
|
21
21
|
from .pre_processors import PreProcessor
|
|
22
22
|
from .utils import CustomUserWarning
|
|
23
|
+
from .context import CURRENT_ENGINE_VAR
|
|
23
24
|
|
|
24
25
|
|
|
25
26
|
class ConstraintViolationException(Exception):
|
|
@@ -416,24 +417,31 @@ class EngineRepository(object):
|
|
|
416
417
|
raise ValueError(f"No engine named {engine} is registered.")
|
|
417
418
|
|
|
418
419
|
def get_dynamic_engine_instance(self):
|
|
419
|
-
|
|
420
|
+
# 1) Primary: use ContextVar (fast, async-safe)
|
|
421
|
+
try:
|
|
422
|
+
eng = CURRENT_ENGINE_VAR.get()
|
|
423
|
+
if eng is not None:
|
|
424
|
+
return eng
|
|
425
|
+
except Exception:
|
|
426
|
+
pass
|
|
420
427
|
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
428
|
+
# 2) Fallback: walk ONLY current thread frames (legacy behavior)
|
|
429
|
+
from .components import DynamicEngine
|
|
430
|
+
try:
|
|
431
|
+
frame = sys._getframe()
|
|
432
|
+
except Exception:
|
|
433
|
+
return None
|
|
434
|
+
while frame:
|
|
435
|
+
try:
|
|
436
|
+
locals_copy = frame.f_locals.copy() if hasattr(frame.f_locals, 'copy') else dict(frame.f_locals)
|
|
437
|
+
except Exception:
|
|
438
|
+
CustomUserWarning(
|
|
439
|
+
"Unexpected failure copying frame locals while resolving DynamicEngine.",
|
|
440
|
+
raise_with=None,
|
|
441
|
+
)
|
|
442
|
+
locals_copy = {}
|
|
443
|
+
for value in locals_copy.values():
|
|
444
|
+
if isinstance(value, DynamicEngine) and getattr(value, '_entered', False):
|
|
445
|
+
return value.engine_instance
|
|
446
|
+
frame = frame.f_back
|
|
439
447
|
return None
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: symbolicai
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.19.0
|
|
4
4
|
Summary: A Neurosymbolic Perspective on Large Language Models
|
|
5
5
|
Author-email: Marius-Constantin Dinu <marius@extensity.ai>, Leoveanu-Condrei Claudiu <leo@extensity.ai>
|
|
6
6
|
Project-URL: Homepage, https://extensity.ai
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
symai/TERMS_OF_SERVICE.md,sha256=HN42UXVI_wAVDHjMShzy_k7xAsbjXaATNeMKcIte_eg,91409
|
|
2
|
-
symai/__init__.py,sha256=
|
|
2
|
+
symai/__init__.py,sha256=9wwYTYS8BnMTNUcn30fgdTbhwDSZU8uF2Aif4zl0ycE,16464
|
|
3
3
|
symai/chat.py,sha256=vqEe7NqSWdzr9ixkko_094SR1LIbgPLcZxQ8W7782N4,12775
|
|
4
|
-
symai/components.py,sha256=
|
|
4
|
+
symai/components.py,sha256=vgIq-cC8rqZG9PAPUB52Y5RGFEKrxFUCWzqzrPzLNvw,52232
|
|
5
5
|
symai/constraints.py,sha256=S1ywLB8nFQy4-beDoJz6IvLTiZHGR8Fu5RNTY4v5zG0,1641
|
|
6
|
+
symai/context.py,sha256=4M69MJOeWSdPTr2Y9teoNTs-nEvpzcAcr7900UgORXA,189
|
|
6
7
|
symai/core.py,sha256=1g45AjJ5wkz1cNTbtoDbd8QlOUc-v-3sWNmDTxaeqY0,69041
|
|
7
8
|
symai/core_ext.py,sha256=binru2AjB8K-arbNLiu1wnNodtFxgqk26b-iLVhPoSU,9322
|
|
8
9
|
symai/exceptions.py,sha256=BxpxI8q3-7Uh_Kg9Xi2PhF6RR6CofxV1h8R07j4v47U,165
|
|
9
|
-
symai/functional.py,sha256=
|
|
10
|
+
symai/functional.py,sha256=ftuo3RB34Al4kMAaqAt9viOd84Tm1mH_svNUSLjnztU,18868
|
|
10
11
|
symai/imports.py,sha256=npVGz9portPb3enIUtLYiwtdhSPVz6ctHLPreS6Jtvo,16354
|
|
11
12
|
symai/interfaces.py,sha256=MwnRvd-0QrMc2t_MLv05ZZASeWEIgbWxadiVOGbPbOQ,2898
|
|
12
13
|
symai/memory.py,sha256=Svie0ozSMOElMzcyAGnShc3VOQYpkiCEN4ZLoc2ofHM,3674
|
|
@@ -36,7 +37,7 @@ symai/backend/engines/execute/engine_python.py,sha256=3rPMBcrCrjggVm7JtGQjAywBZ6
|
|
|
36
37
|
symai/backend/engines/experiments/engine_bard_wrapper.py,sha256=RTRLg5kAq1yKMkgNC8xj9kzOtkeoOANrXzHejKp2haM,5276
|
|
37
38
|
symai/backend/engines/experiments/engine_gptfinetuner.py,sha256=POQwYj_NKjOBLc83FM1S_WBqHudZyYlDENjNFak6ocY,804
|
|
38
39
|
symai/backend/engines/experiments/engine_llamacpp_completion.py,sha256=Wgq56wH9ZoV-FwdWfok90Yv48Zu4kXHMNDdzFe4mmjc,5268
|
|
39
|
-
symai/backend/engines/files/engine_io.py,sha256=
|
|
40
|
+
symai/backend/engines/files/engine_io.py,sha256=KuIUyv9gGecFRbhk0kakmkZRkeH5smPpEIvPzSS5Si0,7729
|
|
40
41
|
symai/backend/engines/imagecaptioning/engine_blip2.py,sha256=V0WQhAjQIsC_YLRVtDqU0oiBlaWxCNKKLJu95b08hxk,3115
|
|
41
42
|
symai/backend/engines/imagecaptioning/engine_llavacpp_client.py,sha256=ZbW6sxFE9DVzoWaxNsTJ2YXbIxl564t0QaN8sHNJQDc,6176
|
|
42
43
|
symai/backend/engines/index/engine_pinecone.py,sha256=Horf9lzw2QLMdYvvBLeAu3MOyiTbNo30en28Ifm4AVA,8956
|
|
@@ -153,8 +154,8 @@ symai/ops/primitives.py,sha256=EaB2Ekx9yGNDaQa3aKS5KpuEr5awAUbO3OcBbufI-l4,11072
|
|
|
153
154
|
symai/server/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
154
155
|
symai/server/huggingface_server.py,sha256=UpSBflnQaenDjY1AAn5LUYeg5J4gJLWiMuC5DcoIV3E,8743
|
|
155
156
|
symai/server/llama_cpp_server.py,sha256=qVCldTdcQhK2YCu7sDNSYziu1p2AQieqMFfY028-yOc,2049
|
|
156
|
-
symbolicai-0.
|
|
157
|
-
symbolicai-0.
|
|
158
|
-
symbolicai-0.
|
|
159
|
-
symbolicai-0.
|
|
160
|
-
symbolicai-0.
|
|
157
|
+
symbolicai-0.19.0.dist-info/METADATA,sha256=Bpe1zJQJp4xtgXx4u3qUQ1IrmxCtaqmaVfiTIjJJqL0,21327
|
|
158
|
+
symbolicai-0.19.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
159
|
+
symbolicai-0.19.0.dist-info/entry_points.txt,sha256=JV5sdydIfUZdDF6QBEQHiZHod6XNPjCjpWQrXh7gTAw,261
|
|
160
|
+
symbolicai-0.19.0.dist-info/top_level.txt,sha256=bOoIDfpDIvCQtQgXcwVKJvxAKwsxpxo2IL4z92rNJjw,6
|
|
161
|
+
symbolicai-0.19.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|