fix bug
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
instance_id = "Mia"
|
||||
fullname = "Mia"
|
||||
llm_model_name = "gpt-4"
|
||||
max_token_size = 16000
|
||||
#llm_model_name = "gpt-4"
|
||||
#max_token_size = 16000
|
||||
#enable_function =["add_event"]
|
||||
#enable_kb = "true"
|
||||
enable_timestamp = "false"
|
||||
#enable_timestamp = "false"
|
||||
owner_prompt = "我是你的主人{name}"
|
||||
contact_prompt = "我是你的朋友{name}"
|
||||
owner_env = "knowledge"
|
||||
|
||||
@@ -243,17 +243,21 @@ class KnowledgeBase:
|
||||
|
||||
def parse_object_in_message(self, message: str) -> KnowledgeObject:
|
||||
# get message's first line
|
||||
logging.info(f"tg parse resp message: {message}")
|
||||
lines = message.split("\n")
|
||||
if len(lines) > 0:
|
||||
message = lines[0]
|
||||
try:
|
||||
desc = json.loads(message)
|
||||
object_id = desc["object_id"]
|
||||
except:
|
||||
if isinstance(desc, dict):
|
||||
object_id = desc["id"]
|
||||
else:
|
||||
object_id = desc[0]["id"]
|
||||
except Exception as e:
|
||||
return None
|
||||
|
||||
if object_id is not None:
|
||||
return self.__load_object(ObjectID(object_id))
|
||||
return self.__load_object(ObjectID.from_base58(object_id))
|
||||
|
||||
|
||||
def bytes_from_object(self, object: KnowledgeObject) -> bytes:
|
||||
@@ -281,7 +285,8 @@ class KnowledgeEnvironment(Environment):
|
||||
self._query,
|
||||
query_param))
|
||||
|
||||
async def _query(self, tokens: str, types: list[str] = ["text"], index: int=0):
|
||||
async def _query(self, tokens: str, types: list[str] = ["text"], index: str=0):
|
||||
index = int(index)
|
||||
object_ids = await KnowledgeBase().query_objects(tokens, types, 4)
|
||||
if len(object_ids) <= index:
|
||||
return "*** I have no more information for your reference.\n"
|
||||
|
||||
@@ -55,6 +55,7 @@ class TelegramTunnel(AgentTunnel):
|
||||
self.bot:Bot = None
|
||||
self.update_queue = None
|
||||
self.allow_group = "contact"
|
||||
self.in_process_tg_msg = {}
|
||||
|
||||
async def _do_process_raw_message(self,bot: Bot, update_id: int) -> int:
|
||||
# Request updates after the last update_id
|
||||
@@ -131,6 +132,13 @@ class TelegramTunnel(AgentTunnel):
|
||||
logger.warning(f"ignore message from telegram bot {update.effective_user.id}")
|
||||
return None
|
||||
|
||||
if self.in_process_tg_msg.get(update.message.message_id) is not None:
|
||||
logger.warning(f"ignore message from telegram bot {update.effective_user.id}")
|
||||
return None
|
||||
|
||||
self.in_process_tg_msg[update.message.message_id] = True
|
||||
|
||||
|
||||
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")
|
||||
|
||||
@@ -252,15 +252,25 @@ class AIOS_Shell:
|
||||
async def append_tunnel_config(self,tunnel_config):
|
||||
user_data_dir = AIStorage.get_instance().get_myai_dir()
|
||||
tunnels_config_path = os.path.abspath(f"{user_data_dir}/etc/tunnels.cfg.toml")
|
||||
all_tunnels = None
|
||||
try:
|
||||
all_tunnels = toml.load(tunnels_config_path)
|
||||
if all_tunnels is not None:
|
||||
except Exception as e:
|
||||
logger.warning(f"load tunnels config for append from {tunnels_config_path} failed! {e}")
|
||||
|
||||
if all_tunnels is None:
|
||||
all_tunnels = {}
|
||||
|
||||
all_tunnels[tunnel_config["tunnel_id"]] = tunnel_config
|
||||
try:
|
||||
f = open(tunnels_config_path,"w")
|
||||
if f:
|
||||
toml.dump(all_tunnels,f)
|
||||
logger.info(f"append tunnel config to {tunnels_config_path} success!")
|
||||
else:
|
||||
logger.warning(f"append tunnel config to {tunnels_config_path} failed!")
|
||||
except Exception as e:
|
||||
logger.warning(f"load tunnels config from {tunnels_config_path} failed! {e}")
|
||||
logger.warning(f"append tunnels config from {tunnels_config_path} failed! {e}")
|
||||
|
||||
async def handle_contact_commands(self,args):
|
||||
cm = ContactManager.get_instance()
|
||||
|
||||
Reference in New Issue
Block a user