fix bugs~
This commit is contained in:
@@ -2,7 +2,6 @@ instance_id = "Jarvis"
|
|||||||
fullname = "Jarvis"
|
fullname = "Jarvis"
|
||||||
llm_model_name = "gpt-3.5-turbo-16k-0613"
|
llm_model_name = "gpt-3.5-turbo-16k-0613"
|
||||||
max_token_size = 16000
|
max_token_size = 16000
|
||||||
#enable_function =["add_event"]
|
|
||||||
#enable_kb = "true"
|
#enable_kb = "true"
|
||||||
enable_timestamp = "true"
|
enable_timestamp = "true"
|
||||||
owner_prompt = "我是你的主人{name}"
|
owner_prompt = "我是你的主人{name}"
|
||||||
@@ -26,7 +25,10 @@ David,私人画家
|
|||||||
消息内容
|
消息内容
|
||||||
```
|
```
|
||||||
2.你可以访问我的Calender,查看我的日程安排。如果你在处理信息的过程中需要修改我的日程安排,请直接用合适的方法修改。
|
2.你可以访问我的Calender,查看我的日程安排。如果你在处理信息的过程中需要修改我的日程安排,请直接用合适的方法修改。
|
||||||
3.你可以访问我的个人信息库,当你处理我的信息时,如果需要用到我的个人信息,请先用合适的方法进行查询,然后再基于查询的结果进行进一步处理后再将结果发给我。
|
3.不符合上述规则的信息,请尽力处理。
|
||||||
4.你能根据我的需要对系统进行配置,但在修改任何配置前,请先和我确认。
|
|
||||||
5.不符合上述规则的信息,请尽力处理。
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
#3.你可以访问我的个人信息库,当你处理我的信息时,如果需要用到我的个人信息,请先用合适的方法进行查询,然后再基于查询的结果进行进一步处理后再将结果发给我。
|
||||||
|
#4.你能根据我的需要对系统进行配置,但在修改任何配置前,请先和我确认。
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
from .environment import Environment,EnvironmentEvent
|
from .environment import Environment,EnvironmentEvent
|
||||||
from .agent_message import AgentMsg,AgentMsgStatus
|
from .agent_message import AgentMsg,AgentMsgStatus,AgentMsgType
|
||||||
from .chatsession import AIChatSession
|
from .chatsession import AIChatSession
|
||||||
from .agent import AIAgent,AIAgentTemplete,AgentPrompt
|
from .agent import AIAgent,AIAgentTemplete,AgentPrompt
|
||||||
from .compute_kernel import ComputeKernel,ComputeTask
|
from .compute_kernel import ComputeKernel,ComputeTask,ComputeTaskResult,ComputeTaskState,ComputeTaskType
|
||||||
from .compute_node import ComputeNode,LocalComputeNode
|
from .compute_node import ComputeNode,LocalComputeNode
|
||||||
from .open_ai_node import OpenAI_ComputeNode
|
from .open_ai_node import OpenAI_ComputeNode
|
||||||
from .knowledge_base import KnowledgeBase
|
from .knowledge_base import KnowledgeBase
|
||||||
@@ -24,5 +24,5 @@ from .workspace_env import WorkspaceEnvironment
|
|||||||
from .local_stability_node import Local_Stability_ComputeNode
|
from .local_stability_node import Local_Stability_ComputeNode
|
||||||
from .stability_node import Stability_ComputeNode
|
from .stability_node import Stability_ComputeNode
|
||||||
|
|
||||||
AIOS_Version = "0.5.1, build 2023-9-17"
|
AIOS_Version = "0.5.1, build 2023-9-26"
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ class AgentMsgType(Enum):
|
|||||||
TYPE_INTERNAL_CALL = 1
|
TYPE_INTERNAL_CALL = 1
|
||||||
TYPE_ACTION = 2
|
TYPE_ACTION = 2
|
||||||
TYPE_EVENT = 3
|
TYPE_EVENT = 3
|
||||||
|
TYPE_SYSTEM = 4
|
||||||
|
|
||||||
class AgentMsgStatus(Enum):
|
class AgentMsgStatus(Enum):
|
||||||
RESPONSED = 0
|
RESPONSED = 0
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ class AIBus:
|
|||||||
|
|
||||||
retry_times = 0
|
retry_times = 0
|
||||||
while True:
|
while True:
|
||||||
resp = sender_handler.results.get(msg.msg_id)
|
resp : AgentMsg = sender_handler.results.get(msg.msg_id)
|
||||||
if resp is not None:
|
if resp is not None:
|
||||||
msg.resp_msg = resp
|
msg.resp_msg = resp
|
||||||
msg.status = AgentMsgStatus.RESPONSED
|
msg.status = AgentMsgStatus.RESPONSED
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ from asyncio import Queue
|
|||||||
|
|
||||||
from .agent import AgentPrompt
|
from .agent import AgentPrompt
|
||||||
from .compute_node import ComputeNode
|
from .compute_node import ComputeNode
|
||||||
from .compute_task import ComputeTask, ComputeTaskState, ComputeTaskResult, ComputeTaskType
|
from .compute_task import ComputeTask, ComputeTaskState, ComputeTaskResult, ComputeTaskType,ComputeTaskResultCode
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -106,9 +106,7 @@ class ComputeKernel:
|
|||||||
self.run(task_req)
|
self.run(task_req)
|
||||||
return task_req
|
return task_req
|
||||||
|
|
||||||
async def do_llm_completion(self, prompt: AgentPrompt, mode_name: Optional[str] = None, max_token: int = 0, inner_functions = None) -> str:
|
async def _send_task(self,task_req:ComputeTask)->ComputeTaskResult:
|
||||||
task_req = self.llm_completion(prompt, mode_name, max_token,inner_functions)
|
|
||||||
|
|
||||||
async def check_timer():
|
async def check_timer():
|
||||||
check_times = 0
|
check_times = 0
|
||||||
while True:
|
while True:
|
||||||
@@ -126,10 +124,18 @@ class ComputeKernel:
|
|||||||
check_times += 1
|
check_times += 1
|
||||||
|
|
||||||
await asyncio.create_task(check_timer())
|
await asyncio.create_task(check_timer())
|
||||||
if task_req.state == ComputeTaskState.DONE:
|
if task_req.result:
|
||||||
return task_req.result
|
return task_req.result
|
||||||
|
else:
|
||||||
|
time_out_result = ComputeTaskResult()
|
||||||
|
time_out_result.result_code = ComputeTaskResultCode.TIMEOUT
|
||||||
|
time_out_result.set_from_task(task_req)
|
||||||
|
## craete timeout task_result
|
||||||
|
|
||||||
|
async def do_llm_completion(self, prompt: AgentPrompt, mode_name: Optional[str] = None, max_token: int = 0, inner_functions = None) -> str:
|
||||||
|
task_req = self.llm_completion(prompt, mode_name, max_token,inner_functions)
|
||||||
|
return await self._send_task(task_req)
|
||||||
|
|
||||||
raise Exception("error!")
|
|
||||||
|
|
||||||
|
|
||||||
def text_embedding(self,input:str,model_name:Optional[str] = None):
|
def text_embedding(self,input:str,model_name:Optional[str] = None):
|
||||||
@@ -140,25 +146,10 @@ class ComputeKernel:
|
|||||||
|
|
||||||
async def do_text_embedding(self,input:str,model_name:Optional[str] = None) -> [float]:
|
async def do_text_embedding(self,input:str,model_name:Optional[str] = None) -> [float]:
|
||||||
task_req = self.text_embedding(input,model_name)
|
task_req = self.text_embedding(input,model_name)
|
||||||
async def check_timer():
|
task_result = await self._send_task(task_req)
|
||||||
check_times = 0
|
|
||||||
while True:
|
|
||||||
if task_req.state == ComputeTaskState.DONE:
|
|
||||||
break
|
|
||||||
|
|
||||||
if task_req.state == ComputeTaskState.ERROR:
|
|
||||||
break
|
|
||||||
|
|
||||||
if check_times >= 20:
|
|
||||||
task_req.state = ComputeTaskState.ERROR
|
|
||||||
break
|
|
||||||
|
|
||||||
await asyncio.sleep(0.5)
|
|
||||||
check_times += 1
|
|
||||||
|
|
||||||
await asyncio.create_task(check_timer())
|
|
||||||
if task_req.state == ComputeTaskState.DONE:
|
if task_req.state == ComputeTaskState.DONE:
|
||||||
return task_req.result.result
|
return task_result.result
|
||||||
|
|
||||||
return "error!"
|
return "error!"
|
||||||
|
|
||||||
@@ -179,22 +170,10 @@ class ComputeKernel:
|
|||||||
task_req.task_type = ComputeTaskType.TEXT_2_VOICE
|
task_req.task_type = ComputeTaskType.TEXT_2_VOICE
|
||||||
self.run(task_req)
|
self.run(task_req)
|
||||||
|
|
||||||
check_times = 0
|
task_result = await self._send_task(task_req)
|
||||||
while True:
|
|
||||||
if task_req.state == ComputeTaskState.DONE:
|
|
||||||
break
|
|
||||||
if task_req.state == ComputeTaskState.ERROR:
|
|
||||||
break
|
|
||||||
if check_times >= 60:
|
|
||||||
task_req.state = ComputeTaskState.ERROR
|
|
||||||
break
|
|
||||||
await asyncio.sleep(0.5)
|
|
||||||
check_times += 1
|
|
||||||
|
|
||||||
if task_req.state == ComputeTaskState.DONE:
|
if task_req.state == ComputeTaskState.DONE:
|
||||||
return task_req.result.result
|
return task_result.result
|
||||||
else:
|
|
||||||
raise Exception("do_text_to_speech failed!")
|
|
||||||
|
|
||||||
|
|
||||||
def text_2_image(self, prompt:str, model_name:Optional[str] = None):
|
def text_2_image(self, prompt:str, model_name:Optional[str] = None):
|
||||||
@@ -205,27 +184,9 @@ class ComputeKernel:
|
|||||||
|
|
||||||
async def do_text_2_image(self, prompt:str, model_name:Optional[str] = None) -> [str, ComputeTaskResult]:
|
async def do_text_2_image(self, prompt:str, model_name:Optional[str] = None) -> [str, ComputeTaskResult]:
|
||||||
task_req = self.text_2_image(prompt,model_name)
|
task_req = self.text_2_image(prompt,model_name)
|
||||||
async def check_timer():
|
task_result = self._send_task(task_req)
|
||||||
check_times = 0
|
|
||||||
while True:
|
|
||||||
if task_req.state == ComputeTaskState.DONE:
|
|
||||||
break
|
|
||||||
|
|
||||||
if task_req.state == ComputeTaskState.ERROR:
|
|
||||||
break
|
|
||||||
|
|
||||||
#may be it will take a long time to generate a image
|
|
||||||
if check_times >= 60:
|
|
||||||
task_req.state = ComputeTaskState.ERROR
|
|
||||||
break
|
|
||||||
|
|
||||||
await asyncio.sleep(0.5)
|
|
||||||
check_times += 1
|
|
||||||
|
|
||||||
await asyncio.create_task(check_timer())
|
|
||||||
|
|
||||||
if task_req.state == ComputeTaskState.DONE:
|
if task_req.state == ComputeTaskState.DONE:
|
||||||
return None, task_req.result
|
return None, task_result
|
||||||
|
|
||||||
return task_req.error_str, None
|
return task_req.error_str, None
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,11 @@ from enum import Enum
|
|||||||
import uuid
|
import uuid
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
class ComputeTaskResultCode(Enum):
|
||||||
|
OK = 0
|
||||||
|
TIMEOUT = 1
|
||||||
|
NO_WORK = 2
|
||||||
|
|
||||||
|
|
||||||
class ComputeTaskState(Enum):
|
class ComputeTaskState(Enum):
|
||||||
DONE = 0
|
DONE = 0
|
||||||
@@ -95,3 +100,4 @@ class ComputeTaskResult:
|
|||||||
def set_from_task(self, task: ComputeTask):
|
def set_from_task(self, task: ComputeTask):
|
||||||
self.task_id = task.task_id
|
self.task_id = task.task_id
|
||||||
self.callchain_id = task.callchain_id
|
self.callchain_id = task.callchain_id
|
||||||
|
task.result = self
|
||||||
|
|||||||
@@ -92,14 +92,16 @@ class UserConfig:
|
|||||||
def get_config_item(self,key:str) -> Any:
|
def get_config_item(self,key:str) -> Any:
|
||||||
config_item = self.config_table.get(key)
|
config_item = self.config_table.get(key)
|
||||||
if config_item is None:
|
if config_item is None:
|
||||||
raise Exception("user config key %s not exist",key)
|
logger.warning(f"user config key {key} not exist")
|
||||||
|
return None
|
||||||
|
|
||||||
return config_item
|
return config_item
|
||||||
|
|
||||||
def get_value(self,key:str)->Any:
|
def get_value(self,key:str)->Any:
|
||||||
config_item = self.config_table.get(key)
|
config_item = self.config_table.get(key)
|
||||||
if config_item is None:
|
if config_item is None:
|
||||||
raise Exception("user config key %s not exist",key)
|
logger.warning(f"user config key {key} not exist")
|
||||||
|
return None
|
||||||
|
|
||||||
if config_item.value is None:
|
if config_item.value is None:
|
||||||
return config_item.default_value
|
return config_item.default_value
|
||||||
|
|||||||
@@ -32,10 +32,13 @@ class TelegramTunnel(AgentTunnel):
|
|||||||
|
|
||||||
|
|
||||||
async def load_from_config(self,config:dict)->bool:
|
async def load_from_config(self,config:dict)->bool:
|
||||||
|
self.type = "TelegramTunnel"
|
||||||
self.tg_token = config["token"]
|
self.tg_token = config["token"]
|
||||||
self.target_id = config["target"]
|
self.target_id = config["target"]
|
||||||
self.tunnel_id = config["tunnel_id"]
|
self.tunnel_id = config["tunnel_id"]
|
||||||
self.type = "TelegramTunnel"
|
if config.get("allow") is not None:
|
||||||
|
self.allow_group = config["allow"]
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def dump_to_config(self) -> dict:
|
def dump_to_config(self) -> dict:
|
||||||
@@ -47,6 +50,7 @@ class TelegramTunnel(AgentTunnel):
|
|||||||
self.tg_token = tg_token
|
self.tg_token = tg_token
|
||||||
self.bot:Bot = None
|
self.bot:Bot = None
|
||||||
self.update_queue = None
|
self.update_queue = None
|
||||||
|
self.allow_group = "contact"
|
||||||
|
|
||||||
async def _do_process_raw_message(self,bot: Bot, update_id: int) -> int:
|
async def _do_process_raw_message(self,bot: Bot, update_id: int) -> int:
|
||||||
# Request updates after the last update_id
|
# Request updates after the last update_id
|
||||||
@@ -88,6 +92,11 @@ class TelegramTunnel(AgentTunnel):
|
|||||||
except Forbidden:
|
except Forbidden:
|
||||||
# The user has removed or blocked the bot.
|
# The user has removed or blocked the bot.
|
||||||
update_id += 1
|
update_id += 1
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"tg_tunnel error:{e}")
|
||||||
|
await asyncio.sleep(1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
asyncio.create_task(_run_app())
|
asyncio.create_task(_run_app())
|
||||||
logger.info(f"tunnel {self.tunnel_id} started.")
|
logger.info(f"tunnel {self.tunnel_id} started.")
|
||||||
@@ -130,7 +139,16 @@ class TelegramTunnel(AgentTunnel):
|
|||||||
|
|
||||||
if contact is not None:
|
if contact is not None:
|
||||||
reomte_user_name = contact.name
|
reomte_user_name = contact.name
|
||||||
|
if not contact.is_family_member:
|
||||||
|
if self.allow_group != "contact" and self.allow_group !="guest":
|
||||||
|
await update.message.reply_text(f"You are not allowed to talk to me! Please contact my father~")
|
||||||
|
return
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
if self.allow_group != "guest":
|
||||||
|
await update.message.reply_text(f"You are not allowed to talk to me! Please contact my father~")
|
||||||
|
return
|
||||||
|
|
||||||
if cm.is_auto_create_contact_from_telegram:
|
if cm.is_auto_create_contact_from_telegram:
|
||||||
contact_name = update.effective_user.first_name
|
contact_name = update.effective_user.first_name
|
||||||
if update.effective_user.last_name is not None:
|
if update.effective_user.last_name is not None:
|
||||||
|
|||||||
+81
-81
@@ -1,89 +1,89 @@
|
|||||||
aiofiles==23.2.1
|
aiofiles>=23.2.1
|
||||||
aiohttp==3.8.5
|
aiohttp>=3.8.5
|
||||||
aioimaplib==1.0.1
|
aioimaplib>=1.0.1
|
||||||
aiosignal==1.3.1
|
aiosignal>=1.3.1
|
||||||
aiosmtplib==2.0.2
|
aiosmtplib>=2.0.2
|
||||||
anyio==4.0.0
|
anyio>=4.0.0
|
||||||
async-timeout==4.0.3
|
async-timeout>=4.0.3
|
||||||
attrs==23.1.0
|
attrs>=23.1.0
|
||||||
backoff==2.2.1
|
backoff>=2.2.1
|
||||||
base36==0.1.1
|
base36>=0.1.1
|
||||||
base58==2.1.1
|
base58>=2.1.1
|
||||||
beautifulsoup4==4.12.2
|
beautifulsoup4>=4.12.2
|
||||||
cachetools==5.3.1
|
cachetools>=5.3.1
|
||||||
certifi==2023.7.22
|
certifi>=2023.7.22
|
||||||
charset-normalizer==3.2.0
|
charset-normalizer>=3.2.0
|
||||||
chroma-hnswlib==0.7.1
|
chroma-hnswlib>=0.7.1
|
||||||
chromadb==0.4.0
|
chromadb>=0.4.0
|
||||||
click==8.1.7
|
click>=8.1.7
|
||||||
colorama==0.4.6
|
colorama>=0.4.6
|
||||||
coloredlogs==15.0.1
|
coloredlogs>=15.0.1
|
||||||
decorator==4.4.2
|
decorator>=4.4.2
|
||||||
fastapi==0.99.1
|
fastapi>=0.99.1
|
||||||
filelock==3.12.3
|
filelock>=3.12.3
|
||||||
flatbuffers==23.5.26
|
flatbuffers>=23.5.26
|
||||||
frozenlist==1.4.0
|
frozenlist>=1.4.0
|
||||||
fsspec==2023.9.0
|
fsspec>=2023.9.0
|
||||||
google==3.0.0
|
google>=3.0.0
|
||||||
google-api-core==2.11.1
|
google-api-core>=2.11.1
|
||||||
google-auth==2.23.0
|
google-auth>=2.23.0
|
||||||
google-cloud==0.34.0
|
google-cloud>=0.34.0
|
||||||
google-cloud-texttospeech==2.14.1
|
google-cloud-texttospeech>=2.14.1
|
||||||
googleapis-common-protos==1.60.0
|
googleapis-common-protos>=1.60.0
|
||||||
|
h11>=0.14.0
|
||||||
|
httpcore>=0.17.3
|
||||||
|
httptools>=0.6.0
|
||||||
|
httpx>=0.24.1
|
||||||
|
huggingface-hub>=0.16.4
|
||||||
|
humanfriendly>=10.0
|
||||||
|
idna>=3.4
|
||||||
|
imageio>=2.31.3
|
||||||
|
imageio-ffmpeg>=0.4.8
|
||||||
|
importlib-resources>=6.0.1
|
||||||
|
mail-parser>=3.15.0
|
||||||
|
monotonic>=1.6
|
||||||
|
moviepy>=1.0.0
|
||||||
|
mpmath>=1.3.0
|
||||||
|
multidict>=6.0.4
|
||||||
|
numpy>=1.25.2
|
||||||
|
onnxruntime>=1.15.1
|
||||||
|
openai>=0.28.0
|
||||||
|
overrides>=7.4.0
|
||||||
|
packaging>=23.1
|
||||||
|
pandas>=2.1.0
|
||||||
|
Pillow>=10.0.0
|
||||||
|
posthog>=3.0.2
|
||||||
|
proglog>=0.1.10
|
||||||
|
prompt-toolkit>=3.0.39
|
||||||
|
proto-plus>=1.22.3
|
||||||
|
pulsar-client>=3.3.0
|
||||||
|
pyasn1>=0.5.0
|
||||||
|
pyasn1-modules>=0.3.0
|
||||||
|
pydantic>=1.10.12
|
||||||
|
PyPika>=0.48.9
|
||||||
|
pyreadline3>=3.4.1
|
||||||
|
python-dateutil>=2.8.2
|
||||||
|
python-dotenv>=1.0.0
|
||||||
|
python-telegram-bot>=20.5
|
||||||
|
pytz>=2023.3.post1
|
||||||
|
PyYAML>=6.0.1
|
||||||
|
requests>=2.31.0
|
||||||
|
rsa>=4.9
|
||||||
|
simplejson>=3.19.1
|
||||||
|
six>=1.16.0
|
||||||
|
sniffio>=1.3.0
|
||||||
|
soupsieve>=2.5
|
||||||
|
starlette>=0.27.0
|
||||||
|
sympy>=1.12
|
||||||
|
tokenizers>=0.14.0
|
||||||
|
toml>=0.10.0
|
||||||
|
protobuf
|
||||||
grpcio
|
grpcio
|
||||||
grpcio-status
|
grpcio-status
|
||||||
h11==0.14.0
|
|
||||||
httpcore==0.17.3
|
|
||||||
httptools==0.6.0
|
|
||||||
httpx==0.24.1
|
|
||||||
huggingface-hub==0.16.4
|
|
||||||
humanfriendly==10.0
|
|
||||||
idna==3.4
|
|
||||||
imageio==2.31.3
|
|
||||||
imageio-ffmpeg==0.4.8
|
|
||||||
importlib-resources==6.0.1
|
|
||||||
mail-parser==3.15.0
|
|
||||||
monotonic==1.6
|
|
||||||
moviepy==1.0.0
|
|
||||||
mpmath==1.3.0
|
|
||||||
multidict==6.0.4
|
|
||||||
numpy==1.25.2
|
|
||||||
onnxruntime==1.15.1
|
|
||||||
openai==0.28.0
|
|
||||||
overrides==7.4.0
|
|
||||||
packaging==23.1
|
|
||||||
pandas==2.1.0
|
|
||||||
Pillow==10.0.0
|
|
||||||
posthog==3.0.2
|
|
||||||
proglog==0.1.10
|
|
||||||
prompt-toolkit==3.0.39
|
|
||||||
proto-plus==1.22.3
|
|
||||||
protobuf
|
|
||||||
pulsar-client==3.3.0
|
|
||||||
pyasn1==0.5.0
|
|
||||||
pyasn1-modules==0.3.0
|
|
||||||
pydantic==1.10.12
|
|
||||||
PyPika==0.48.9
|
|
||||||
pyreadline3==3.4.1
|
|
||||||
python-dateutil==2.8.2
|
|
||||||
python-dotenv==1.0.0
|
|
||||||
python-telegram-bot==20.5
|
|
||||||
pytz==2023.3.post1
|
|
||||||
PyYAML==6.0.1
|
|
||||||
requests==2.31.0
|
|
||||||
rsa==4.9
|
|
||||||
simplejson==3.19.1
|
|
||||||
six==1.16.0
|
|
||||||
sniffio==1.3.0
|
|
||||||
soupsieve==2.5
|
|
||||||
starlette==0.27.0
|
|
||||||
sympy==1.12
|
|
||||||
telegram==0.0.1
|
|
||||||
tokenizers==0.14.0
|
|
||||||
toml==0.10.0
|
|
||||||
pysocks
|
pysocks
|
||||||
chardet
|
chardet
|
||||||
pydub
|
pydub
|
||||||
aiosqlite
|
aiosqlite
|
||||||
python-telegram-bot
|
python-telegram-bot
|
||||||
pydub
|
pydub
|
||||||
|
stability_sdk
|
||||||
@@ -24,7 +24,7 @@ directory = os.path.dirname(__file__)
|
|||||||
sys.path.append(directory + '/../../')
|
sys.path.append(directory + '/../../')
|
||||||
|
|
||||||
|
|
||||||
from aios_kernel import AIOS_Version,UserConfigItem,AIStorage,Workflow,AIAgent,AgentMsg,AgentMsgStatus,ComputeKernel,OpenAI_ComputeNode,AIBus,AIChatSession,AgentTunnel,TelegramTunnel,CalenderEnvironment,Environment,EmailTunnel,LocalLlama_ComputeNode,Local_Stability_ComputeNode,Stability_ComputeNode,PaintEnvironment
|
from aios_kernel import AIOS_Version,AgentMsgType,UserConfigItem,AIStorage,Workflow,AIAgent,AgentMsg,AgentMsgStatus,ComputeKernel,OpenAI_ComputeNode,AIBus,AIChatSession,AgentTunnel,TelegramTunnel,CalenderEnvironment,Environment,EmailTunnel,LocalLlama_ComputeNode,Local_Stability_ComputeNode,Stability_ComputeNode,PaintEnvironment
|
||||||
from aios_kernel import ContactManager,Contact
|
from aios_kernel import ContactManager,Contact
|
||||||
import proxy
|
import proxy
|
||||||
from aios_kernel import *
|
from aios_kernel import *
|
||||||
@@ -199,9 +199,12 @@ class AIOS_Shell:
|
|||||||
agent_msg.topic = topic
|
agent_msg.topic = topic
|
||||||
resp = await AIBus.get_default_bus().send_message(agent_msg)
|
resp = await AIBus.get_default_bus().send_message(agent_msg)
|
||||||
if resp is not None:
|
if resp is not None:
|
||||||
return resp.body
|
if resp.msg_type != AgentMsgType.TYPE_SYSTEM:
|
||||||
|
return resp.body
|
||||||
|
else:
|
||||||
|
return f"Process Message Error: {resp.body} Please check logs/aios.log for more details!"
|
||||||
else:
|
else:
|
||||||
return "error!"
|
return "System Error: Timeout, no resopnse! Please check logs/aios.log for more details!"
|
||||||
|
|
||||||
async def _user_process_msg(self,msg:AgentMsg) -> AgentMsg:
|
async def _user_process_msg(self,msg:AgentMsg) -> AgentMsg:
|
||||||
pass
|
pass
|
||||||
@@ -211,12 +214,13 @@ class AIOS_Shell:
|
|||||||
tunnel_config = {}
|
tunnel_config = {}
|
||||||
tunnel_config["tunnel_id"] = f"{tunnel_type}_2_{tunnel_target}"
|
tunnel_config["tunnel_id"] = f"{tunnel_type}_2_{tunnel_target}"
|
||||||
tunnel_config["target"] = tunnel_target
|
tunnel_config["target"] = tunnel_target
|
||||||
intpu_table = {}
|
input_table = {}
|
||||||
tunnel_introduce : str = ""
|
tunnel_introduce : str = ""
|
||||||
match tunnel_type:
|
match tunnel_type:
|
||||||
case "telegram":
|
case "telegram":
|
||||||
tunnel_config["type"] = "TelegramTunnel"
|
tunnel_config["type"] = "TelegramTunnel"
|
||||||
intpu_table["token"] = UserConfigItem("telegram bot token")
|
input_table["token"] = UserConfigItem("telegram bot token")
|
||||||
|
input_table["allow"] = UserConfigItem("allow group (default is member,you can choose contact or guest)")
|
||||||
case "email":
|
case "email":
|
||||||
tunnel_config["type"] = "EmailTunnel"
|
tunnel_config["type"] = "EmailTunnel"
|
||||||
case _:
|
case _:
|
||||||
@@ -226,7 +230,7 @@ class AIOS_Shell:
|
|||||||
|
|
||||||
intro_text = FormattedText([("class:prompt", tunnel_introduce)])
|
intro_text = FormattedText([("class:prompt", tunnel_introduce)])
|
||||||
print_formatted_text(intro_text,style=shell_style)
|
print_formatted_text(intro_text,style=shell_style)
|
||||||
for key,item in intpu_table.items():
|
for key,item in input_table.items():
|
||||||
user_input = await try_get_input(f"{key} : {item.desc}")
|
user_input = await try_get_input(f"{key} : {item.desc}")
|
||||||
if user_input is None:
|
if user_input is None:
|
||||||
return None
|
return None
|
||||||
@@ -246,7 +250,7 @@ class AIOS_Shell:
|
|||||||
if f:
|
if f:
|
||||||
toml.dump(all_tunnels,f)
|
toml.dump(all_tunnels,f)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"load tunnels config from {tunnels_config_path} failed!")
|
logger.warning(f"load tunnels config from {tunnels_config_path} failed! {e}")
|
||||||
|
|
||||||
async def handle_contact_commands(self,args):
|
async def handle_contact_commands(self,args):
|
||||||
cm = ContactManager.get_instance()
|
cm = ContactManager.get_instance()
|
||||||
@@ -353,15 +357,17 @@ class AIOS_Shell:
|
|||||||
async def call_func(self,func_name, args):
|
async def call_func(self,func_name, args):
|
||||||
match func_name:
|
match func_name:
|
||||||
case 'send':
|
case 'send':
|
||||||
target_id = args[0]
|
show_text = FormattedText([("class:error", f'send args error,/send Tracy "Hello! It is a good day!" default')])
|
||||||
msg_content = args[1]
|
if len(args) == 3:
|
||||||
topic = args[2]
|
target_id = args[0]
|
||||||
resp = await self.send_msg(msg_content,target_id,topic,self.username)
|
msg_content = args[1]
|
||||||
show_text = FormattedText([("class:title", f"{self.current_topic}@{self.current_target} >>> "),
|
topic = args[2]
|
||||||
("class:content", resp)])
|
resp = await self.send_msg(msg_content,target_id,topic,self.username)
|
||||||
|
show_text = FormattedText([("class:title", f"{self.current_topic}@{self.current_target} >>> "),
|
||||||
|
("class:content", resp)])
|
||||||
return show_text
|
return show_text
|
||||||
case 'set_config':
|
case 'set_config':
|
||||||
show_text = FormattedText([("class:title", f"set config failed!")])
|
show_text = FormattedText([("class:error", f"set config args error,/set_config $config_item! ")])
|
||||||
if len(args) == 1:
|
if len(args) == 1:
|
||||||
key = args[0]
|
key = args[0]
|
||||||
config_item = AIStorage.get_instance().get_user_config().get_config_item(key)
|
config_item = AIStorage.get_instance().get_user_config().get_config_item(key)
|
||||||
@@ -372,10 +378,12 @@ class AIOS_Shell:
|
|||||||
AIStorage.get_instance().get_user_config().set_value(key,value)
|
AIStorage.get_instance().get_user_config().set_value(key,value)
|
||||||
await AIStorage.get_instance().get_user_config().save_to_user_config()
|
await AIStorage.get_instance().get_user_config().save_to_user_config()
|
||||||
show_text = FormattedText([("class:title", f"set {key} to {value} success!")])
|
show_text = FormattedText([("class:title", f"set {key} to {value} success!")])
|
||||||
|
else:
|
||||||
|
show_text = FormattedText([("class:error", f"set config failed! config item {key} not found!")])
|
||||||
|
|
||||||
return show_text
|
return show_text
|
||||||
case 'connect':
|
case 'connect':
|
||||||
show_text = FormattedText([("class:title", "args error, /connect $target telegram | email")])
|
show_text = FormattedText([("class:error", "args error, /connect $target")])
|
||||||
if len(args) < 1:
|
if len(args) < 1:
|
||||||
return show_text
|
return show_text
|
||||||
tunnel_target = args[0]
|
tunnel_target = args[0]
|
||||||
@@ -442,12 +450,12 @@ class AIOS_Shell:
|
|||||||
AIStorage.get_instance().disable_feature(feature)
|
AIStorage.get_instance().disable_feature(feature)
|
||||||
show_text = FormattedText([("class:title", f"Feature {feature} disabled!")])
|
show_text = FormattedText([("class:title", f"Feature {feature} disabled!")])
|
||||||
return show_text
|
return show_text
|
||||||
case 'login':
|
#case 'login':
|
||||||
if len(args) >= 1:
|
# if len(args) >= 1:
|
||||||
self.username = args[0]
|
# self.username = args[0]
|
||||||
AIBus().get_default_bus().register_message_handler(self.username,self._user_process_msg)
|
# AIBus().get_default_bus().register_message_handler(self.username,self._user_process_msg)
|
||||||
|
|
||||||
return self.username + " login success!"
|
# return self.username + " login success!"
|
||||||
case 'history':
|
case 'history':
|
||||||
num = 10
|
num = 10
|
||||||
offset = 0
|
offset = 0
|
||||||
@@ -491,12 +499,14 @@ def parse_function_call(func_string):
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
async def try_get_input(desc:str,check_func:callable = None) -> str:
|
async def try_get_input(desc:str,mutil_line:bool = False,check_func:callable = None) -> str:
|
||||||
user_input = await session.prompt_async(f"{desc} \nType /exit to abort. \nPlease input:",style=shell_style)
|
user_input = await session.prompt_async(f"{desc} \nType /exit to abort. \nPlease input:",style=shell_style)
|
||||||
err_str = ""
|
err_str = ""
|
||||||
if check_func is None:
|
if check_func is None:
|
||||||
if len(user_input) > 0:
|
if len(user_input) > 0:
|
||||||
if user_input != "/exit":
|
if user_input != "/exit":
|
||||||
|
if mutil_line is False:
|
||||||
|
user_input = user_input.strip()
|
||||||
return user_input
|
return user_input
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
@@ -580,7 +590,10 @@ async def main():
|
|||||||
level=logging.INFO,
|
level=logging.INFO,
|
||||||
format='[%(asctime)s]%(name)s[%(levelname)s]: %(message)s')
|
format='[%(asctime)s]%(name)s[%(levelname)s]: %(message)s')
|
||||||
else:
|
else:
|
||||||
log_file = f"{AIStorage.get_instance().get_myai_dir()}/logs/aios_shell.log"
|
dir_path = f"{AIStorage.get_instance().get_myai_dir()}/logs"
|
||||||
|
if not os.path.exists(dir_path):
|
||||||
|
os.makedirs(dir_path)
|
||||||
|
log_file = f"{AIStorage.get_instance().get_myai_dir()}/logs/aios.log"
|
||||||
handler = RotatingFileHandler(log_file, maxBytes=50*1024*1024, backupCount=100)
|
handler = RotatingFileHandler(log_file, maxBytes=50*1024*1024, backupCount=100)
|
||||||
|
|
||||||
logging.basicConfig(handlers=[handler],
|
logging.basicConfig(handlers=[handler],
|
||||||
@@ -591,6 +604,8 @@ async def main():
|
|||||||
if os.name != 'nt':
|
if os.name != 'nt':
|
||||||
if os.getppid() == 1:
|
if os.getppid() == 1:
|
||||||
is_daemon = True
|
is_daemon = True
|
||||||
|
if not sys.stdout.isatty():
|
||||||
|
is_daemon = True
|
||||||
|
|
||||||
shell = AIOS_Shell("user")
|
shell = AIOS_Shell("user")
|
||||||
shell.declare_all_user_config()
|
shell.declare_all_user_config()
|
||||||
@@ -604,8 +619,10 @@ async def main():
|
|||||||
#Remind users to enter necessary configurations.
|
#Remind users to enter necessary configurations.
|
||||||
if await get_user_config_from_input(check_result) is False:
|
if await get_user_config_from_input(check_result) is False:
|
||||||
return 1
|
return 1
|
||||||
|
shell.username = AIStorage.get_instance().get_user_config().get_value("username")
|
||||||
init_result = await shell.initial()
|
init_result = await shell.initial()
|
||||||
|
proxy.apply_storage()
|
||||||
|
|
||||||
if init_result is False:
|
if init_result is False:
|
||||||
if is_daemon:
|
if is_daemon:
|
||||||
logger.error("aios shell initial failed!")
|
logger.error("aios shell initial failed!")
|
||||||
@@ -614,16 +631,14 @@ async def main():
|
|||||||
print("aios shell initial failed!")
|
print("aios shell initial failed!")
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
print(f"aios shell {shell.get_version()} ready.")
|
print(f"aios shell {shell.get_version()} ready. Daemon:{is_daemon}")
|
||||||
|
logger.info(f"aios shell {shell.get_version()} ready. Daemon:{is_daemon}")
|
||||||
if is_daemon:
|
if is_daemon:
|
||||||
return await main_daemon_loop(shell)
|
return await main_daemon_loop(shell)
|
||||||
|
|
||||||
proxy.apply_storage()
|
|
||||||
|
|
||||||
completer = WordCompleter(['/send $target $msg $topic',
|
completer = WordCompleter(['/send $target $msg $topic',
|
||||||
'/open $target $topic',
|
'/open $target $topic',
|
||||||
'/history $num $offset',
|
'/history $num $offset',
|
||||||
'/login $username',
|
|
||||||
'/connect $target',
|
'/connect $target',
|
||||||
'/contact $name',
|
'/contact $name',
|
||||||
'/knowledge add email | dir',
|
'/knowledge add email | dir',
|
||||||
|
|||||||
Reference in New Issue
Block a user