naas-abi-core 1.1.2__py3-none-any.whl → 1.2.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.
@@ -1,10 +1,14 @@
1
1
  import os
2
+ import sys
2
3
  from io import StringIO
3
4
  from typing import List
4
5
 
5
6
  import yaml
6
7
  from jinja2 import Template
7
8
  from naas_abi_core import logger
9
+ from naas_abi_core.engine.engine_configuration.EngineConfiguration_Deploy import (
10
+ DeployConfiguration,
11
+ )
8
12
  from naas_abi_core.engine.engine_configuration.EngineConfiguration_ObjectStorageService import (
9
13
  ObjectStorageServiceConfiguration,
10
14
  )
@@ -19,8 +23,9 @@ from naas_abi_core.engine.engine_configuration.EngineConfiguration_VectorStoreSe
19
23
  )
20
24
  from naas_abi_core.services.secret.Secret import Secret
21
25
  from pydantic import BaseModel, model_validator
22
- from typing_extensions import Literal
23
- from naas_abi_core.engine.engine_configuration.EngineConfiguration_Deploy import DeployConfiguration
26
+ from rich.prompt import Prompt
27
+ from typing_extensions import Literal, Self
28
+
24
29
 
25
30
  class ServicesConfiguration(BaseModel):
26
31
  object_storage: ObjectStorageServiceConfiguration
@@ -80,7 +85,7 @@ class GlobalConfig(BaseModel):
80
85
 
81
86
  class EngineConfiguration(BaseModel):
82
87
  api: ApiConfiguration
83
-
88
+
84
89
  deploy: DeployConfiguration | None = None
85
90
 
86
91
  services: ServicesConfiguration
@@ -89,6 +94,25 @@ class EngineConfiguration(BaseModel):
89
94
 
90
95
  modules: List[ModuleConfig]
91
96
 
97
+ def ensure_default_modules(self) -> None:
98
+ if not any(
99
+ m.path == "naas_abi_core.modules.templatablesparqlquery"
100
+ or m.module == "naas_abi_core.modules.templatablesparqlquery"
101
+ for m in self.modules
102
+ ):
103
+ self.modules.append(
104
+ ModuleConfig(
105
+ module="naas_abi_core.modules.templatablesparqlquery",
106
+ enabled=True,
107
+ config={},
108
+ )
109
+ )
110
+
111
+ @model_validator(mode="after")
112
+ def validate_modules(self) -> Self:
113
+ self.ensure_default_modules()
114
+ return self
115
+
92
116
  @classmethod
93
117
  def from_yaml(cls, yaml_path: str) -> "EngineConfiguration":
94
118
  with open(yaml_path, "r") as file:
@@ -108,7 +132,16 @@ class EngineConfiguration(BaseModel):
108
132
  return 0
109
133
  secret = self.secret_service.get(name)
110
134
  if secret is None:
111
- raise ValueError(f"Secret {name} not found")
135
+ if not sys.stdin.isatty():
136
+ raise ValueError(
137
+ f"Secret '{name}' not found and no TTY available to prompt. Please provide it via the configured secret service or environment."
138
+ )
139
+ value = Prompt.ask(
140
+ f"[bold yellow]Secret '{name}' not found.[/bold yellow] Please enter the value for [cyan]{name}[/cyan]",
141
+ password=False,
142
+ )
143
+ self.secret_service.set(name, value)
144
+ return value
112
145
  return secret
113
146
 
114
147
  def get(self, key, default=None):
@@ -20,11 +20,29 @@ if TYPE_CHECKING:
20
20
 
21
21
 
22
22
  class OxigraphAdapterConfiguration(BaseModel):
23
+ """Oxigraph adapter configuration.
24
+
25
+ triple_store_adapter:
26
+ adapter: "oxigraph"
27
+ config:
28
+ oxigraph_url: "http://localhost:7878"
29
+ timeout: 60
30
+ """
23
31
  oxigraph_url: str = "http://localhost:7878"
24
32
  timeout: int = 60
25
33
 
26
34
 
27
35
  class AWSNeptuneAdapterConfiguration(BaseModel):
36
+ """AWS Neptune adapter configuration.
37
+
38
+ triple_store_adapter:
39
+ adapter: "aws_neptune"
40
+ config:
41
+ aws_region_name: "eu-west-3"
42
+ aws_access_key_id: "{{ secret.AWS_ACCESS_KEY_ID }}"
43
+ aws_secret_access_key: "{{ secret.AWS_SECRET_ACCESS_KEY }}"
44
+ db_instance_identifier: "{{ secret.DB_INSTANCE_IDENTIFIER }}"
45
+ """
28
46
  aws_region_name: str
29
47
  aws_access_key_id: str
30
48
  aws_secret_access_key: str
@@ -32,6 +50,20 @@ class AWSNeptuneAdapterConfiguration(BaseModel):
32
50
 
33
51
 
34
52
  class AWSNeptuneSSHTunnelAdapterConfiguration(AWSNeptuneAdapterConfiguration):
53
+ """AWS Neptune SSH tunnel adapter configuration.
54
+
55
+ triple_store_adapter:
56
+ adapter: "aws_neptune_sshtunnel"
57
+ config:
58
+ aws_region_name: "eu-west-3"
59
+ aws_access_key_id: "{{ secret.AWS_ACCESS_KEY_ID }}"
60
+ aws_secret_access_key: "{{ secret.AWS_SECRET_ACCESS_KEY }}"
61
+ db_instance_identifier: "{{ secret.DB_INSTANCE_IDENTIFIER }}"
62
+ bastion_host: "bastion.example.com"
63
+ bastion_port: 22
64
+ bastion_user: "ubuntu"
65
+ bastion_private_key: "{{ secret.BASTION_PRIVATE_KEY }}"
66
+ """
35
67
  bastion_host: str
36
68
  bastion_port: int
37
69
  bastion_user: str
@@ -39,11 +71,27 @@ class AWSNeptuneSSHTunnelAdapterConfiguration(AWSNeptuneAdapterConfiguration):
39
71
 
40
72
 
41
73
  class TripleStoreAdapterFilesystemConfiguration(BaseModel):
74
+ """Filesystem adapter configuration.
75
+
76
+ triple_store_adapter:
77
+ adapter: "fs"
78
+ config:
79
+ store_path: "storage/triplestore"
80
+ triples_path: "triples"
81
+ """
42
82
  store_path: str
43
83
  triples_path: str = "triples"
44
84
 
45
85
 
46
86
  class TripleStoreAdapterObjectStorageConfiguration(BaseModel):
87
+ """Object storage adapter configuration.
88
+
89
+ triple_store_adapter:
90
+ adapter: "object_storage"
91
+ config:
92
+ object_storage_service: *object_storage_service
93
+ triples_prefix: "triples"
94
+ """
47
95
  object_storage_service: ObjectStorageServiceConfiguration
48
96
  triples_prefix: str = "triples"
49
97
 
@@ -1,8 +1,11 @@
1
1
  import os
2
+
3
+ # from dotenv import load_dotenv
2
4
  from langchain_openai import ChatOpenAI # using the OpenAI LLM class as wrapper
3
5
  from pydantic import SecretStr
4
- from dotenv import load_dotenv
5
- load_dotenv()
6
+
7
+ # load_dotenv()
8
+
6
9
 
7
10
  class ChatOpenRouter(ChatOpenAI):
8
11
  def __init__(self, model_name: str, **kwargs):
@@ -23,6 +23,7 @@ class ModuleAgentLoader:
23
23
  agent_module_path = (
24
24
  f"{class_.__module__}.agents.{file.replace('.py', '')}"
25
25
  )
26
+ logger.debug(f"Importing agent module from {agent_module_path}")
26
27
  agent_module = importlib.import_module(agent_module_path)
27
28
  for key, value in agent_module.__dict__.items():
28
29
  if (
@@ -13,6 +13,7 @@ from langgraph.graph.message import MessagesState
13
13
  from langgraph.types import Command
14
14
  from naas_abi_core import logger
15
15
  from naas_abi_core.models.Model import ChatModel
16
+ from spacy.cli import download as spacy_download
16
17
 
17
18
  from .Agent import Agent, AgentConfiguration, AgentSharedState, create_checkpointer
18
19
  from .beta.IntentMapper import Intent, IntentMapper, IntentScope, IntentType
@@ -23,7 +24,14 @@ _nlp = None
23
24
  def get_nlp():
24
25
  global _nlp
25
26
  if _nlp is None:
26
- _nlp = spacy.load("en_core_web_sm")
27
+ try:
28
+ _nlp = spacy.load("en_core_web_sm")
29
+ except OSError:
30
+ logger.warning(
31
+ "Downloading spacy model en_core_web_sm as it is not installed. This is a one time operation and can take a few seconds to complete based on your internet connection speed."
32
+ )
33
+ spacy_download("en_core_web_sm")
34
+ _nlp = spacy.load("en_core_web_sm")
27
35
  return _nlp
28
36
 
29
37
 
@@ -2,13 +2,14 @@ import hashlib
2
2
  import os
3
3
 
4
4
  import requests
5
- from dotenv import load_dotenv
5
+
6
+ # from dotenv import load_dotenv
6
7
  from naas_abi_core.services.cache.CacheFactory import CacheFactory
7
8
  from naas_abi_core.services.cache.CachePort import DataType
8
9
  from pydantic import SecretStr
9
10
  from tqdm import tqdm
10
11
 
11
- load_dotenv()
12
+ # load_dotenv()
12
13
 
13
14
 
14
15
  cache = CacheFactory.CacheFS_find_storage(subpath="intent_mapping")
@@ -3,16 +3,17 @@ from dataclasses import dataclass
3
3
  from enum import Enum
4
4
  from typing import Any, Optional, Tuple
5
5
 
6
- from dotenv import load_dotenv
6
+ # from dotenv import load_dotenv
7
7
  from langchain_openai import ChatOpenAI
8
8
  from pydantic import SecretStr
9
9
 
10
- from .Embeddings import EMBEDDINGS_MODELS_DIMENSIONS_MAP, embeddings_batch
10
+ from .Embeddings import EMBEDDINGS_MODELS_DIMENSIONS_MAP
11
11
  from .Embeddings import _model_name as embeddings_model_name
12
12
  from .Embeddings import embeddings as embeddings
13
+ from .Embeddings import embeddings_batch
13
14
  from .VectorStore import VectorStore
14
15
 
15
- load_dotenv()
16
+ # load_dotenv()
16
17
 
17
18
 
18
19
  class IntentScope(Enum):
@@ -1,12 +1,15 @@
1
1
  import os
2
2
  from typing import Any, Dict
3
3
 
4
- from dotenv import dotenv_values, set_key
4
+ from dotenv import dotenv_values, find_dotenv, set_key
5
5
  from naas_abi_core.services.secret.SecretPorts import ISecretAdapter
6
+ from naas_abi_core.utils.Logger import logger
6
7
 
7
8
 
8
9
  class DotenvSecretSecondaryAdaptor(ISecretAdapter):
9
10
  def __init__(self):
11
+ logger.debug(f"dotenv is using the file: {find_dotenv()}")
12
+
10
13
  self.secrets = dotenv_values()
11
14
 
12
15
  def get(self, key: str, default: Any = None) -> str:
@@ -9,4 +9,4 @@ def reconfigure(level: str = "DEBUG"):
9
9
  logger.add(sys.stderr, level=level)
10
10
 
11
11
 
12
- reconfigure(os.environ.get("LOG_LEVEL", "ERROR"))
12
+ reconfigure(os.environ.get("LOG_LEVEL", "WARNING"))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: naas-abi-core
3
- Version: 1.1.2
3
+ Version: 1.2.0
4
4
  Summary: Abi framework allowing you to build your AI system.
5
5
  Author-email: Maxime Jublou <maxime@naas.ai>, Florent Ravenel <florent@naas.ai>, Jeremy Ravenel <jeremy@naas.ai>
6
6
  Requires-Python: <4,>=3.10
@@ -7,27 +7,18 @@ naas_abi_core/apps/mcp/mcp_server.py,sha256=U-wDl8rswMk4nefGg2SUByw4x8CM10M59FfL
7
7
  naas_abi_core/apps/mcp/mcp_server_test.py,sha256=8jixnDyERM_HjjDTRtPDQcJ_rzA0ESAn147sl2Gk8gw,5636
8
8
  naas_abi_core/apps/terminal_agent/main.py,sha256=ucrNCGjjixyiO47Eily1yAmrwznS6KOcB1kk02yt_m8,19631
9
9
  naas_abi_core/apps/terminal_agent/terminal_style.py,sha256=YOpfvBlKU52wNyGEKbZPiRQVKxug-hI92H8ScV5L8Ew,5254
10
- naas_abi_core/cli/__init__.py,sha256=P89Ihofvv_pQf2wsfYL-PjLJMl6KRj3fNNIZDB77Qy0,1324
11
- naas_abi_core/cli/agent.py,sha256=fMdbC7HsrOfZSf5zVRHWSmyrejI5mUdRlAT5v5YHXzk,658
12
- naas_abi_core/cli/chat.py,sha256=3t_TJ7vqCNs0MIIXOtlSke3nzy4rMSEJtB3P6pKItMo,856
13
- naas_abi_core/cli/config.py,sha256=CcdDX6HKCP32NjRhbVsCOwLUC9LmaqTm2sv8W5rOt00,1484
14
- naas_abi_core/cli/deploy.py,sha256=WrIkCIdNjUuvgQ_HLh2rlPkWmw_2MS6NzTgn--o0P2Q,6081
15
- naas_abi_core/cli/init.py,sha256=Pcy2-hy-FvpXf3UOKMP6agWyFrCl9z-KP5ktEWltPy0,220
16
- naas_abi_core/cli/module.py,sha256=TBl-SpeGUcy1Rrp40Irbt34yQS00xJcNje-OijNE4Hk,717
17
- naas_abi_core/cli/new.py,sha256=aFhKbTHwqYkPdzrd7r8i_h9dfzXNjI03t8qVeqME8w8,262
18
- naas_abi_core/cli/secret.py,sha256=u_yUZgVEcns-CM-qsIIZUHX8j8T6aioJYluqSQhnXFE,2491
19
10
  naas_abi_core/engine/Engine.py,sha256=jGsGleO9PeFb7D9LlyO6gH1FFCh7Vj8wC7s0N0cuyxU,3257
20
11
  naas_abi_core/engine/EngineProxy.py,sha256=o-D8LlP-PjQ_Yct4JWrDZw7mA7yporxb2XrJFowLYrY,3379
21
12
  naas_abi_core/engine/Engine_test.py,sha256=8eLZEnkL0IR4VAr6LF8fJ_fxZzi9s1mXCLgTVOIsR3E,161
22
13
  naas_abi_core/engine/IEngine.py,sha256=u-m-Qrvt3SP3gYKWPFPVjV8rs05D6NGnzO3XA0FInnw,2865
23
14
  naas_abi_core/engine/conftest.py,sha256=Al-SRVLrEdbTrX8sxQ3bBK4w1bbzE4GoBkzoBK-aXlg,932
24
- naas_abi_core/engine/engine_configuration/EngineConfiguration.py,sha256=12rKgF1LaLC_YMhKEABFSdU_Fb04qGpW4tft3eVCnPI,5529
15
+ naas_abi_core/engine/engine_configuration/EngineConfiguration.py,sha256=NdjfrECgQ5leU7TNxxV6-qackTi0eaKzebqyJXlRPXk,6735
25
16
  naas_abi_core/engine/engine_configuration/EngineConfiguration_Deploy.py,sha256=7nqOnXWcNbQAp9G3afc3y58BrxCaIrrTpUz7yBngy14,163
26
17
  naas_abi_core/engine/engine_configuration/EngineConfiguration_GenericLoader.py,sha256=KK2TQx6cNmoqFcwr9En00NKrX4ckkZl4ecv9QCUwPyc,1995
27
18
  naas_abi_core/engine/engine_configuration/EngineConfiguration_ObjectStorageService.py,sha256=cPZBs5-2dqX-piIZ7KTqiOce6O6GbnDDwjPGcfDN_U4,4736
28
19
  naas_abi_core/engine/engine_configuration/EngineConfiguration_ObjectStorageService_test.py,sha256=h1PdIbMTJWi_lG83YgpI6zg8gRo0WEWvGSE6R4uKQp4,1063
29
20
  naas_abi_core/engine/engine_configuration/EngineConfiguration_SecretService.py,sha256=nqQ7XmfZZIx4kUvSO_FkBsSf9mcrRdwpsF_vkEdKqgU,4064
30
- naas_abi_core/engine/engine_configuration/EngineConfiguration_TripleStoreService.py,sha256=XCyn1DO3oW7xPlrfmD1lo3GPymDCVDPI-QXw-lbzzIQ,6278
21
+ naas_abi_core/engine/engine_configuration/EngineConfiguration_TripleStoreService.py,sha256=Wy4866k9JykcMf9ZDqBZfIVFLp98oU3_NwIaDPHrykI,7756
31
22
  naas_abi_core/engine/engine_configuration/EngineConfiguration_VectorStoreService.py,sha256=aoO-cmC1dfaXT4gqFivrO1ntB0xK8rjFoWmruf-I67U,2210
32
23
  naas_abi_core/engine/engine_configuration/EngineConfiguration_test.py,sha256=PL4A4Dawq6tfyHsiIkqbHhovc7wkIHcVZra6llRI-CY,286
33
24
  naas_abi_core/engine/engine_configuration/utils/PydanticModelValidator.py,sha256=jZzLqLvR8HawpyGYiUJEng3NlebLHiN3mVFOzNDSWs8,504
@@ -37,10 +28,10 @@ naas_abi_core/engine/engine_loaders/EngineServiceLoader.py,sha256=OPBTFG1c-QAFul
37
28
  naas_abi_core/integration/__init__.py,sha256=bB7l26o_ksuEo8O5dggIaZcolJbveJxGZe0-J_UzL3Y,305
38
29
  naas_abi_core/integration/integration.py,sha256=tbdAV63Uisml9G8diZl20_JDlgJVFuLQpK_7VE4qgSw,811
39
30
  naas_abi_core/models/Model.py,sha256=s1Aj8Mcy113uhgYR4-lSfoyLnucOzOlnxKu6QKSwfeY,8223
40
- naas_abi_core/models/OpenRouter.py,sha256=6bvn_Dl4mQB1J-XTMoF1rD8F4FNszLAA0358fzJDBxs,485
31
+ naas_abi_core/models/OpenRouter.py,sha256=BqDRnBlDmTdhE5cv7VsZ1IiZVad_lIltnnGt4V6MRuw,492
41
32
  naas_abi_core/models/OpenRouter_test.py,sha256=nLlVdBaBan0mkdbnF3vrWGJYr8zQAC7Fl3wLUc37Mvw,1168
42
33
  naas_abi_core/module/Module.py,sha256=UGNXZkwgD0xv7HrxTHH9eRXYPv8kuxqfMGAHgfgQJlM,9096
43
- naas_abi_core/module/ModuleAgentLoader.py,sha256=Tc2KYODt8cGeK__QLk7h0J5QZ0EM-ZsQZTDeCJ4ip38,1965
34
+ naas_abi_core/module/ModuleAgentLoader.py,sha256=9FXcK8h0_0h4hU3gEjImUbNBBeYJ9HOEjYqKVdTl3ik,2050
44
35
  naas_abi_core/module/ModuleUtils.py,sha256=6wUHpbdl0y_16xvz7W-NSOaRyLW9N9zx2Lg_Jkg0eMM,707
45
36
  naas_abi_core/modules/templatablesparqlquery/README.md,sha256=Cpz3FPMc1q-P5HmQ7848er5_MRTHLDLqYqq0nFrs7Dw,6991
46
37
  naas_abi_core/modules/templatablesparqlquery/__init__.py,sha256=Y2tAF9omNqYhJGYbt4MA28q7bnTX3wy3ATvJQwEwAmU,1225
@@ -53,12 +44,12 @@ naas_abi_core/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3
53
44
  naas_abi_core/services/agent/Agent.py,sha256=SOoo1J50qMJwfgart2zUC98oa6C43L_FN5UJl90182k,63648
54
45
  naas_abi_core/services/agent/AgentMemory_test.py,sha256=sSqDkr0o0MgeHudsX5s3u2oFLaAX7GVgyQPwdsD76Cs,650
55
46
  naas_abi_core/services/agent/Agent_test.py,sha256=VITdYn0fSK-7dq67qVQbirkwZBIRBwtRqdaWy9E87VY,6343
56
- naas_abi_core/services/agent/IntentAgent.py,sha256=gGAeLGLuJUNAi8cxsKRoazaoI6_75rX5sgV7qHY4R6w,45100
47
+ naas_abi_core/services/agent/IntentAgent.py,sha256=Wi1MncB5EDhV78ZVkt86jzwm2tmrF2R3wdagDrE5bbY,45515
57
48
  naas_abi_core/services/agent/IntentAgent_test.py,sha256=g5mI1EjLGsJm2rssxp3lsdP-WJbp6uuWePWGGazkgm8,4453
58
49
  naas_abi_core/services/agent/test_agent_memory.py,sha256=X1ZgEEDq10PYisnouBodThDT-JIgG_UHVmYp4xkBhOs,11079
59
50
  naas_abi_core/services/agent/test_postgres_integration.py,sha256=tzVJjBAqcHomUVuTQ5-kom3POOgbYjilw5Vzfr9Q6go,4458
60
- naas_abi_core/services/agent/beta/Embeddings.py,sha256=qC0DXWGhns_c04DeRzzbHFcgwY5cvcxuxWeL65O0su4,5109
61
- naas_abi_core/services/agent/beta/IntentMapper.py,sha256=NgZLybuj2Rp-jZmVRiMbtFESwOFldwCOXISkogOEYMc,3834
51
+ naas_abi_core/services/agent/beta/Embeddings.py,sha256=WT-iG3Ufx3uW6xzNhzkN6QAmekvbkJJ10DG3HzI_8BY,5114
52
+ naas_abi_core/services/agent/beta/IntentMapper.py,sha256=Oivf8ZqRCK7aFX9kilsPNhW59eO5-RKKQnkka_k6MEQ,3861
62
53
  naas_abi_core/services/agent/beta/LocalModel.py,sha256=QCOyEngihK8oh1CvFmiGUPUdvUAb2_tEwPPri45xoz0,3935
63
54
  naas_abi_core/services/agent/beta/VectorStore.py,sha256=ps6FvJz6Y-pb2WpcSDH1zm6is44tWJhSw0F2kziVxDI,2980
64
55
  naas_abi_core/services/cache/CacheFactory.py,sha256=i3kNZ3OjFGq4myxo1GvYyhp7DTSVoepQsXC3n9iIgzI,1054
@@ -82,7 +73,7 @@ naas_abi_core/services/secret/adaptors/secondary/Base64Secret.py,sha256=Py7bBEBn
82
73
  naas_abi_core/services/secret/adaptors/secondary/Base64Secret_test.py,sha256=wwdfMJrkh6vFZabZie9xyQHYlTjPAfouV-sPI4pk8MM,1287
83
74
  naas_abi_core/services/secret/adaptors/secondary/NaasSecret.py,sha256=b31HLYCN3JzYwlWwsiTlQ3FM7t9sLFz7dF3eMmFnA6c,2755
84
75
  naas_abi_core/services/secret/adaptors/secondary/NaasSecret_test.py,sha256=gR2hjU8e3hbkWn_suhwj4kfWLjTZjZavj-5R-z93zjU,625
85
- naas_abi_core/services/secret/adaptors/secondary/dotenv_secret_secondaryadaptor.py,sha256=gVNPGhtwfu_j_73PpWQtHC1gx8yR0qDqgjn4m1yppXs,782
76
+ naas_abi_core/services/secret/adaptors/secondary/dotenv_secret_secondaryadaptor.py,sha256=jNs1bTz25lD0B5HZUKjenxZ7x6qUm9kIESFmh2-QDs8,909
86
77
  naas_abi_core/services/triple_store/TripleStoreFactory.py,sha256=4cCWJUhmXo5-yB61fyDwc-pigIYZo_PzmPW_5pY5I-E,4560
87
78
  naas_abi_core/services/triple_store/TripleStorePorts.py,sha256=dRhDc5-uiXDZQWzscqUd972EPi_pafPLkj4sXwxF8Xs,6681
88
79
  naas_abi_core/services/triple_store/TripleStoreService.py,sha256=X1ty-fH0A1XyLhZpU6oc3h-BgOoarAHSMPzITBBVhlY,16274
@@ -106,7 +97,7 @@ naas_abi_core/utils/Expose.py,sha256=ycxiz2tOXkRco_fiNM281e85RWHWi2xUT82PEE_Hdjk
106
97
  naas_abi_core/utils/Graph.py,sha256=FoBuiTrcLw4dzhROnd7JHp-LMxMuwJISFbtdrwpoM24,6288
107
98
  naas_abi_core/utils/JSON.py,sha256=onIs-E3GWz4fvRuWBQpyb9qRNXCOJPf9x1yV1-jDlqU,1687
108
99
  naas_abi_core/utils/LazyLoader.py,sha256=rWrnFVuKCK1WrtNgeiegT_i7AkxGy9qK2hfhsXV4dCY,1120
109
- naas_abi_core/utils/Logger.py,sha256=WzsLDu52Nko3LHuZFZ5B_etcL4ZhLsx5IN6TxSV6FGY,201
100
+ naas_abi_core/utils/Logger.py,sha256=emZwe1EKAWcEegDQGFkr2U8vLX-oDUZXX580o9kP_xc,203
110
101
  naas_abi_core/utils/OntologyReasoner.py,sha256=OgDgiymd7HuDI28XZfcS2-9QeR7_jY9o9LWBQu2AU7k,4591
111
102
  naas_abi_core/utils/OntologyYaml.disabled.py,sha256=y5dYzD6w3yByQ4I-T6km6T2J0t-sTNy6iNm8ocpffyA,25246
112
103
  naas_abi_core/utils/SPARQL.py,sha256=Yjk2INdNIUuv8P26-ToqNik5odyUroybzWvijMsfcns,9313
@@ -123,7 +114,7 @@ naas_abi_core/utils/onto2py/tests/ttl2py_test.py,sha256=5OZqSxPffjJYiX9T4rT1mV0P
123
114
  naas_abi_core/workflow/__init__.py,sha256=hZD58mCB1PApxITqftP_xgjxL7NeLvOfI-rJENg1ENs,250
124
115
  naas_abi_core/workflow/workflow.py,sha256=ZufSS073JztVl0OQRTqNyK7FepFvv7gXlc4j5FAEZCI,1216
125
116
  assets/favicon.ico,sha256=nWk8wrHZiJV3DeuWrP2MqilXxCuoNWKGtMZfYmEVQLw,666
126
- naas_abi_core-1.1.2.dist-info/METADATA,sha256=IBC1ogptv8c_hN1nZ3hLGnTZYygPgSrLNtlMZVydT8c,3897
127
- naas_abi_core-1.1.2.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
128
- naas_abi_core-1.1.2.dist-info/entry_points.txt,sha256=q68PvlGw_rozZ0nl6mUg6l1l2IhxaTOKlf5K9goRDu0,99
129
- naas_abi_core-1.1.2.dist-info/RECORD,,
117
+ naas_abi_core-1.2.0.dist-info/METADATA,sha256=LiS6tUJsKiaQkMhf6U3_DIF-gKLIXybnqKY-kcDhCXM,3897
118
+ naas_abi_core-1.2.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
119
+ naas_abi_core-1.2.0.dist-info/entry_points.txt,sha256=IX0WUFxZuo1JU6H66fcRR6y7gYChMVw_XA9suPk9_1Q,70
120
+ naas_abi_core-1.2.0.dist-info/RECORD,,
@@ -1,3 +1,2 @@
1
1
  [console_scripts]
2
- abi = naas_abi_core.cli:main
3
2
  onto2py = naas_abi_core.utils.onto2py.__main__:main
@@ -1,54 +0,0 @@
1
- import click
2
-
3
- from .agent import agent
4
- from .chat import chat
5
- from .config import config
6
- from .init import init
7
- from .module import module
8
- from .new import new
9
- from .secret import secrets
10
- from .deploy import deploy
11
- # from dotenv import load_dotenv
12
-
13
- # load_dotenv()
14
-
15
-
16
- @click.group("abi")
17
- def main():
18
- pass
19
-
20
-
21
- # @main.command("chat")
22
- # @click.option("--module-name", type=str, required=True, default="chatgpt")
23
- # @click.option("--agent-name", type=str, required=True, default="ChatGPTAgent")
24
- # def chat(module_name: str, agent_name: str):
25
- # from naas_abi_core.engine.Engine import Engine
26
-
27
- # engine = Engine()
28
- # engine.load(module_names=[module_name])
29
-
30
- # from naas_abi_core.apps.terminal_agent.main import run_agent
31
-
32
- # logger.debug(f"Module agents: {engine.modules[module_name].agents}")
33
-
34
- # for agent_class in engine.modules[module_name].agents:
35
- # logger.debug(f"Agent class: {agent_class.__name__}")
36
- # if agent_class.__name__ == agent_name:
37
- # run_agent(agent_class.New())
38
- # break
39
-
40
-
41
- # Add the secrets group to the main abi group
42
-
43
-
44
- main.add_command(secrets)
45
- main.add_command(config)
46
- main.add_command(module)
47
- main.add_command(agent)
48
- main.add_command(chat)
49
- main.add_command(new)
50
- main.add_command(init)
51
- main.add_command(deploy)
52
-
53
- # if __name__ == "__main__":
54
- main()
@@ -1,30 +0,0 @@
1
- import click
2
- from rich.console import Console
3
- from rich.table import Table
4
-
5
- from naas_abi_core.engine.Engine import Engine
6
-
7
-
8
- @click.group("agent")
9
- def agent():
10
- pass
11
-
12
-
13
- @agent.command("list")
14
- def list():
15
- engine = Engine()
16
- engine.load()
17
-
18
- console = Console()
19
- table = Table(
20
- title="Available Agents", show_header=True, header_style="bold magenta"
21
- )
22
- table.add_column("Module", style="cyan", no_wrap=True)
23
- table.add_column("Agent", style="green")
24
-
25
- modules = engine.modules
26
- for module in modules:
27
- for agent in modules[module].agents:
28
- table.add_row(module, agent.__name__)
29
-
30
- console.print(table)
naas_abi_core/cli/chat.py DELETED
@@ -1,26 +0,0 @@
1
- import click
2
-
3
- from naas_abi_core import logger
4
-
5
-
6
- @click.command("chat")
7
- @click.argument("module-name", type=str, required=True, default="naas_abi")
8
- @click.argument("agent-name", type=str, required=True, default="AbiAgent")
9
- def chat(module_name: str, agent_name: str):
10
- from naas_abi_core.engine.Engine import Engine
11
-
12
- engine = Engine()
13
- engine.load(module_names=[module_name])
14
-
15
- from naas_abi_core.apps.terminal_agent.main import run_agent
16
-
17
- if module_name not in engine.modules:
18
- raise ValueError(f"Module {module_name} not found")
19
-
20
- logger.debug(f"Module agents: {engine.modules[module_name].agents}")
21
-
22
- for agent_class in engine.modules[module_name].agents:
23
- logger.debug(f"Agent class: {agent_class.__name__}")
24
- if agent_class.__name__ == agent_name:
25
- run_agent(agent_class.New())
26
- break
@@ -1,49 +0,0 @@
1
- import os
2
-
3
- import click
4
- import yaml
5
-
6
- from naas_abi_core.engine.engine_configuration.EngineConfiguration import (
7
- EngineConfiguration,
8
- )
9
-
10
-
11
- @click.group("config")
12
- def config():
13
- pass
14
-
15
-
16
- @config.command("validate")
17
- @click.option("--configuration-file", type=str, required=False, default=None)
18
- def validate(configuration_file: str | None):
19
- configuration_content: str | None = None
20
-
21
- if configuration_file is not None:
22
- if not os.path.exists(configuration_file):
23
- raise FileNotFoundError(
24
- f"Configuration file {configuration_file} not found"
25
- )
26
- with open(configuration_file, "r") as file:
27
- configuration_content = file.read()
28
-
29
- EngineConfiguration.load_configuration(configuration_content)
30
- print("Configuration is valid")
31
-
32
-
33
- @config.command("render")
34
- @click.option("--configuration-file", type=str, required=False, default=None)
35
- def render(configuration_file: str | None):
36
- configuration_content: str | None = None
37
-
38
- if configuration_file is not None:
39
- if not os.path.exists(configuration_file):
40
- raise FileNotFoundError(
41
- f"Configuration file {configuration_file} not found"
42
- )
43
- with open(configuration_file, "r") as file:
44
- configuration_content = file.read()
45
-
46
- configuration: EngineConfiguration = EngineConfiguration.load_configuration(
47
- configuration_content
48
- )
49
- print(yaml.dump(configuration.model_dump(), indent=2))
@@ -1,198 +0,0 @@
1
- import json
2
- import subprocess
3
- from uuid import uuid4
4
-
5
- import click
6
- import requests
7
- from pydantic import BaseModel
8
- from rich.console import Console
9
- from rich.markdown import Markdown
10
-
11
- from naas_abi_core import logger
12
- from naas_abi_core.engine.engine_configuration.EngineConfiguration import (
13
- EngineConfiguration,
14
- )
15
-
16
-
17
- @click.group("deploy")
18
- def deploy():
19
- pass
20
-
21
-
22
- class Container(BaseModel):
23
- name: str
24
- image: str
25
- port: int
26
- cpu: str
27
- memory: str
28
- env: dict
29
-
30
-
31
- class Space(BaseModel):
32
- name: str
33
- containers: list[Container]
34
-
35
-
36
- class NaasAPIClient:
37
- naas_api_key: str
38
- base_url: str
39
-
40
- def __init__(self, naas_api_key: str):
41
- self.naas_api_key = naas_api_key
42
- self.base_url = "https://api.naas.ai"
43
-
44
- def create_registry(self, name: str):
45
- response = requests.post(
46
- f"{self.base_url}/registry/",
47
- headers={"Authorization": f"Bearer {self.naas_api_key}"},
48
- json={"name": name},
49
- )
50
- if response.status_code == 409:
51
- return self.get_registry(name)
52
- response.raise_for_status()
53
- return response.json()
54
-
55
- def get_registry(self, name: str):
56
- response = requests.get(
57
- f"{self.base_url}/registry/{name}",
58
- headers={"Authorization": f"Bearer {self.naas_api_key}"},
59
- )
60
- response.raise_for_status()
61
- return response.json()
62
-
63
- def get_registry_credentials(self, name: str):
64
- response = requests.get(
65
- f"{self.base_url}/registry/{name}/credentials",
66
- headers={"Authorization": f"Bearer {self.naas_api_key}"},
67
- )
68
- response.raise_for_status()
69
- return response.json()
70
-
71
- def update_space(self, space: Space) -> dict:
72
- response = requests.put(
73
- f"{self.base_url}/space/{space.name}",
74
- headers={"Authorization": f"Bearer {self.naas_api_key}"},
75
- json=space.model_dump(),
76
- )
77
- response.raise_for_status()
78
- return response.json()
79
-
80
- def create_space(self, space: Space) -> dict:
81
- response = requests.post(
82
- f"{self.base_url}/space/",
83
- headers={"Authorization": f"Bearer {self.naas_api_key}"},
84
- json=space.model_dump(),
85
- )
86
-
87
- if response.status_code == 409:
88
- return self.update_space(space)
89
-
90
- response.raise_for_status()
91
- return response.json()
92
-
93
- def get_space(self, name: str) -> dict:
94
- response = requests.get(
95
- f"{self.base_url}/space/{name}",
96
- headers={"Authorization": f"Bearer {self.naas_api_key}"},
97
- )
98
- response.raise_for_status()
99
- return response.json()
100
-
101
-
102
- class NaasDeployer:
103
- image_name: str
104
-
105
- naas_api_client: NaasAPIClient
106
-
107
- def __init__(self, configuration: EngineConfiguration):
108
- self.configuration = configuration
109
- self.image_name = str(uuid4())
110
- assert configuration.deploy is not None
111
- self.naas_api_client = NaasAPIClient(configuration.deploy.naas_api_key)
112
-
113
- def docker_build(self, image_name: str):
114
- subprocess.run(
115
- f"docker build -t {image_name} . --platform linux/amd64", shell=True
116
- )
117
-
118
- def env_list_to_dict(self, env: list[str]) -> dict:
119
- return {env_var.split("=", 1)[0]: env_var.split("=", 1)[1] for env_var in env}
120
-
121
- def deploy(self, env: list[str]):
122
-
123
- registry = self.naas_api_client.create_registry(
124
- self.configuration.deploy.space_name
125
- )
126
-
127
- uid = str(uuid4())
128
-
129
- image_name = f"{registry['registry']['uri']}:{uid}"
130
- self.docker_build(image_name)
131
- credentials = self.naas_api_client.get_registry_credentials(
132
- self.configuration.deploy.space_name
133
- )
134
- docker_login_command = f"docker login -u {credentials['credentials']['username']} -p {credentials['credentials']['password']} {registry['registry']['uri']}"
135
- subprocess.run(docker_login_command, shell=True)
136
- subprocess.run(f"docker push {image_name}", shell=True)
137
-
138
- image_sha = (
139
- subprocess.run(
140
- "docker inspect --format='{{index .RepoDigests 0}}' "
141
- + image_name
142
- + " | cut -d'@' -f2",
143
- shell=True,
144
- capture_output=True,
145
- )
146
- .stdout.strip()
147
- .decode("utf-8")
148
- )
149
-
150
- image_name_with_sha = f"{image_name.replace(':' + uid, '')}@{image_sha}"
151
-
152
-
153
- self.naas_api_client.create_space(
154
- Space(
155
- name=self.configuration.deploy.space_name,
156
- containers=[
157
- Container(
158
- name="api",
159
- image=image_name_with_sha,
160
- port=9879,
161
- cpu="1",
162
- memory="1Gi",
163
- # env=self.env_list_to_dict(env) | {
164
- # "NAAS_API_KEY": self.configuration.deploy.naas_api_key,
165
- # "ENV": "prod",
166
- # },
167
- env=self.configuration.deploy.env | self.env_list_to_dict(env),
168
- )
169
- ],
170
- )
171
- )
172
-
173
- space = self.naas_api_client.get_space(self.configuration.deploy.space_name)
174
-
175
- Console().print(
176
- Markdown(f"""
177
- # Deployment successful
178
-
179
- - Space: {self.configuration.deploy.space_name}
180
- - Image: {image_name_with_sha}
181
- - URL: https://{self.configuration.deploy.space_name}.default.space.naas.ai
182
-
183
- """)
184
- )
185
-
186
-
187
- @deploy.command("naas")
188
- @click.option("-e", "--env", multiple=True, help="Environment variables to set (e.g. -e FOO=BAR -e BAZ=QUX)")
189
- def naas(env: list[str]):
190
- configuration: EngineConfiguration = EngineConfiguration.load_configuration()
191
-
192
- if configuration.deploy is None:
193
- logger.error(
194
- "Deploy configuration not found in the yaml configuration file. Please add a deploy section to the configuration file."
195
- )
196
-
197
- deployer = NaasDeployer(configuration)
198
- deployer.deploy(env)
naas_abi_core/cli/init.py DELETED
@@ -1,13 +0,0 @@
1
- import os
2
-
3
- import click
4
-
5
-
6
- @click.command("init")
7
- @click.argument("path")
8
- def init(path: str):
9
- if path == ".":
10
- path = os.getcwd()
11
-
12
- os.makedirs(path, exist_ok=True)
13
- # os.exec(f"cd {path} && uv init .")
@@ -1,28 +0,0 @@
1
- import click
2
- from naas_abi_core.engine.engine_configuration.EngineConfiguration import (
3
- EngineConfiguration,
4
- )
5
- from rich.console import Console
6
- from rich.table import Table
7
-
8
-
9
- @click.group("module")
10
- def module():
11
- pass
12
-
13
-
14
- @module.command("list")
15
- def list() -> None:
16
- configuration: EngineConfiguration = EngineConfiguration.load_configuration()
17
-
18
- console = Console()
19
- table = Table(
20
- title="Available Modules", show_header=True, header_style="bold magenta"
21
- )
22
- table.add_column("Module", style="cyan", no_wrap=True)
23
- table.add_column("Enabled", style="green")
24
-
25
- for module in configuration.modules:
26
- table.add_row(module.module, str(module.enabled))
27
-
28
- console.print(table)
naas_abi_core/cli/new.py DELETED
@@ -1,13 +0,0 @@
1
- import click
2
-
3
-
4
- @click.group("new")
5
- def new():
6
- pass
7
-
8
-
9
- @new.command("module")
10
- @click.argument("module-name")
11
- @click.argument("module-path")
12
- def new_module(module_name: str, module_path: str):
13
- print(f"Creating a new module: {module_name} at {module_path}")
@@ -1,79 +0,0 @@
1
- import os
2
-
3
- import click
4
-
5
-
6
- @click.group("secrets")
7
- def secrets():
8
- pass
9
-
10
-
11
- @secrets.group("naas")
12
- def naas():
13
- pass
14
-
15
-
16
- @naas.command("push-env-as-base64")
17
- @click.option(
18
- "--naas-api-key", type=str, required=True, default=os.getenv("NAAS_API_KEY")
19
- )
20
- @click.option("--naas-api-url", type=str, required=True, default="https://api.naas.ai")
21
- @click.option("--naas-secret-name", type=str, required=True, default="abi_secrets")
22
- @click.option("--env-file", type=str, required=True, default=".env.prod")
23
- def push_env_to_naas(naas_api_key, naas_api_url, naas_secret_name, env_file):
24
- import base64
25
-
26
- from naas_abi_core.services.secret.adaptors.secondary.NaasSecret import NaasSecret
27
-
28
- naas_secret = NaasSecret(naas_api_key, naas_api_url)
29
-
30
- envfile_content = ""
31
-
32
- with open(env_file, "r") as envfile:
33
- envfile_content = envfile.read()
34
-
35
- print(envfile_content)
36
-
37
- base64_content = base64.b64encode(envfile_content.encode("utf-8")).decode("utf-8")
38
- naas_secret.set(naas_secret_name, base64_content)
39
-
40
- print(f"Pushed {env_file} to Naas as base64 secret {naas_secret_name}")
41
-
42
-
43
- @naas.command("list")
44
- @click.option(
45
- "--naas-api-key", type=str, required=True, default=os.getenv("NAAS_API_KEY")
46
- )
47
- @click.option("--naas-api-url", type=str, required=True, default="https://api.naas.ai")
48
- def list_secrets(naas_api_key, naas_api_url):
49
- from naas_abi_core.services.secret.adaptors.secondary.NaasSecret import NaasSecret
50
-
51
- naas_secret = NaasSecret(naas_api_key, naas_api_url)
52
-
53
- naas_secret.list()
54
-
55
- for key, value in naas_secret.list().items():
56
- print(f"{key}: {value}")
57
-
58
-
59
- @naas.command("get-base64-env")
60
- @click.option(
61
- "--naas-api-key", type=str, required=True, default=os.getenv("NAAS_API_KEY")
62
- )
63
- @click.option("--naas-api-url", type=str, required=True, default="https://api.naas.ai")
64
- @click.option("--naas-secret-name", type=str, required=True, default="abi_secrets")
65
- def get_secret(naas_api_key, naas_api_url, naas_secret_name):
66
- from naas_abi_core.services.secret.adaptors.secondary.Base64Secret import (
67
- Base64Secret,
68
- )
69
- from naas_abi_core.services.secret.adaptors.secondary.NaasSecret import NaasSecret
70
-
71
- naas_secret = NaasSecret(naas_api_key, naas_api_url)
72
- base64_secret = Base64Secret(naas_secret, naas_secret_name)
73
-
74
- for key, value in base64_secret.list().items():
75
- # If value is multiline
76
- if "\n" in value:
77
- print(f'{key}="{value}"')
78
- else:
79
- print(f"{key}={value}")