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,175 @@
|
|
|
1
|
+
from rich.console import Console
|
|
2
|
+
from rich.markdown import Markdown
|
|
3
|
+
from rich.panel import Panel
|
|
4
|
+
from rich.syntax import Syntax
|
|
5
|
+
from rich.text import Text
|
|
6
|
+
from rich.box import ROUNDED
|
|
7
|
+
from PIL import Image
|
|
8
|
+
import os
|
|
9
|
+
import platform
|
|
10
|
+
import subprocess
|
|
11
|
+
|
|
12
|
+
console = Console()
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def set_terminal_title():
|
|
16
|
+
"""Set the terminal title to 'ABI'"""
|
|
17
|
+
if platform.system() == "Windows":
|
|
18
|
+
os.system("title ABI")
|
|
19
|
+
else: # For Unix-like systems (Linux, macOS)
|
|
20
|
+
print("\33]0;ABI\a", end="", flush=True)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def print_agent_response(text, agent_label):
|
|
24
|
+
console.print() # Add a blank line before the assistant's response
|
|
25
|
+
console.print(f"[bold green]{agent_label}:[/bold green] ", end="")
|
|
26
|
+
md = Markdown(text)
|
|
27
|
+
console.print(md)
|
|
28
|
+
console.print() # Add a blank line after the assistant's response
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def print_system_message(text):
|
|
32
|
+
console.print() # Add a blank line before the system message
|
|
33
|
+
system_text = Text(text, style="yellow")
|
|
34
|
+
console.print(
|
|
35
|
+
Panel(
|
|
36
|
+
system_text,
|
|
37
|
+
border_style="yellow",
|
|
38
|
+
box=ROUNDED,
|
|
39
|
+
expand=False,
|
|
40
|
+
title="System",
|
|
41
|
+
title_align="left",
|
|
42
|
+
)
|
|
43
|
+
)
|
|
44
|
+
console.print() # Add a blank line after the system message
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def print_code(code, language="python"):
|
|
48
|
+
syntax = Syntax(code, language, theme="monokai", line_numbers=True)
|
|
49
|
+
console.print(
|
|
50
|
+
Panel(
|
|
51
|
+
syntax,
|
|
52
|
+
border_style="red",
|
|
53
|
+
box=ROUNDED,
|
|
54
|
+
expand=False,
|
|
55
|
+
title=f"Code ({language})",
|
|
56
|
+
title_align="left",
|
|
57
|
+
)
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def dict_to_equal_string(d: dict) -> str:
|
|
62
|
+
return "\n".join([f'-{key}="{value}"' for key, value in d.items()])
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def print_tool_usage(message):
|
|
66
|
+
print_message = ""
|
|
67
|
+
tool_name = message.tool_calls[0]["name"]
|
|
68
|
+
arguments = ""
|
|
69
|
+
if (
|
|
70
|
+
"args" in message.tool_calls[0]
|
|
71
|
+
and len(message.tool_calls[0]["args"].values()) > 0
|
|
72
|
+
):
|
|
73
|
+
arguments += dict_to_equal_string(message.tool_calls[0]["args"])
|
|
74
|
+
|
|
75
|
+
if tool_name.startswith("transfer_to_"):
|
|
76
|
+
tool_label = " ".join(
|
|
77
|
+
word.capitalize()
|
|
78
|
+
for word in tool_name.split("transfer_to_")[1].replace("_", " ").split()
|
|
79
|
+
)
|
|
80
|
+
print_message = f"\n🧞 [bold blue]Delegated to [/bold blue]{tool_label}"
|
|
81
|
+
else:
|
|
82
|
+
tool_label = tool_name.capitalize().replace("_", " ")
|
|
83
|
+
print_message = f"\n[bold blue]Tool Used:[/bold blue] {tool_label}\n{arguments}"
|
|
84
|
+
console.print(print_message)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def print_tool_response(response):
|
|
88
|
+
console.print(f"\n[bold blue]Response:[/bold blue] {response}")
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def clear_screen():
|
|
92
|
+
console.clear()
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def print_welcome_message(agent):
|
|
96
|
+
# Set terminal title
|
|
97
|
+
set_terminal_title()
|
|
98
|
+
|
|
99
|
+
# Skip the welcome - we already said hello in the CLI startup
|
|
100
|
+
# Just quietly start the conversation
|
|
101
|
+
pass
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def print_divider():
|
|
105
|
+
console.print("─" * console.width, style="dim")
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def get_user_input(agent_label):
|
|
109
|
+
try:
|
|
110
|
+
user_input = console.input(
|
|
111
|
+
"\n[bold cyan]You:[/bold cyan] "
|
|
112
|
+
) # Add a newline before the prompt
|
|
113
|
+
console.print() # Add a blank line after the user's input
|
|
114
|
+
return user_input
|
|
115
|
+
except EOFError:
|
|
116
|
+
console.print(
|
|
117
|
+
f"\n[bold red]{agent_label}:[/bold red] Conversation ended by user."
|
|
118
|
+
)
|
|
119
|
+
return "exit"
|
|
120
|
+
except KeyboardInterrupt:
|
|
121
|
+
console.print(
|
|
122
|
+
f"\n[bold red]{agent_label}:[/bold red] Conversation ended by user."
|
|
123
|
+
)
|
|
124
|
+
return "exit"
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def print_image(image_path: str):
|
|
128
|
+
"""Display an image in the terminal."""
|
|
129
|
+
try:
|
|
130
|
+
console.print() # Add some spacing
|
|
131
|
+
|
|
132
|
+
# Display the file path and viewing instructions
|
|
133
|
+
message = (
|
|
134
|
+
f"[yellow]Image saved at: {image_path}[/yellow]\n\n"
|
|
135
|
+
"[dim]To view the image:[/dim]\n"
|
|
136
|
+
f"[cyan]• Local system: Open {image_path} with your image viewer[/cyan]\n"
|
|
137
|
+
"[cyan]• Remote/SSH: Download the file to your local machine to view[/cyan]"
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
console.print(
|
|
141
|
+
Panel(
|
|
142
|
+
message,
|
|
143
|
+
border_style="yellow",
|
|
144
|
+
box=ROUNDED,
|
|
145
|
+
expand=False,
|
|
146
|
+
title="Graph Output",
|
|
147
|
+
title_align="left",
|
|
148
|
+
)
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
# Only try to show the image if we're in a GUI environment
|
|
152
|
+
if os.environ.get("DISPLAY") and platform.system() != "Windows":
|
|
153
|
+
try:
|
|
154
|
+
img = Image.open(image_path)
|
|
155
|
+
img.show()
|
|
156
|
+
except Exception:
|
|
157
|
+
pass # Silently fail if we can't display the image
|
|
158
|
+
elif platform.system() == "Windows":
|
|
159
|
+
try:
|
|
160
|
+
subprocess.run(['start', '', image_path], shell=True) # Windows-specific file opening
|
|
161
|
+
except Exception:
|
|
162
|
+
pass
|
|
163
|
+
|
|
164
|
+
console.print() # Add some spacing after
|
|
165
|
+
except Exception as e:
|
|
166
|
+
console.print(
|
|
167
|
+
Panel(
|
|
168
|
+
f"[yellow]Unable to process image. File saved at: {image_path}[/yellow]\nError: {str(e)}",
|
|
169
|
+
border_style="yellow",
|
|
170
|
+
box=ROUNDED,
|
|
171
|
+
expand=False,
|
|
172
|
+
title="Graph Output",
|
|
173
|
+
title_align="left",
|
|
174
|
+
)
|
|
175
|
+
)
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
from typing import Dict, List
|
|
2
|
+
|
|
3
|
+
from naas_abi_core import logger
|
|
4
|
+
from naas_abi_core.engine.engine_configuration.EngineConfiguration import (
|
|
5
|
+
EngineConfiguration,
|
|
6
|
+
)
|
|
7
|
+
from naas_abi_core.engine.engine_loaders.EngineModuleLoader import EngineModuleLoader
|
|
8
|
+
from naas_abi_core.engine.engine_loaders.EngineOntologyLoader import (
|
|
9
|
+
EngineOntologyLoader,
|
|
10
|
+
)
|
|
11
|
+
from naas_abi_core.engine.engine_loaders.EngineServiceLoader import EngineServiceLoader
|
|
12
|
+
from naas_abi_core.engine.IEngine import IEngine
|
|
13
|
+
from naas_abi_core.module.Module import BaseModule
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class Engine(IEngine):
|
|
17
|
+
__configuration: EngineConfiguration
|
|
18
|
+
__engine_module_loader: EngineModuleLoader
|
|
19
|
+
__engine_service_loader: EngineServiceLoader
|
|
20
|
+
|
|
21
|
+
__modules: Dict[
|
|
22
|
+
str, BaseModule
|
|
23
|
+
] # Must not set a default value to prevent modules to try to access modules inside constructors.
|
|
24
|
+
|
|
25
|
+
__services: IEngine.Services
|
|
26
|
+
|
|
27
|
+
@property
|
|
28
|
+
def configuration(self) -> EngineConfiguration:
|
|
29
|
+
return self.__configuration
|
|
30
|
+
|
|
31
|
+
@property
|
|
32
|
+
def modules(self) -> Dict[str, BaseModule]:
|
|
33
|
+
try:
|
|
34
|
+
return self.__modules
|
|
35
|
+
except AttributeError:
|
|
36
|
+
error_message = "You are trying to access the engine's modules before the engine is loaded. Modules are accessible when on_initialized is called. If you are in your module constructor or in the on_load method, you should not try to access self.engine yet."
|
|
37
|
+
logger.error(error_message)
|
|
38
|
+
raise RuntimeError(error_message)
|
|
39
|
+
|
|
40
|
+
@property
|
|
41
|
+
def services(self) -> IEngine.Services:
|
|
42
|
+
return self.__services
|
|
43
|
+
|
|
44
|
+
def __init__(self, configuration: str | None = None):
|
|
45
|
+
# Load configuration
|
|
46
|
+
self.__configuration = EngineConfiguration.load_configuration(configuration)
|
|
47
|
+
self.__engine_module_loader = EngineModuleLoader(self.__configuration)
|
|
48
|
+
self.__engine_service_loader = EngineServiceLoader(self.__configuration)
|
|
49
|
+
|
|
50
|
+
def load(self, module_names: List[str] = []):
|
|
51
|
+
module_dependencies = self.__engine_module_loader.get_modules_dependencies(
|
|
52
|
+
module_names
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
logger.debug("Loading engine services")
|
|
56
|
+
self.__services = self.__engine_service_loader.load_services(
|
|
57
|
+
module_dependencies
|
|
58
|
+
)
|
|
59
|
+
logger.debug("Engine services loaded")
|
|
60
|
+
|
|
61
|
+
logger.debug("Loading engine modules")
|
|
62
|
+
self.__modules = self.__engine_module_loader.load_modules(self, module_names)
|
|
63
|
+
logger.debug("Engine modules loaded")
|
|
64
|
+
|
|
65
|
+
if self.__services.triple_store_available():
|
|
66
|
+
logger.debug("Loading engine ontologies")
|
|
67
|
+
EngineOntologyLoader.load_ontologies(
|
|
68
|
+
self.__services.triple_store,
|
|
69
|
+
self.__engine_module_loader.ordered_modules,
|
|
70
|
+
)
|
|
71
|
+
logger.debug("Engine ontologies loaded")
|
|
72
|
+
else:
|
|
73
|
+
logger.debug("No triple store available, skipping ontology loading")
|
|
74
|
+
|
|
75
|
+
logger.debug("Initializing engine")
|
|
76
|
+
self.on_initialized()
|
|
77
|
+
logger.debug("Engine initialized")
|
|
78
|
+
|
|
79
|
+
def on_initialized(self):
|
|
80
|
+
for module in self.__modules.values():
|
|
81
|
+
module.on_initialized()
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
if __name__ == "__main__":
|
|
85
|
+
engine = Engine()
|
|
86
|
+
engine.load(module_names=["chatgpt"])
|
|
87
|
+
print("Engine loaded successfully")
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import TYPE_CHECKING, Dict
|
|
4
|
+
|
|
5
|
+
from naas_abi_core.engine.IEngine import IEngine
|
|
6
|
+
from naas_abi_core.services.object_storage.ObjectStorageService import (
|
|
7
|
+
ObjectStorageService,
|
|
8
|
+
)
|
|
9
|
+
from naas_abi_core.services.secret.Secret import Secret
|
|
10
|
+
from naas_abi_core.services.triple_store.TripleStoreService import TripleStoreService
|
|
11
|
+
from naas_abi_core.services.vector_store.VectorStoreService import VectorStoreService
|
|
12
|
+
|
|
13
|
+
if TYPE_CHECKING:
|
|
14
|
+
from naas_abi_core.module.Module import BaseModule, ModuleDependencies
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class ServicesProxy:
|
|
18
|
+
__engine: IEngine
|
|
19
|
+
__module_name: str
|
|
20
|
+
__module_dependencies: ModuleDependencies
|
|
21
|
+
|
|
22
|
+
def __init__(
|
|
23
|
+
self, engine: IEngine, module_name: str, module_dependencies: ModuleDependencies
|
|
24
|
+
):
|
|
25
|
+
self.__engine = engine
|
|
26
|
+
self.__module_name = module_name
|
|
27
|
+
self.__module_dependencies = module_dependencies
|
|
28
|
+
|
|
29
|
+
# def __accessible_services(self) -> List[Any]:
|
|
30
|
+
# engine_services = {
|
|
31
|
+
# type(service): service for service in self.__engine.services.all
|
|
32
|
+
# }
|
|
33
|
+
|
|
34
|
+
# for service_type in self.__module_dependencies.services:
|
|
35
|
+
# assert service_type in engine_services, (
|
|
36
|
+
# f"Service {service_type} not found in engine services"
|
|
37
|
+
# )
|
|
38
|
+
|
|
39
|
+
# return [
|
|
40
|
+
# service
|
|
41
|
+
# for service in engine_services.values()
|
|
42
|
+
# if type(service) in self.__module_dependencies.services
|
|
43
|
+
# ]
|
|
44
|
+
|
|
45
|
+
def __ensure_access(self, service_type: type) -> None:
|
|
46
|
+
if service_type not in self.__module_dependencies.services:
|
|
47
|
+
raise ValueError(
|
|
48
|
+
f"Module {self.__module_name} does not have access to {service_type}"
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
@property
|
|
52
|
+
def object_storage(self) -> ObjectStorageService:
|
|
53
|
+
self.__ensure_access(ObjectStorageService)
|
|
54
|
+
|
|
55
|
+
return self.__engine.services.object_storage
|
|
56
|
+
|
|
57
|
+
@property
|
|
58
|
+
def triple_store(self) -> TripleStoreService:
|
|
59
|
+
self.__ensure_access(TripleStoreService)
|
|
60
|
+
|
|
61
|
+
return self.__engine.services.triple_store
|
|
62
|
+
|
|
63
|
+
@property
|
|
64
|
+
def vector_store(self) -> VectorStoreService:
|
|
65
|
+
self.__ensure_access(VectorStoreService)
|
|
66
|
+
|
|
67
|
+
return self.__engine.services.vector_store
|
|
68
|
+
|
|
69
|
+
@property
|
|
70
|
+
def secret(self) -> Secret:
|
|
71
|
+
self.__ensure_access(Secret)
|
|
72
|
+
|
|
73
|
+
return self.__engine.services.secret
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class EngineProxy:
|
|
77
|
+
__engine: IEngine
|
|
78
|
+
__module_name: str
|
|
79
|
+
__module_dependencies: ModuleDependencies
|
|
80
|
+
|
|
81
|
+
__services_proxy: ServicesProxy
|
|
82
|
+
|
|
83
|
+
def __init__(
|
|
84
|
+
self,
|
|
85
|
+
engine: IEngine,
|
|
86
|
+
module_name: str,
|
|
87
|
+
module_dependencies: ModuleDependencies,
|
|
88
|
+
):
|
|
89
|
+
self.__engine = engine
|
|
90
|
+
self.__module_name = module_name
|
|
91
|
+
self.__module_dependencies = module_dependencies
|
|
92
|
+
self.__services_proxy = ServicesProxy(engine, module_name, module_dependencies)
|
|
93
|
+
|
|
94
|
+
@property
|
|
95
|
+
def modules(self) -> Dict[str, BaseModule]:
|
|
96
|
+
_modules = {}
|
|
97
|
+
|
|
98
|
+
for module in self.__module_dependencies.modules:
|
|
99
|
+
is_soft = module.endswith("#soft")
|
|
100
|
+
module = module.replace("#soft", "")
|
|
101
|
+
if module not in self.__engine.modules and is_soft:
|
|
102
|
+
continue
|
|
103
|
+
_modules[module] = self.__engine.modules[module]
|
|
104
|
+
|
|
105
|
+
return _modules
|
|
106
|
+
|
|
107
|
+
@property
|
|
108
|
+
def services(self) -> ServicesProxy:
|
|
109
|
+
return self.__services_proxy
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import TYPE_CHECKING, Dict, List, Union
|
|
4
|
+
|
|
5
|
+
from naas_abi_core.services.object_storage.ObjectStorageService import (
|
|
6
|
+
ObjectStorageService,
|
|
7
|
+
)
|
|
8
|
+
from naas_abi_core.services.secret.Secret import Secret
|
|
9
|
+
from naas_abi_core.services.triple_store.TripleStoreService import TripleStoreService
|
|
10
|
+
from naas_abi_core.services.vector_store.VectorStoreService import VectorStoreService
|
|
11
|
+
|
|
12
|
+
if TYPE_CHECKING:
|
|
13
|
+
from naas_abi_core.module.Module import BaseModule
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class IEngine:
|
|
17
|
+
class Services:
|
|
18
|
+
__object_storage: ObjectStorageService | None
|
|
19
|
+
__triple_store: TripleStoreService | None
|
|
20
|
+
__vector_store: VectorStoreService | None
|
|
21
|
+
__secret: Secret | None
|
|
22
|
+
|
|
23
|
+
def __init__(
|
|
24
|
+
self,
|
|
25
|
+
object_storage: ObjectStorageService | None = None,
|
|
26
|
+
triple_store: TripleStoreService | None = None,
|
|
27
|
+
vector_store: VectorStoreService | None = None,
|
|
28
|
+
secret: Secret | None = None,
|
|
29
|
+
):
|
|
30
|
+
self.__object_storage = object_storage
|
|
31
|
+
self.__triple_store = triple_store
|
|
32
|
+
self.__vector_store = vector_store
|
|
33
|
+
self.__secret = secret
|
|
34
|
+
|
|
35
|
+
@property
|
|
36
|
+
def object_storage(self) -> ObjectStorageService:
|
|
37
|
+
assert self.__object_storage is not None, (
|
|
38
|
+
"Object storage service is not initialized"
|
|
39
|
+
)
|
|
40
|
+
return self.__object_storage
|
|
41
|
+
|
|
42
|
+
@property
|
|
43
|
+
def triple_store(self) -> TripleStoreService:
|
|
44
|
+
assert self.__triple_store is not None, (
|
|
45
|
+
"Triple store service is not initialized"
|
|
46
|
+
)
|
|
47
|
+
return self.__triple_store
|
|
48
|
+
|
|
49
|
+
def triple_store_available(self) -> bool:
|
|
50
|
+
return self.__triple_store is not None
|
|
51
|
+
|
|
52
|
+
@property
|
|
53
|
+
def vector_store(self) -> VectorStoreService:
|
|
54
|
+
assert self.__vector_store is not None, (
|
|
55
|
+
"Vector store service is not initialized"
|
|
56
|
+
)
|
|
57
|
+
return self.__vector_store
|
|
58
|
+
|
|
59
|
+
@property
|
|
60
|
+
def secret(self) -> Secret:
|
|
61
|
+
assert self.__secret is not None, "Secret service is not initialized"
|
|
62
|
+
return self.__secret
|
|
63
|
+
|
|
64
|
+
@property
|
|
65
|
+
def all(
|
|
66
|
+
self,
|
|
67
|
+
) -> List[
|
|
68
|
+
Union[
|
|
69
|
+
ObjectStorageService | None,
|
|
70
|
+
TripleStoreService | None,
|
|
71
|
+
VectorStoreService | None,
|
|
72
|
+
Secret | None,
|
|
73
|
+
]
|
|
74
|
+
]:
|
|
75
|
+
return [
|
|
76
|
+
self.__object_storage,
|
|
77
|
+
self.__triple_store,
|
|
78
|
+
self.__vector_store,
|
|
79
|
+
self.__secret,
|
|
80
|
+
]
|
|
81
|
+
|
|
82
|
+
__services: Services
|
|
83
|
+
__modules: Dict[str, BaseModule]
|
|
84
|
+
|
|
85
|
+
@property
|
|
86
|
+
def services(self) -> Services:
|
|
87
|
+
return self.__services
|
|
88
|
+
|
|
89
|
+
@property
|
|
90
|
+
def modules(self) -> Dict[str, BaseModule]:
|
|
91
|
+
return self.__modules
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from pytest import fixture
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
@fixture
|
|
5
|
+
def test_configuration():
|
|
6
|
+
return """
|
|
7
|
+
workspace_id: "1234567890"
|
|
8
|
+
storage_name: "test"
|
|
9
|
+
github_repository: "test"
|
|
10
|
+
github_project_id: 1234567890
|
|
11
|
+
triple_store_path: "test"
|
|
12
|
+
api_title: "test"
|
|
13
|
+
api_description: "test"
|
|
14
|
+
logo_path: "test"
|
|
15
|
+
favicon_path: "test"
|
|
16
|
+
space_name: "test"
|
|
17
|
+
cors_origins:
|
|
18
|
+
- "http://localhost:9879"
|
|
19
|
+
|
|
20
|
+
services:
|
|
21
|
+
object_storage: &object_storage_service
|
|
22
|
+
object_storage_adapter:
|
|
23
|
+
adapter: "fs"
|
|
24
|
+
config:
|
|
25
|
+
base_path: "test"
|
|
26
|
+
test: "{{ secret.OXIGRAPH_URL }}"
|
|
27
|
+
|
|
28
|
+
triple_store:
|
|
29
|
+
triple_store_adapter:
|
|
30
|
+
adapter: "object_storage"
|
|
31
|
+
config:
|
|
32
|
+
triples_prefix: "test"
|
|
33
|
+
object_storage_service: *object_storage_service
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
vector_store:
|
|
37
|
+
vector_store_adapter:
|
|
38
|
+
adapter: "qdrant"
|
|
39
|
+
config: {}
|
|
40
|
+
|
|
41
|
+
secret:
|
|
42
|
+
secret_adapters:
|
|
43
|
+
- adapter: "dotenv"
|
|
44
|
+
config: {}
|
|
45
|
+
"""
|