naas-abi-core 1.4.1__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.
- assets/favicon.ico +0 -0
- assets/logo.png +0 -0
- naas_abi_core/__init__.py +1 -0
- naas_abi_core/apps/api/api.py +245 -0
- naas_abi_core/apps/api/api_test.py +281 -0
- naas_abi_core/apps/api/openapi_doc.py +144 -0
- naas_abi_core/apps/mcp/Dockerfile.mcp +35 -0
- naas_abi_core/apps/mcp/mcp_server.py +243 -0
- naas_abi_core/apps/mcp/mcp_server_test.py +163 -0
- naas_abi_core/apps/terminal_agent/main.py +555 -0
- naas_abi_core/apps/terminal_agent/terminal_style.py +175 -0
- naas_abi_core/engine/Engine.py +87 -0
- naas_abi_core/engine/EngineProxy.py +109 -0
- naas_abi_core/engine/Engine_test.py +6 -0
- naas_abi_core/engine/IEngine.py +91 -0
- naas_abi_core/engine/conftest.py +45 -0
- naas_abi_core/engine/engine_configuration/EngineConfiguration.py +216 -0
- naas_abi_core/engine/engine_configuration/EngineConfiguration_Deploy.py +7 -0
- naas_abi_core/engine/engine_configuration/EngineConfiguration_GenericLoader.py +49 -0
- naas_abi_core/engine/engine_configuration/EngineConfiguration_ObjectStorageService.py +159 -0
- naas_abi_core/engine/engine_configuration/EngineConfiguration_ObjectStorageService_test.py +26 -0
- naas_abi_core/engine/engine_configuration/EngineConfiguration_SecretService.py +138 -0
- naas_abi_core/engine/engine_configuration/EngineConfiguration_SecretService_test.py +74 -0
- naas_abi_core/engine/engine_configuration/EngineConfiguration_TripleStoreService.py +224 -0
- naas_abi_core/engine/engine_configuration/EngineConfiguration_TripleStoreService_test.py +109 -0
- naas_abi_core/engine/engine_configuration/EngineConfiguration_VectorStoreService.py +76 -0
- naas_abi_core/engine/engine_configuration/EngineConfiguration_VectorStoreService_test.py +33 -0
- naas_abi_core/engine/engine_configuration/EngineConfiguration_test.py +9 -0
- naas_abi_core/engine/engine_configuration/utils/PydanticModelValidator.py +15 -0
- naas_abi_core/engine/engine_loaders/EngineModuleLoader.py +302 -0
- naas_abi_core/engine/engine_loaders/EngineOntologyLoader.py +16 -0
- naas_abi_core/engine/engine_loaders/EngineServiceLoader.py +47 -0
- naas_abi_core/integration/__init__.py +7 -0
- naas_abi_core/integration/integration.py +28 -0
- naas_abi_core/models/Model.py +198 -0
- naas_abi_core/models/OpenRouter.py +18 -0
- naas_abi_core/models/OpenRouter_test.py +36 -0
- naas_abi_core/module/Module.py +252 -0
- naas_abi_core/module/ModuleAgentLoader.py +50 -0
- naas_abi_core/module/ModuleUtils.py +20 -0
- naas_abi_core/modules/templatablesparqlquery/README.md +196 -0
- naas_abi_core/modules/templatablesparqlquery/__init__.py +39 -0
- naas_abi_core/modules/templatablesparqlquery/ontologies/TemplatableSparqlQueryOntology.ttl +116 -0
- naas_abi_core/modules/templatablesparqlquery/workflows/GenericWorkflow.py +48 -0
- naas_abi_core/modules/templatablesparqlquery/workflows/TemplatableSparqlQueryLoader.py +192 -0
- naas_abi_core/pipeline/__init__.py +6 -0
- naas_abi_core/pipeline/pipeline.py +70 -0
- naas_abi_core/services/__init__.py +0 -0
- naas_abi_core/services/agent/Agent.py +1619 -0
- naas_abi_core/services/agent/AgentMemory_test.py +28 -0
- naas_abi_core/services/agent/Agent_test.py +214 -0
- naas_abi_core/services/agent/IntentAgent.py +1179 -0
- naas_abi_core/services/agent/IntentAgent_test.py +139 -0
- naas_abi_core/services/agent/beta/Embeddings.py +181 -0
- naas_abi_core/services/agent/beta/IntentMapper.py +120 -0
- naas_abi_core/services/agent/beta/LocalModel.py +88 -0
- naas_abi_core/services/agent/beta/VectorStore.py +89 -0
- naas_abi_core/services/agent/test_agent_memory.py +278 -0
- naas_abi_core/services/agent/test_postgres_integration.py +145 -0
- naas_abi_core/services/cache/CacheFactory.py +31 -0
- naas_abi_core/services/cache/CachePort.py +63 -0
- naas_abi_core/services/cache/CacheService.py +246 -0
- naas_abi_core/services/cache/CacheService_test.py +85 -0
- naas_abi_core/services/cache/adapters/secondary/CacheFSAdapter.py +39 -0
- naas_abi_core/services/object_storage/ObjectStorageFactory.py +57 -0
- naas_abi_core/services/object_storage/ObjectStoragePort.py +47 -0
- naas_abi_core/services/object_storage/ObjectStorageService.py +41 -0
- naas_abi_core/services/object_storage/adapters/secondary/ObjectStorageSecondaryAdapterFS.py +52 -0
- naas_abi_core/services/object_storage/adapters/secondary/ObjectStorageSecondaryAdapterNaas.py +131 -0
- naas_abi_core/services/object_storage/adapters/secondary/ObjectStorageSecondaryAdapterS3.py +171 -0
- naas_abi_core/services/ontology/OntologyPorts.py +36 -0
- naas_abi_core/services/ontology/OntologyService.py +17 -0
- naas_abi_core/services/ontology/adaptors/secondary/OntologyService_SecondaryAdaptor_NERPort.py +37 -0
- naas_abi_core/services/secret/Secret.py +138 -0
- naas_abi_core/services/secret/SecretPorts.py +45 -0
- naas_abi_core/services/secret/Secret_test.py +65 -0
- naas_abi_core/services/secret/adaptors/secondary/Base64Secret.py +57 -0
- naas_abi_core/services/secret/adaptors/secondary/Base64Secret_test.py +39 -0
- naas_abi_core/services/secret/adaptors/secondary/NaasSecret.py +88 -0
- naas_abi_core/services/secret/adaptors/secondary/NaasSecret_test.py +25 -0
- naas_abi_core/services/secret/adaptors/secondary/dotenv_secret_secondaryadaptor.py +29 -0
- naas_abi_core/services/triple_store/TripleStoreFactory.py +116 -0
- naas_abi_core/services/triple_store/TripleStorePorts.py +223 -0
- naas_abi_core/services/triple_store/TripleStoreService.py +419 -0
- naas_abi_core/services/triple_store/adaptors/secondary/AWSNeptune.py +1300 -0
- naas_abi_core/services/triple_store/adaptors/secondary/AWSNeptune_test.py +284 -0
- naas_abi_core/services/triple_store/adaptors/secondary/Oxigraph.py +597 -0
- naas_abi_core/services/triple_store/adaptors/secondary/Oxigraph_test.py +1474 -0
- naas_abi_core/services/triple_store/adaptors/secondary/TripleStoreService__SecondaryAdaptor__Filesystem.py +223 -0
- naas_abi_core/services/triple_store/adaptors/secondary/TripleStoreService__SecondaryAdaptor__ObjectStorage.py +234 -0
- naas_abi_core/services/triple_store/adaptors/secondary/base/TripleStoreService__SecondaryAdaptor__FileBase.py +18 -0
- naas_abi_core/services/vector_store/IVectorStorePort.py +101 -0
- naas_abi_core/services/vector_store/IVectorStorePort_test.py +189 -0
- naas_abi_core/services/vector_store/VectorStoreFactory.py +47 -0
- naas_abi_core/services/vector_store/VectorStoreService.py +171 -0
- naas_abi_core/services/vector_store/VectorStoreService_test.py +185 -0
- naas_abi_core/services/vector_store/__init__.py +13 -0
- naas_abi_core/services/vector_store/adapters/QdrantAdapter.py +251 -0
- naas_abi_core/services/vector_store/adapters/QdrantAdapter_test.py +57 -0
- naas_abi_core/tests/test_services_imports.py +69 -0
- naas_abi_core/utils/Expose.py +55 -0
- naas_abi_core/utils/Graph.py +182 -0
- naas_abi_core/utils/JSON.py +49 -0
- naas_abi_core/utils/LazyLoader.py +44 -0
- naas_abi_core/utils/Logger.py +12 -0
- naas_abi_core/utils/OntologyReasoner.py +141 -0
- naas_abi_core/utils/OntologyYaml.py +681 -0
- naas_abi_core/utils/SPARQL.py +256 -0
- naas_abi_core/utils/Storage.py +33 -0
- naas_abi_core/utils/StorageUtils.py +398 -0
- naas_abi_core/utils/String.py +52 -0
- naas_abi_core/utils/Workers.py +114 -0
- naas_abi_core/utils/__init__.py +0 -0
- naas_abi_core/utils/onto2py/README.md +0 -0
- naas_abi_core/utils/onto2py/__init__.py +10 -0
- naas_abi_core/utils/onto2py/__main__.py +29 -0
- naas_abi_core/utils/onto2py/onto2py.py +611 -0
- naas_abi_core/utils/onto2py/tests/ttl2py_test.py +271 -0
- naas_abi_core/workflow/__init__.py +5 -0
- naas_abi_core/workflow/workflow.py +48 -0
- naas_abi_core-1.4.1.dist-info/METADATA +630 -0
- naas_abi_core-1.4.1.dist-info/RECORD +124 -0
- naas_abi_core-1.4.1.dist-info/WHEEL +4 -0
- naas_abi_core-1.4.1.dist-info/entry_points.txt +2 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
from urllib.parse import quote
|
|
2
|
+
import hashlib
|
|
3
|
+
import uuid
|
|
4
|
+
from uuid import UUID
|
|
5
|
+
import unicodedata
|
|
6
|
+
import re
|
|
7
|
+
|
|
8
|
+
def create_id_from_string(string: str) -> str:
|
|
9
|
+
"""Create a URL-safe ID from a string.
|
|
10
|
+
|
|
11
|
+
Args:
|
|
12
|
+
string (str): Input string to convert
|
|
13
|
+
|
|
14
|
+
Returns:
|
|
15
|
+
str: URL-safe string with spaces replaced by hyphens
|
|
16
|
+
"""
|
|
17
|
+
return quote(string.replace(" ", "-").lower(), safe="")
|
|
18
|
+
|
|
19
|
+
def string_to_uuid(input_string: str) -> UUID:
|
|
20
|
+
"""Convert a string to a UUID.
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
input_string (str): Input string to convert
|
|
24
|
+
|
|
25
|
+
Returns:
|
|
26
|
+
str: UUID
|
|
27
|
+
"""
|
|
28
|
+
hash_object = hashlib.sha256(input_string.encode())
|
|
29
|
+
hex_hash = hash_object.hexdigest()
|
|
30
|
+
uuid_obj = uuid.UUID(hex_hash[:32])
|
|
31
|
+
return uuid_obj
|
|
32
|
+
|
|
33
|
+
def create_hash_from_string(input_string: str) -> str:
|
|
34
|
+
"""Convert a string to a UUID.
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
input_string (str): Input string to convert
|
|
38
|
+
|
|
39
|
+
Returns:
|
|
40
|
+
str: UUID
|
|
41
|
+
"""
|
|
42
|
+
hash_object = hashlib.sha256(input_string.encode())
|
|
43
|
+
hex_hash = hash_object.hexdigest()
|
|
44
|
+
return hex_hash
|
|
45
|
+
|
|
46
|
+
def normalize(text: str) -> str:
|
|
47
|
+
"""Normalize text by removing accents, punctuation, and converting to lowercase."""
|
|
48
|
+
text = text.lower()
|
|
49
|
+
text = unicodedata.normalize('NFKD', text)
|
|
50
|
+
text = re.sub(r'[^\w\s]', '', text)
|
|
51
|
+
text = ''.join(c for c in text if not unicodedata.combining(c))
|
|
52
|
+
return text
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import uuid
|
|
2
|
+
from enum import Enum
|
|
3
|
+
from queue import Empty, Queue
|
|
4
|
+
from threading import Event, Lock, Thread
|
|
5
|
+
from typing import Callable, List, Optional
|
|
6
|
+
|
|
7
|
+
from naas_abi_core import logger
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class JobStatus(Enum):
|
|
11
|
+
PENDING = "pending"
|
|
12
|
+
RUNNING = "running"
|
|
13
|
+
COMPLETED = "completed"
|
|
14
|
+
FAILED = "failed"
|
|
15
|
+
RESULT_FETCHED = "result_fetched"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class Job:
|
|
19
|
+
def __init__(self, queue: Optional[Queue], func: Callable, *args, **kwargs):
|
|
20
|
+
self.id = str(uuid.uuid4())
|
|
21
|
+
self.queue = queue
|
|
22
|
+
self.func = func
|
|
23
|
+
self.args = args
|
|
24
|
+
self.kwargs = kwargs
|
|
25
|
+
self.status = JobStatus.PENDING
|
|
26
|
+
self.result = None
|
|
27
|
+
self.error = None
|
|
28
|
+
self._completion_event = Event()
|
|
29
|
+
self._lock = Lock() # For thread-safe status updates
|
|
30
|
+
|
|
31
|
+
def execute(self):
|
|
32
|
+
"""Execute the job - called by worker thread"""
|
|
33
|
+
with self._lock:
|
|
34
|
+
self.status = JobStatus.RUNNING
|
|
35
|
+
|
|
36
|
+
try:
|
|
37
|
+
self.result = self.func(*self.args, **self.kwargs)
|
|
38
|
+
with self._lock:
|
|
39
|
+
self.status = JobStatus.COMPLETED
|
|
40
|
+
except Exception as e:
|
|
41
|
+
self.error = e
|
|
42
|
+
import traceback
|
|
43
|
+
|
|
44
|
+
logger.error(f"Job {self.id} failed: {e}\n{traceback.format_exc()}")
|
|
45
|
+
with self._lock:
|
|
46
|
+
self.status = JobStatus.FAILED
|
|
47
|
+
finally:
|
|
48
|
+
self._completion_event.set()
|
|
49
|
+
if self.queue:
|
|
50
|
+
self.queue.put(self)
|
|
51
|
+
|
|
52
|
+
def wait(self, timeout: Optional[float] = None) -> bool:
|
|
53
|
+
"""Wait for the job to complete"""
|
|
54
|
+
return self._completion_event.wait(timeout)
|
|
55
|
+
|
|
56
|
+
def is_completed(self) -> bool:
|
|
57
|
+
"""Check if the job is completed (successfully or with failure)"""
|
|
58
|
+
return self.status in (JobStatus.COMPLETED, JobStatus.FAILED)
|
|
59
|
+
|
|
60
|
+
def get_result(self):
|
|
61
|
+
"""Get the job result, raising any error that occurred"""
|
|
62
|
+
with self._lock:
|
|
63
|
+
self.status = JobStatus.RESULT_FETCHED
|
|
64
|
+
|
|
65
|
+
if self.error:
|
|
66
|
+
raise self.error
|
|
67
|
+
|
|
68
|
+
return self.result
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class WorkerPool:
|
|
72
|
+
def __init__(self, num_workers: int):
|
|
73
|
+
self.job_queue: Queue[Job] = Queue()
|
|
74
|
+
self.workers: List[Thread] = []
|
|
75
|
+
self.shutdown_event = Event()
|
|
76
|
+
|
|
77
|
+
# Start worker threads
|
|
78
|
+
for _ in range(num_workers):
|
|
79
|
+
worker = Thread(target=self._worker_loop)
|
|
80
|
+
worker.daemon = True
|
|
81
|
+
worker.start()
|
|
82
|
+
self.workers.append(worker)
|
|
83
|
+
|
|
84
|
+
def _worker_loop(self):
|
|
85
|
+
while not self.shutdown_event.is_set():
|
|
86
|
+
try:
|
|
87
|
+
# Get job from queue with timeout to check shutdown periodically
|
|
88
|
+
job = self.job_queue.get(timeout=1.0)
|
|
89
|
+
job.execute()
|
|
90
|
+
self.job_queue.task_done()
|
|
91
|
+
except Empty:
|
|
92
|
+
continue
|
|
93
|
+
|
|
94
|
+
def submit(self, job: Job):
|
|
95
|
+
"""Submit a job to the worker pool"""
|
|
96
|
+
self.job_queue.put(job)
|
|
97
|
+
|
|
98
|
+
def submit_all(self, jobs: List[Job]) -> Queue[Job]:
|
|
99
|
+
"""Submit multiple jobs to the worker pool"""
|
|
100
|
+
queue: Queue[Job] = Queue(maxsize=len(jobs))
|
|
101
|
+
|
|
102
|
+
for job in jobs:
|
|
103
|
+
if job.queue is None:
|
|
104
|
+
job.queue = queue
|
|
105
|
+
self.submit(job)
|
|
106
|
+
|
|
107
|
+
return queue
|
|
108
|
+
|
|
109
|
+
def shutdown(self):
|
|
110
|
+
"""Shutdown the worker pool"""
|
|
111
|
+
logger.debug("Shutting down worker pool")
|
|
112
|
+
self.shutdown_event.set()
|
|
113
|
+
for worker in self.workers:
|
|
114
|
+
worker.join()
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Main entry point for running onto2py as a module.
|
|
3
|
+
|
|
4
|
+
Usage: python -m onto2py <ttl_file> <output_file>
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import sys
|
|
8
|
+
from .onto2py import onto2py
|
|
9
|
+
|
|
10
|
+
def main():
|
|
11
|
+
if len(sys.argv) < 3:
|
|
12
|
+
print("Usage: python -m onto2py <ttl_file> <output_file>")
|
|
13
|
+
sys.exit(1)
|
|
14
|
+
|
|
15
|
+
# take a ttl file as input
|
|
16
|
+
ttl_file = sys.argv[1]
|
|
17
|
+
output_file = sys.argv[2]
|
|
18
|
+
|
|
19
|
+
try:
|
|
20
|
+
python_code = onto2py(ttl_file)
|
|
21
|
+
with open(output_file, "w") as f:
|
|
22
|
+
f.write(python_code)
|
|
23
|
+
print(f"✅ Python code written to {output_file}")
|
|
24
|
+
except Exception as e:
|
|
25
|
+
print(f"❌ Error converting TTL file: {e}")
|
|
26
|
+
sys.exit(1)
|
|
27
|
+
|
|
28
|
+
if __name__ == "__main__":
|
|
29
|
+
main()
|