fix bug
This commit is contained in:
@@ -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
|
||||
@@ -130,6 +131,13 @@ class TelegramTunnel(AgentTunnel):
|
||||
if update.effective_user.is_bot:
|
||||
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"
|
||||
|
||||
Reference in New Issue
Block a user