complete ai kerne frame code
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
from typing import Optional
|
||||
import logging
|
||||
import llm_kernel,llm_work_task
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
||||
class agent_msg:
|
||||
def __init__(self) -> None:
|
||||
pass
|
||||
|
||||
class agent_prompt:
|
||||
def __init__(self) -> None:
|
||||
pass
|
||||
|
||||
def as_str()->str:
|
||||
pass
|
||||
|
||||
class agent_chat_session:
|
||||
def __init__(self) -> None:
|
||||
self.llm_model_name = None
|
||||
self.llm_instance = None
|
||||
self.max_token_size = 0
|
||||
self.chat_msg_list = None
|
||||
self.enable_function = True
|
||||
|
||||
pass
|
||||
|
||||
def chat(self,message:str) -> None:
|
||||
pass
|
||||
# Key functions, let the AI Agent try to run.
|
||||
def completion(self)->llm_work_task:
|
||||
if self.llm_instance is None:
|
||||
self.llm_instance = llm_kernel.craete(self.llm_model_name)
|
||||
if self.llm_instance is None:
|
||||
logger.fatal(f"cann't get llm_kerenel : {self.llm_model_name}")
|
||||
return
|
||||
|
||||
llm_work_task = self.llm_instance.completion(self._get_prompt(),self.max_token_size)
|
||||
return llm_work_task
|
||||
|
||||
def _get_prompt(str) -> str:
|
||||
pass
|
||||
|
||||
class ai_agent:
|
||||
def __init__(self) -> None:
|
||||
pass
|
||||
|
||||
def get_chat_session(self,chat_user_name:str,session_id:Optional[str]) -> agent_chat_session:
|
||||
pass
|
||||
|
||||
|
||||
|
||||
#chat_session = agent.get_default_chat_session("master");
|
||||
#chat_session.chat("给我讲一个英文笑话!");
|
||||
#chat_session.completion();
|
||||
#print(chat_session.last_msg());
|
||||
@@ -0,0 +1,20 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Any
|
||||
from .agent import agent,agent_msg
|
||||
|
||||
class ai_role:
|
||||
def __init__(self) -> None:
|
||||
pass
|
||||
|
||||
class agent_group:
|
||||
def __init__(self) -> None:
|
||||
self.roles = None
|
||||
pass
|
||||
|
||||
def add_role(self,role_name:str,agent_id:str) -> None:
|
||||
pass
|
||||
|
||||
def send_msg(self,role_name:str,msg:agent_msg) -> None:
|
||||
pass
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
from .workflow import ai_workflow
|
||||
from agent import agent_msg
|
||||
class aios_shell:
|
||||
def send_msg(self,msg:agent_msg,target:ai_workflow) -> None:
|
||||
pass
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
from compute_node import compute_node
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
# How to dispatch different computing tasks (some tasks may contain a large amount of state for correct execution)
|
||||
# to suitable computing nodes, achieving a balance of speed, cost, and power consumption,
|
||||
# is the CORE GOAL of the entire computing task schedule system (aios_kernel).
|
||||
class compute_task(ABC):
|
||||
@abstractmethod
|
||||
def display(self) -> str:
|
||||
pass
|
||||
|
||||
|
||||
class compute_kernel:
|
||||
def __init__(self) -> None:
|
||||
pass
|
||||
|
||||
def run(self,task:compute_task) -> None:
|
||||
# check there is compute node can support this task
|
||||
# add task to working_queue
|
||||
pass
|
||||
|
||||
def start(self):
|
||||
pass
|
||||
|
||||
def add_compute_node(self,node:compute_node):
|
||||
pass
|
||||
|
||||
def disable_compute_node(self,):
|
||||
pass
|
||||
@@ -0,0 +1,13 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class compute_node(ABC):
|
||||
@abstractmethod
|
||||
def display(self) -> str:
|
||||
pass
|
||||
|
||||
class local_compute_node(compute_node):
|
||||
def display(self) -> str:
|
||||
return super().display()
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
class environment_event(ABC):
|
||||
@abstractmethod
|
||||
def display(self) -> str:
|
||||
pass
|
||||
|
||||
|
||||
class environment:
|
||||
def __init__(self) -> None:
|
||||
pass
|
||||
|
||||
def event_to_msg(self,) -> environment_event:
|
||||
pass
|
||||
@@ -0,0 +1,14 @@
|
||||
|
||||
class llm_work_task:
|
||||
def __init__(self) -> None:
|
||||
pass
|
||||
|
||||
|
||||
class llm_kernel:
|
||||
def __init__(self) -> None:
|
||||
pass
|
||||
def completion(self,prompt:str,max_token:int) -> llm_work_task:
|
||||
# craete a llm_work_task ,push on queue's end
|
||||
# then task_schedule would run this task.(might schedule some work_task to another host)
|
||||
pass
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
from compute_node import compute_node
|
||||
|
||||
class open_ai_compute_node(compute_node):
|
||||
def display(self) -> str:
|
||||
return super().display()
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import environment
|
||||
import agent_prompt,agent_msg
|
||||
|
||||
class ai_workflow:
|
||||
def __init__(self) -> None:
|
||||
self.rule_prompt : agent_prompt = None
|
||||
self.workflow_config = None
|
||||
self.context = None
|
||||
|
||||
def load_from_disk(self,config_path:str,context_dir_path) -> int:
|
||||
pass
|
||||
|
||||
def send_msg(self,msg:agent_msg,target_group:str = None) -> None:
|
||||
if target_group is None:
|
||||
target_group = self.get_default_group()
|
||||
pass
|
||||
|
||||
def run(self):
|
||||
|
||||
pass
|
||||
|
||||
def _pop_msg(self) -> Tuple[agent_msg,str]:
|
||||
pass
|
||||
|
||||
def get_default_group(self) -> agent_group:
|
||||
pass
|
||||
|
||||
def get_group(self,group_name:str) -> agent_group:
|
||||
pass
|
||||
|
||||
def get_workflow_rule_prompt(self) -> agent_prompt:
|
||||
return self.rule_prompt
|
||||
|
||||
def get_inner_environment(self) -> environment:
|
||||
pass
|
||||
|
||||
def connect_to_environment(self,env:environment) -> None:
|
||||
pass
|
||||
@@ -1,3 +0,0 @@
|
||||
class ai_agent:
|
||||
def __init__(self) -> None:
|
||||
pass
|
||||
@@ -1,11 +1,19 @@
|
||||
|
||||
import logging
|
||||
import toml
|
||||
|
||||
from .agent import ai_agent
|
||||
from .templete import ai_agent_templete
|
||||
from package_manager import pkg_env,pkg_env_mgr,pkg_media_info,media_reader,pkg_install_task
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class agent_manager:
|
||||
_instance = None
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.loaded_agent_instance = {}
|
||||
pass
|
||||
|
||||
def __new__(cls):
|
||||
@@ -15,22 +23,51 @@ class agent_manager:
|
||||
|
||||
|
||||
def initial(self,root_dir:str) -> None:
|
||||
pass
|
||||
self.agent_templete_env : pkg_env = pkg_env_mgr().get_env(f"{root_dir}templetes/agent_templetes.cfg")
|
||||
self.agent_env : pkg_env = pkg_env_mgr().get_env(f"{root_dir}agents/agents.cfg")
|
||||
if self.agent_templete_env is None:
|
||||
raise Exception("agent_manager initial failed")
|
||||
|
||||
|
||||
|
||||
def get(self,agent_id) -> ai_agent:
|
||||
pass
|
||||
def get(self,agent_id:str) -> ai_agent:
|
||||
the_agent = self.loaded_agent_instance.get(agent_id)
|
||||
if the_agent:
|
||||
return the_agent
|
||||
|
||||
# try load from disk
|
||||
agent_media_info = self.agent_env.load(agent_id)
|
||||
if agent_media_info is None:
|
||||
return None
|
||||
|
||||
the_agent = self._load_agent_from_media(agent_media_info)
|
||||
if the_agent is None:
|
||||
logger.warn(f"load agent {agent_id} from media failed!")
|
||||
|
||||
return the_agent
|
||||
|
||||
|
||||
def remove(self,agent_id:str)->int:
|
||||
pass
|
||||
|
||||
def get_templete(self,templete_id) -> ai_agent_templete:
|
||||
template_media_info = self.agent_templete_env.get(templete_id)
|
||||
if template_media_info is None:
|
||||
return None
|
||||
return self._load_templete_from_media(template_media_info)
|
||||
|
||||
def install(self,templete_id) -> pkg_install_task:
|
||||
installer = self.agent_templete_env.get_installer()
|
||||
return installer.install(templete_id)
|
||||
|
||||
def uninstall(self,templete_id) -> int:
|
||||
pass
|
||||
|
||||
def _load_templete_from_media(self,templete_media:pkg_media_info) -> ai_agent_templete:
|
||||
pass
|
||||
|
||||
def install(self,templete_id) -> int:
|
||||
|
||||
installer = None
|
||||
#installer.install(templete_id)
|
||||
def _load_agent_from_media(self,agent_media:pkg_media_info) -> ai_agent:
|
||||
pass
|
||||
|
||||
|
||||
def create(self,template,agent_name,agent_last_name,agent_introduce) -> ai_agent:
|
||||
pass
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
from .env import pkg_env_mgr,pkg_env
|
||||
from .pkg import pkg_info,pkg_media_info
|
||||
from .installer import pkg_install_task
|
||||
@@ -19,7 +19,7 @@ INSTALL_TASK_STATE_DOWNLOADING = 3
|
||||
INSTALL_TASK_STATE_INSTALLING = 4
|
||||
INSTALL_TAKS_STATE_ERROR = 5
|
||||
|
||||
class install_task:
|
||||
class pkg_install_task:
|
||||
def __init__(self,owner:pkg_env) -> None:
|
||||
self.owner = owner
|
||||
self.state = INSTALL_TASK_STATE_CHECK_DEPENDENCY
|
||||
@@ -35,7 +35,7 @@ class pkg_installer:
|
||||
self.owner_env = owner_env
|
||||
|
||||
def install(self,pkg_name:str,
|
||||
install_from_dependency = False, can_upgrade = True,skip_depends = False,options = None)->Tuple[install_task,str]:
|
||||
install_from_dependency = False, can_upgrade = True,skip_depends = False,options = None)->Tuple[pkg_install_task,str]:
|
||||
|
||||
the_pkg_info : pkg_info = None
|
||||
is_upgrade : bool = False
|
||||
@@ -74,7 +74,7 @@ class pkg_installer:
|
||||
return result_task,"already installing"
|
||||
|
||||
logger.info(f"start download&install {pkg_name},install_from_dependency={install_from_dependency},upgrade={is_upgrade},backup={need_backup},target_pkg_info={the_pkg_info}")
|
||||
result_task = install_task()
|
||||
result_task = pkg_install_task()
|
||||
self.all_tasks[the_pkg_info.cid] = result_task
|
||||
async def download_and_install_pkg()->int:
|
||||
# check dependency
|
||||
@@ -149,7 +149,7 @@ class pkg_installer:
|
||||
if depend_task is not None:
|
||||
logger.debug(f"{pkg.name}'s depend pkg {depend_pkg_name} already in task list")
|
||||
continue
|
||||
depend_task = install_task()
|
||||
depend_task = pkg_install_task()
|
||||
task_list[depend_pkg_name] = depend_task
|
||||
|
||||
depend_pkg_info = self.owner_env.lookup(depend_pkg_name)
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
class media_reader:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def load_from_media(self,media_info:str) -> int:
|
||||
pass
|
||||
|
||||
def read(self, inner_path:str):
|
||||
raise NotImplementedError
|
||||
@@ -9,12 +9,13 @@ class pkg_info:
|
||||
self.target_media_type = "dir"
|
||||
self.source_media_type = "7z"
|
||||
|
||||
|
||||
|
||||
def parse_pkg_name(pkg_name:str) -> Tuple[str, str, str]:
|
||||
#return pkg_id,version_str,cid
|
||||
@classmethod
|
||||
def parse_pkg_name(cls,pkg_name:str) -> Tuple[str, str, str]:
|
||||
"""parse pkg name like test-pkg#nightly#>0.2.31#sha1:323423423 to test-pkg,nightly#>0.2.31,sha1:323423423"""
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@property
|
||||
def cid(self) -> str:
|
||||
return self.cid
|
||||
|
||||
Reference in New Issue
Block a user