Jarvis can update contract, aios_shell can update contract.

This commit is contained in:
Liu Zhicong
2023-09-25 20:57:10 -07:00
parent 7d4b92d4b9
commit 7f11edb706
7 changed files with 182 additions and 8 deletions
+16 -1
View File
@@ -49,7 +49,7 @@ class ContactManager:
@classmethod
def get_instance(cls,filename=None) -> "ContactManager":
if cls._instance is None:
cls._instance = ContactManager(filename)
cls._instance = ContactManager(str(filename))
return cls._instance
def __init__(self, filename="contacts.toml"):
@@ -79,6 +79,21 @@ class ContactManager:
with open(self.filename, "w") as f:
toml.dump(data, f)
def set_contact(self, name:str, new_contact:Contact):
assert name == new_contact.name
for i, contact in enumerate(self.contacts):
if contact.name == name:
self.contacts[i] = new_contact
self.save_data()
return True
for i, member in enumerate(self.family_members):
if member.name == name:
self.family_members[i] = new_contact
self.save_data()
return True
return False
def add_contact(self, name:str, new_contact:Contact):
assert name == new_contact.name
self.contacts.append(new_contact)
@@ -176,5 +176,5 @@ class GoogleTextToSpeechNode(ComputeNode):
user_config = AIStorage.get_instance().get_user_config()
user_config.add_user_config("google_application_credentials",
"google application credentials, please visit:https://cloud.google.com/text-to-speech/docs/before-you-begin",
False,
True,
None)
+1 -1
View File
@@ -30,7 +30,7 @@ class Local_Stability_ComputeNode(ComputeNode):
user_config = AIStorage.get_instance().get_user_config()
if os.getenv("LOCAL_STABILITY_URL") is None:
user_config.add_user_config(
"local_stability_url", "local stability url", False, None)
"local_stability_url", "local stability url", True, None)
if os.getenv("TEXT2IMG_OUTPUT_DIR") is None:
home_dir = Path.home()
output_dir = Path.joinpath(home_dir, "text2img_output")
+16
View File
@@ -13,6 +13,10 @@ class ResourceLocation:
def __init__(self) -> None:
pass
class FeatureItem:
def __init__(self) -> None:
pass
class UserConfigItem:
def __init__(self,desc:str=None) -> None:
self.default_value = None
@@ -142,6 +146,18 @@ class AIStorage:
await self.user_config.load_value_from_file(self.get_system_dir() + "/system.cfg.toml")
await self.user_config.load_value_from_file(self.user_config.user_config_path,True)
async def enable_feature(self,feature_name:str) -> None:
pass
async def disable_feature(self,feature_name:str) -> None:
pass
async def set_feature_init_result(self,feature_name:str,result:bool) -> None:
pass
async def is_feature_enable(self,feature_name:str) -> bool:
pass
def get_user_config(self) -> UserConfig:
return self.user_config
+6 -2
View File
@@ -10,6 +10,7 @@ from telegram.ext import Updater
from telegram.error import Forbidden, NetworkError
from .tunnel import AgentTunnel
from .storage import AIStorage
from .contact_manager import ContactManager,Contact,FamilyMember
from .agent_message import AgentMsg
@@ -119,6 +120,10 @@ class TelegramTunnel(AgentTunnel):
cm : ContactManager = ContactManager.get_instance()
reomte_user_name = f"{update.effective_user.id}@telegram"
#owner_tg_username = AIStorage.get_instance().get_user_config().get_value("telegram")
#owner_name = AIStorage.get_instance().get_user_config().get_value("username")
contact : Contact = cm.find_contact_by_telegram(update.effective_user.username)
if contact is None:
contact = cm.find_contact_by_telegram(str(update.effective_user.id))
@@ -136,8 +141,7 @@ class TelegramTunnel(AgentTunnel):
contact.added_by = self.target_id
cm.add_contact(contact.name, contact)
reomte_user_name = contact.name
# create gust account?
agent_msg = await self.conver_tg_msg_to_agent_msg(update)
agent_msg.sender = reomte_user_name
self.ai_bus.register_message_handler(reomte_user_name, self._process_message)
+51
View File
@@ -13,6 +13,7 @@ from .compute_kernel import ComputeKernel
from .environment import Environment,EnvironmentEvent
from .ai_function import SimpleAIFunction
from .storage import AIStorage
from .contact_manager import ContactManager,Contact,FamilyMember
import aiosqlite
@@ -93,6 +94,17 @@ class CalenderEnvironment(Environment):
"Draw a picture according to the description",
self._paint,paint_param))
self.add_ai_function(SimpleAIFunction("get_contact",
"get contact info",
self._get_contact,{"name":"name of contact"}))
self.add_ai_function(SimpleAIFunction("set_contact",
"set contact info",
self._set_contact,{"name":"name of contact","contact_info":"A json to descrpit contact"}))
#self.add_ai_function(SimpleAIFunction("user_confirm",
# "user confirm",
# self._user_confirm))
@@ -222,6 +234,45 @@ class CalenderEnvironment(Environment):
def _do_get_value(self,key:str) -> Optional[str]:
return None
async def _get_contact(self,name:str) -> str:
cm = ContactManager.get_instance()
contact : Contact = cm.find_contact_by_name(name)
if contact:
s = json.dumps(contact.to_dict())
return f"Execute get_contact OK , contact {name} is {s}"
else:
return f"Execute get_contact OK , contact {name} not found!"
async def _set_contact(self,name:str,contact_info:str) -> str:
cm = ContactManager.get_instance()
contact = cm.find_contact_by_name(name)
contact_info = json.loads(contact_info)
if contact is None:
contact = Contact(name)
contact.email = contact_info.get("email")
contact.telegram = contact_info.get("telegram")
contact.notes = contact_info.get("notes")
contact.added_by = self.env_id
cm.add_contact(name,contact)
return f"Execute set_contact OK , new contact {name} added!"
else:
if contact_info.get("email") is not None:
contact.email = contact_info.get("email")
if contact_info.get("telegram") is not None:
contact.telegram = contact_info.get("telegram")
if contact_info.get("notes") is not None:
contact.notes = contact_info.get("notes")
contact.added_by = self.env_id
cm.set_contact(name,contact)
return f"Execute set_contact OK , contact {name} updated!"
async def start(self) -> None:
if self.is_run: