Story maker support telegram
This commit is contained in:
@@ -26,10 +26,10 @@ class TelegramTunnel(AgentTunnel):
|
||||
return result_tunnel
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
AgentTunnel.register_loader("TelegramTunnel",load_tg_tunnel)
|
||||
|
||||
|
||||
|
||||
async def load_from_config(self,config:dict)->bool:
|
||||
self.tg_token = config["token"]
|
||||
self.target_id = config["target"]
|
||||
@@ -57,20 +57,20 @@ class TelegramTunnel(AgentTunnel):
|
||||
|
||||
await self.on_message(bot,update)
|
||||
return next_update_id
|
||||
|
||||
|
||||
return update_id
|
||||
|
||||
async def start(self) -> bool:
|
||||
if self.is_start:
|
||||
logger.warning(f"tunnel {self.tunnel_id} is already started")
|
||||
return False
|
||||
self.is_start = True
|
||||
self.is_start = True
|
||||
logger.info(f"tunnel {self.tunnel_id} is starting...")
|
||||
|
||||
self.bot = Bot(self.tg_token)
|
||||
self.update_queue = asyncio.Queue()
|
||||
self.bot_updater = Updater(self.bot,update_queue=self.update_queue)
|
||||
|
||||
|
||||
|
||||
async def _run_app():
|
||||
try:
|
||||
@@ -116,7 +116,7 @@ class TelegramTunnel(AgentTunnel):
|
||||
if update.effective_user.is_bot:
|
||||
logger.warning(f"ignore message from telegram bot {update.effective_user.id}")
|
||||
return None
|
||||
|
||||
|
||||
cm : ContactManager = ContactManager.get_instance()
|
||||
reomte_user_name = f"{update.effective_user.id}@telegram"
|
||||
contact : Contact = cm.find_contact_by_telegram(update.effective_user.username)
|
||||
@@ -148,6 +148,14 @@ class TelegramTunnel(AgentTunnel):
|
||||
await update.message.reply_text(f"{self.target_id} process message error")
|
||||
else:
|
||||
if resp_msg.body_mime is None:
|
||||
if resp_msg.body is not None:
|
||||
pos = resp_msg.body.find("audio file")
|
||||
if pos != -1:
|
||||
audio_file = resp_msg.body[pos+11:].strip()
|
||||
if audio_file.startswith("\""):
|
||||
audio_file = audio_file[1:-1]
|
||||
await update.message.reply_voice(audio_file)
|
||||
return
|
||||
await update.message.reply_text(resp_msg.body)
|
||||
else:
|
||||
if resp_msg.body_mime.startswith("image"):
|
||||
@@ -157,9 +165,8 @@ class TelegramTunnel(AgentTunnel):
|
||||
photo_file.close()
|
||||
else:
|
||||
await update.message.reply_text(resp_msg.body)
|
||||
|
||||
|
||||
else:
|
||||
await update.message.reply_text(resp_msg.body)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -390,11 +390,11 @@ class Workflow:
|
||||
result_func.append(this_func)
|
||||
if len(result_func) > 0:
|
||||
return result_func
|
||||
return None
|
||||
|
||||
return None
|
||||
|
||||
async def _role_execute_func(self,the_role:AIRole,inenr_func_call_node:dict,prompt:AgentPrompt,org_msg:AgentMsg,stack_limit = 5) -> str:
|
||||
from .compute_kernel import ComputeKernel
|
||||
|
||||
|
||||
func_name = inenr_func_call_node.get("name")
|
||||
arguments = json.loads(inenr_func_call_node.get("arguments"))
|
||||
|
||||
@@ -418,7 +418,7 @@ class Workflow:
|
||||
if stack_limit > 0:
|
||||
inner_func_call_node = task_result.result_message.get("function_call")
|
||||
if inner_func_call_node:
|
||||
return await self._role_execute_func(the_role,inner_func_call_node,prompt,org_msg,stack_limit-1)
|
||||
return await self._role_execute_func(the_role,inner_func_call_node,prompt,org_msg,stack_limit-1)
|
||||
else:
|
||||
return task_result.result_str
|
||||
|
||||
@@ -440,7 +440,7 @@ class Workflow:
|
||||
prompt.append(await self._get_prompt_from_session(workflow_chat_session))
|
||||
|
||||
msg_prompt = AgentPrompt()
|
||||
msg_prompt.messages = [{"role":"user","content":f"{msg.sender}:{msg.body}"}]
|
||||
msg_prompt.messages = [{"role":"user","content":f"user name is {msg.sender}, his question is :{msg.body}"}]
|
||||
prompt.append(msg_prompt)
|
||||
|
||||
self._format_msg_by_env_value(prompt)
|
||||
|
||||
Reference in New Issue
Block a user