send image with telegram message
This commit is contained in:
@@ -1,10 +1,10 @@
|
|||||||
instance_id = "Mia"
|
instance_id = "Mia"
|
||||||
fullname = "Mia"
|
fullname = "Mia"
|
||||||
llm_model_name = "gpt-3.5-turbo-16k-0613"
|
llm_model_name = "gpt-4"
|
||||||
max_token_size = 16000
|
max_token_size = 16000
|
||||||
#enable_function =["add_event"]
|
#enable_function =["add_event"]
|
||||||
#enable_kb = "true"
|
#enable_kb = "true"
|
||||||
enable_timestamp = "true"
|
enable_timestamp = "false"
|
||||||
owner_prompt = "我是你的主人{name}"
|
owner_prompt = "我是你的主人{name}"
|
||||||
contact_prompt = "我是你的朋友{name}"
|
contact_prompt = "我是你的朋友{name}"
|
||||||
owner_env = "knowledge"
|
owner_env = "knowledge"
|
||||||
@@ -18,6 +18,7 @@ content = """
|
|||||||
你在收到我的信息后,按如下规则处理
|
你在收到我的信息后,按如下规则处理
|
||||||
1. 在第一次接受到一条信息时,优先尝试用合适的关键字查询去查询知识库。
|
1. 在第一次接受到一条信息时,优先尝试用合适的关键字查询去查询知识库。
|
||||||
2. 如果信息中包含一段知识库的查询结果,尝试用查询结果处理,如果还是不能处理,尝试递增index继续查询。
|
2. 如果信息中包含一段知识库的查询结果,尝试用查询结果处理,如果还是不能处理,尝试递增index继续查询。
|
||||||
3. 如果知识库返回不了结果了,请尽力返回。
|
3. 如果要返回知识库结果条目,在消息开头附上他的json字符串。
|
||||||
|
4. 如果知识库返回不了结果了,请尽力返回。
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|||||||
@@ -358,13 +358,6 @@ class AIAgent:
|
|||||||
old_content = msg.get("content")
|
old_content = msg.get("content")
|
||||||
msg["content"] = old_content.format_map(self.owner_env)
|
msg["content"] = old_content.format_map(self.owner_env)
|
||||||
|
|
||||||
async def _get_knowlege_prompt(self,input_msg:AgentPrompt) -> AgentPrompt:
|
|
||||||
if self.enable_kb is False:
|
|
||||||
return None
|
|
||||||
|
|
||||||
from .knowledge_base import KnowledgeBase
|
|
||||||
return await KnowledgeBase().query_prompt(input_msg)
|
|
||||||
|
|
||||||
async def _process_msg(self,msg:AgentMsg) -> AgentMsg:
|
async def _process_msg(self,msg:AgentMsg) -> AgentMsg:
|
||||||
from .compute_kernel import ComputeKernel
|
from .compute_kernel import ComputeKernel
|
||||||
from .bus import AIBus
|
from .bus import AIBus
|
||||||
@@ -393,11 +386,6 @@ class AIAgent:
|
|||||||
history_prmpt,history_token_len = await self._get_prompt_from_session(chatsession,system_prompt_len + function_token_len,input_len)
|
history_prmpt,history_token_len = await self._get_prompt_from_session(chatsession,system_prompt_len + function_token_len,input_len)
|
||||||
prompt.append(history_prmpt) # chat context
|
prompt.append(history_prmpt) # chat context
|
||||||
|
|
||||||
kb_prompt = await self._get_knowlege_prompt(msg_prompt)
|
|
||||||
prompt.append(kb_prompt)
|
|
||||||
prompt.append(msg_prompt)
|
|
||||||
|
|
||||||
|
|
||||||
logger.debug(f"Agent {self.agent_id} do llm token static system:{system_prompt_len},function:{function_token_len},history:{history_token_len},input:{input_len}, totoal prompt:{system_prompt_len + function_token_len + history_token_len} ")
|
logger.debug(f"Agent {self.agent_id} do llm token static system:{system_prompt_len},function:{function_token_len},history:{history_token_len},input:{input_len}, totoal prompt:{system_prompt_len + function_token_len + history_token_len} ")
|
||||||
task_result:ComputeTaskResult = await ComputeKernel.get_instance().do_llm_completion(prompt,self.llm_model_name,self.max_token_size,inner_functions)
|
task_result:ComputeTaskResult = await ComputeKernel.get_instance().do_llm_completion(prompt,self.llm_model_name,self.max_token_size,inner_functions)
|
||||||
if task_result.result_code != ComputeTaskResultCode.OK:
|
if task_result.result_code != ComputeTaskResultCode.OK:
|
||||||
|
|||||||
@@ -239,6 +239,31 @@ class KnowledgeBase:
|
|||||||
|
|
||||||
return content
|
return content
|
||||||
|
|
||||||
|
def parse_object_in_message(self, message: str) -> KnowledgeObject:
|
||||||
|
# get message's first line
|
||||||
|
lines = message.split("\n")
|
||||||
|
if len(lines) > 0:
|
||||||
|
message = lines[0]
|
||||||
|
try:
|
||||||
|
desc = json.loads(message)
|
||||||
|
object_id = desc["object_id"]
|
||||||
|
except:
|
||||||
|
return None
|
||||||
|
|
||||||
|
if object_id is not None:
|
||||||
|
return self.__load_object(ObjectID(object_id))
|
||||||
|
|
||||||
|
|
||||||
|
def bytes_from_object(self, object: KnowledgeObject) -> bytes:
|
||||||
|
if object.get_object_type() == ObjectType.Image:
|
||||||
|
image_object = object
|
||||||
|
return self.store.get_chunk_reader().read_chunk_list_to_single_bytes(image_object.get_chunk_list())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class KnowledgeEnvironment(Environment):
|
class KnowledgeEnvironment(Environment):
|
||||||
def __init__(self, env_id: str) -> None:
|
def __init__(self, env_id: str) -> None:
|
||||||
|
|||||||
@@ -9,6 +9,10 @@ from telegram import Bot
|
|||||||
from telegram.ext import Updater
|
from telegram.ext import Updater
|
||||||
from telegram.error import Forbidden, NetworkError
|
from telegram.error import Forbidden, NetworkError
|
||||||
|
|
||||||
|
from knowledge.object.object_id import ObjectType
|
||||||
|
|
||||||
|
from .knowledge_base import KnowledgeBase
|
||||||
|
|
||||||
from .tunnel import AgentTunnel
|
from .tunnel import AgentTunnel
|
||||||
from .storage import AIStorage
|
from .storage import AIStorage
|
||||||
from .contact_manager import ContactManager,Contact,FamilyMember
|
from .contact_manager import ContactManager,Contact,FamilyMember
|
||||||
@@ -171,13 +175,20 @@ class TelegramTunnel(AgentTunnel):
|
|||||||
else:
|
else:
|
||||||
if resp_msg.body_mime is None:
|
if resp_msg.body_mime is None:
|
||||||
if resp_msg.body is not None:
|
if resp_msg.body is not None:
|
||||||
pos = resp_msg.body.find("audio file")
|
knowledge_object = KnowledgeBase().parse_object_in_message(resp_msg.body)
|
||||||
if pos != -1:
|
if knowledge_object is not None:
|
||||||
audio_file = resp_msg.body[pos+11:].strip()
|
if knowledge_object.get_object_type() == ObjectType.Image:
|
||||||
if audio_file.startswith("\""):
|
image = KnowledgeBase().bytes_from_object(knowledge_object)
|
||||||
audio_file = audio_file[1:-1]
|
await update.message.reply_photo(image)
|
||||||
await update.message.reply_voice(audio_file)
|
return
|
||||||
return
|
else:
|
||||||
|
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)
|
await update.message.reply_text(resp_msg.body)
|
||||||
else:
|
else:
|
||||||
if resp_msg.body_mime.startswith("image"):
|
if resp_msg.body_mime.startswith("image"):
|
||||||
|
|||||||
Reference in New Issue
Block a user