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.
Files changed (124) hide show
  1. assets/favicon.ico +0 -0
  2. assets/logo.png +0 -0
  3. naas_abi_core/__init__.py +1 -0
  4. naas_abi_core/apps/api/api.py +245 -0
  5. naas_abi_core/apps/api/api_test.py +281 -0
  6. naas_abi_core/apps/api/openapi_doc.py +144 -0
  7. naas_abi_core/apps/mcp/Dockerfile.mcp +35 -0
  8. naas_abi_core/apps/mcp/mcp_server.py +243 -0
  9. naas_abi_core/apps/mcp/mcp_server_test.py +163 -0
  10. naas_abi_core/apps/terminal_agent/main.py +555 -0
  11. naas_abi_core/apps/terminal_agent/terminal_style.py +175 -0
  12. naas_abi_core/engine/Engine.py +87 -0
  13. naas_abi_core/engine/EngineProxy.py +109 -0
  14. naas_abi_core/engine/Engine_test.py +6 -0
  15. naas_abi_core/engine/IEngine.py +91 -0
  16. naas_abi_core/engine/conftest.py +45 -0
  17. naas_abi_core/engine/engine_configuration/EngineConfiguration.py +216 -0
  18. naas_abi_core/engine/engine_configuration/EngineConfiguration_Deploy.py +7 -0
  19. naas_abi_core/engine/engine_configuration/EngineConfiguration_GenericLoader.py +49 -0
  20. naas_abi_core/engine/engine_configuration/EngineConfiguration_ObjectStorageService.py +159 -0
  21. naas_abi_core/engine/engine_configuration/EngineConfiguration_ObjectStorageService_test.py +26 -0
  22. naas_abi_core/engine/engine_configuration/EngineConfiguration_SecretService.py +138 -0
  23. naas_abi_core/engine/engine_configuration/EngineConfiguration_SecretService_test.py +74 -0
  24. naas_abi_core/engine/engine_configuration/EngineConfiguration_TripleStoreService.py +224 -0
  25. naas_abi_core/engine/engine_configuration/EngineConfiguration_TripleStoreService_test.py +109 -0
  26. naas_abi_core/engine/engine_configuration/EngineConfiguration_VectorStoreService.py +76 -0
  27. naas_abi_core/engine/engine_configuration/EngineConfiguration_VectorStoreService_test.py +33 -0
  28. naas_abi_core/engine/engine_configuration/EngineConfiguration_test.py +9 -0
  29. naas_abi_core/engine/engine_configuration/utils/PydanticModelValidator.py +15 -0
  30. naas_abi_core/engine/engine_loaders/EngineModuleLoader.py +302 -0
  31. naas_abi_core/engine/engine_loaders/EngineOntologyLoader.py +16 -0
  32. naas_abi_core/engine/engine_loaders/EngineServiceLoader.py +47 -0
  33. naas_abi_core/integration/__init__.py +7 -0
  34. naas_abi_core/integration/integration.py +28 -0
  35. naas_abi_core/models/Model.py +198 -0
  36. naas_abi_core/models/OpenRouter.py +18 -0
  37. naas_abi_core/models/OpenRouter_test.py +36 -0
  38. naas_abi_core/module/Module.py +252 -0
  39. naas_abi_core/module/ModuleAgentLoader.py +50 -0
  40. naas_abi_core/module/ModuleUtils.py +20 -0
  41. naas_abi_core/modules/templatablesparqlquery/README.md +196 -0
  42. naas_abi_core/modules/templatablesparqlquery/__init__.py +39 -0
  43. naas_abi_core/modules/templatablesparqlquery/ontologies/TemplatableSparqlQueryOntology.ttl +116 -0
  44. naas_abi_core/modules/templatablesparqlquery/workflows/GenericWorkflow.py +48 -0
  45. naas_abi_core/modules/templatablesparqlquery/workflows/TemplatableSparqlQueryLoader.py +192 -0
  46. naas_abi_core/pipeline/__init__.py +6 -0
  47. naas_abi_core/pipeline/pipeline.py +70 -0
  48. naas_abi_core/services/__init__.py +0 -0
  49. naas_abi_core/services/agent/Agent.py +1619 -0
  50. naas_abi_core/services/agent/AgentMemory_test.py +28 -0
  51. naas_abi_core/services/agent/Agent_test.py +214 -0
  52. naas_abi_core/services/agent/IntentAgent.py +1179 -0
  53. naas_abi_core/services/agent/IntentAgent_test.py +139 -0
  54. naas_abi_core/services/agent/beta/Embeddings.py +181 -0
  55. naas_abi_core/services/agent/beta/IntentMapper.py +120 -0
  56. naas_abi_core/services/agent/beta/LocalModel.py +88 -0
  57. naas_abi_core/services/agent/beta/VectorStore.py +89 -0
  58. naas_abi_core/services/agent/test_agent_memory.py +278 -0
  59. naas_abi_core/services/agent/test_postgres_integration.py +145 -0
  60. naas_abi_core/services/cache/CacheFactory.py +31 -0
  61. naas_abi_core/services/cache/CachePort.py +63 -0
  62. naas_abi_core/services/cache/CacheService.py +246 -0
  63. naas_abi_core/services/cache/CacheService_test.py +85 -0
  64. naas_abi_core/services/cache/adapters/secondary/CacheFSAdapter.py +39 -0
  65. naas_abi_core/services/object_storage/ObjectStorageFactory.py +57 -0
  66. naas_abi_core/services/object_storage/ObjectStoragePort.py +47 -0
  67. naas_abi_core/services/object_storage/ObjectStorageService.py +41 -0
  68. naas_abi_core/services/object_storage/adapters/secondary/ObjectStorageSecondaryAdapterFS.py +52 -0
  69. naas_abi_core/services/object_storage/adapters/secondary/ObjectStorageSecondaryAdapterNaas.py +131 -0
  70. naas_abi_core/services/object_storage/adapters/secondary/ObjectStorageSecondaryAdapterS3.py +171 -0
  71. naas_abi_core/services/ontology/OntologyPorts.py +36 -0
  72. naas_abi_core/services/ontology/OntologyService.py +17 -0
  73. naas_abi_core/services/ontology/adaptors/secondary/OntologyService_SecondaryAdaptor_NERPort.py +37 -0
  74. naas_abi_core/services/secret/Secret.py +138 -0
  75. naas_abi_core/services/secret/SecretPorts.py +45 -0
  76. naas_abi_core/services/secret/Secret_test.py +65 -0
  77. naas_abi_core/services/secret/adaptors/secondary/Base64Secret.py +57 -0
  78. naas_abi_core/services/secret/adaptors/secondary/Base64Secret_test.py +39 -0
  79. naas_abi_core/services/secret/adaptors/secondary/NaasSecret.py +88 -0
  80. naas_abi_core/services/secret/adaptors/secondary/NaasSecret_test.py +25 -0
  81. naas_abi_core/services/secret/adaptors/secondary/dotenv_secret_secondaryadaptor.py +29 -0
  82. naas_abi_core/services/triple_store/TripleStoreFactory.py +116 -0
  83. naas_abi_core/services/triple_store/TripleStorePorts.py +223 -0
  84. naas_abi_core/services/triple_store/TripleStoreService.py +419 -0
  85. naas_abi_core/services/triple_store/adaptors/secondary/AWSNeptune.py +1300 -0
  86. naas_abi_core/services/triple_store/adaptors/secondary/AWSNeptune_test.py +284 -0
  87. naas_abi_core/services/triple_store/adaptors/secondary/Oxigraph.py +597 -0
  88. naas_abi_core/services/triple_store/adaptors/secondary/Oxigraph_test.py +1474 -0
  89. naas_abi_core/services/triple_store/adaptors/secondary/TripleStoreService__SecondaryAdaptor__Filesystem.py +223 -0
  90. naas_abi_core/services/triple_store/adaptors/secondary/TripleStoreService__SecondaryAdaptor__ObjectStorage.py +234 -0
  91. naas_abi_core/services/triple_store/adaptors/secondary/base/TripleStoreService__SecondaryAdaptor__FileBase.py +18 -0
  92. naas_abi_core/services/vector_store/IVectorStorePort.py +101 -0
  93. naas_abi_core/services/vector_store/IVectorStorePort_test.py +189 -0
  94. naas_abi_core/services/vector_store/VectorStoreFactory.py +47 -0
  95. naas_abi_core/services/vector_store/VectorStoreService.py +171 -0
  96. naas_abi_core/services/vector_store/VectorStoreService_test.py +185 -0
  97. naas_abi_core/services/vector_store/__init__.py +13 -0
  98. naas_abi_core/services/vector_store/adapters/QdrantAdapter.py +251 -0
  99. naas_abi_core/services/vector_store/adapters/QdrantAdapter_test.py +57 -0
  100. naas_abi_core/tests/test_services_imports.py +69 -0
  101. naas_abi_core/utils/Expose.py +55 -0
  102. naas_abi_core/utils/Graph.py +182 -0
  103. naas_abi_core/utils/JSON.py +49 -0
  104. naas_abi_core/utils/LazyLoader.py +44 -0
  105. naas_abi_core/utils/Logger.py +12 -0
  106. naas_abi_core/utils/OntologyReasoner.py +141 -0
  107. naas_abi_core/utils/OntologyYaml.py +681 -0
  108. naas_abi_core/utils/SPARQL.py +256 -0
  109. naas_abi_core/utils/Storage.py +33 -0
  110. naas_abi_core/utils/StorageUtils.py +398 -0
  111. naas_abi_core/utils/String.py +52 -0
  112. naas_abi_core/utils/Workers.py +114 -0
  113. naas_abi_core/utils/__init__.py +0 -0
  114. naas_abi_core/utils/onto2py/README.md +0 -0
  115. naas_abi_core/utils/onto2py/__init__.py +10 -0
  116. naas_abi_core/utils/onto2py/__main__.py +29 -0
  117. naas_abi_core/utils/onto2py/onto2py.py +611 -0
  118. naas_abi_core/utils/onto2py/tests/ttl2py_test.py +271 -0
  119. naas_abi_core/workflow/__init__.py +5 -0
  120. naas_abi_core/workflow/workflow.py +48 -0
  121. naas_abi_core-1.4.1.dist-info/METADATA +630 -0
  122. naas_abi_core-1.4.1.dist-info/RECORD +124 -0
  123. naas_abi_core-1.4.1.dist-info/WHEEL +4 -0
  124. 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,10 @@
1
+ """
2
+ TTL to Python converter
3
+
4
+ Convert TTL (Turtle) files to Python Pydantic classes.
5
+ """
6
+
7
+ from .onto2py import onto2py
8
+
9
+ __version__ = "0.1.0"
10
+ __all__ = ["onto2py"]
@@ -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()