Refactor the code directory structure to better suit the current complexity
This commit is contained in:
@@ -11,7 +11,6 @@ from logging.handlers import RotatingFileHandler
|
||||
from typing import Any, Optional, TypeVar, Tuple, Sequence
|
||||
import argparse
|
||||
|
||||
|
||||
from prompt_toolkit import HTML, PromptSession, prompt,print_formatted_text
|
||||
from prompt_toolkit.formatted_text import FormattedText
|
||||
from prompt_toolkit.selection import SelectionState
|
||||
@@ -20,8 +19,6 @@ from prompt_toolkit.auto_suggest import AutoSuggestFromHistory
|
||||
from prompt_toolkit.completion import WordCompleter
|
||||
from prompt_toolkit.styles import Style
|
||||
|
||||
|
||||
|
||||
directory = os.path.dirname(__file__)
|
||||
sys.path.append(directory + '/../../')
|
||||
|
||||
@@ -30,15 +27,23 @@ sys.path.append(directory + '/../../')
|
||||
# os.environ['HTTPS_PROXY'] = '127.0.0.1:10809'
|
||||
|
||||
import proxy
|
||||
from aios_kernel import *
|
||||
from knowledge import *
|
||||
|
||||
|
||||
from aios import *
|
||||
|
||||
sys.path.append(directory + '/../../component/')
|
||||
|
||||
from google_node import *
|
||||
from llama_node import *
|
||||
from openai_node import *
|
||||
from sd_node import *
|
||||
from st_node import *
|
||||
|
||||
from agent_manager import AgentManager
|
||||
from workflow_manager import WorkflowManager
|
||||
from knowledge_manager import KnowledgePipelineManager
|
||||
from tg_tunnel import TelegramTunnel
|
||||
from email_tunnel import EmailTunnel
|
||||
|
||||
from compute_node_config import *
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
"""
|
||||
compute node config
|
||||
Configuration for nodes:
|
||||
|
||||
```
|
||||
├── nodes
|
||||
│ └── llama
|
||||
| └── 0
|
||||
| | └── url
|
||||
| | └── model_name
|
||||
| └── 1
|
||||
| └── url
|
||||
| └── model_name
|
||||
```
|
||||
"""
|
||||
import logging
|
||||
from typing import List
|
||||
import sys
|
||||
|
||||
import os
|
||||
import toml
|
||||
|
||||
|
||||
from aios import AIStorage
|
||||
directory = os.path.dirname(__file__)
|
||||
sys.path.append(directory + '/../../component/')
|
||||
|
||||
from llama_node import LocalLlama_ComputeNode
|
||||
|
||||
|
||||
# define singleton class knowledge pipline
|
||||
class ComputeNodeConfig:
|
||||
_instance = None
|
||||
|
||||
@classmethod
|
||||
def get_instance(cls):
|
||||
if cls._instance is None:
|
||||
cls._instance = ComputeNodeConfig()
|
||||
cls._instance.__singleton_init__()
|
||||
|
||||
return cls._instance
|
||||
|
||||
def initial(self) -> List[LocalLlama_ComputeNode]:
|
||||
config_path = self.__config_path()
|
||||
logging.info(f"initial nodes from {config_path}")
|
||||
|
||||
if os.path.exists(config_path):
|
||||
self.config = toml.load(self.__config_path())
|
||||
if self.config is None:
|
||||
return []
|
||||
|
||||
nodes = []
|
||||
llama_nodes_cfg = self.config["llama"]
|
||||
if llama_nodes_cfg is not None:
|
||||
for cfg in llama_nodes_cfg:
|
||||
node = LocalLlama_ComputeNode(url=cfg["url"], model_name=cfg["model_name"])
|
||||
nodes.append(node)
|
||||
|
||||
return nodes
|
||||
|
||||
return []
|
||||
|
||||
def save(self):
|
||||
with open(self.__config_path(), "w") as f:
|
||||
toml.dump(self.config, f)
|
||||
|
||||
def add_node(self, model_type: str, url: str, model_name: str):
|
||||
if model_type == "llama":
|
||||
llama_nodes_cfg = self.config.get("llama") or []
|
||||
for cfg in llama_nodes_cfg:
|
||||
if url == cfg["url"] and model_name == cfg["model_name"]:
|
||||
return
|
||||
llama_nodes_cfg.append({"url": url, "model_name": model_name})
|
||||
self.config["llama"] = llama_nodes_cfg
|
||||
|
||||
|
||||
def remove_node(self, model_type: str, url: str, model_name: str):
|
||||
if model_type == "llama":
|
||||
llama_nodes_cfg = self.config.get("llama") or []
|
||||
i = 0
|
||||
for cfg in llama_nodes_cfg:
|
||||
if url == cfg["url"] and model_name == cfg["model_name"]:
|
||||
llama_nodes_cfg.pop(i)
|
||||
else:
|
||||
i += 1
|
||||
|
||||
def list(self) -> str:
|
||||
return toml.dumps(self.config)
|
||||
|
||||
def __singleton_init__(self):
|
||||
self.config = {}
|
||||
|
||||
@classmethod
|
||||
def __config_path(cls) -> str:
|
||||
user_data_dir = AIStorage.get_instance().get_myai_dir()
|
||||
return os.path.abspath(f"{user_data_dir}/etc/compute_nodes.cfg.toml")
|
||||
@@ -9,7 +9,7 @@ import logging
|
||||
directory = os.path.dirname(__file__)
|
||||
sys.path.append(directory + '/../../')
|
||||
|
||||
from aios_kernel import AIStorage
|
||||
from aios import AIStorage
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user