first pipeline framework

This commit is contained in:
yzlin 2023-09-23 01:43:48 +08:00
parent bbffb3f135
commit 2e6cc6540b
15 changed files with 445 additions and 6 deletions

View file

@ -33,7 +33,7 @@ class Environment(BaseModel):
Add a role in the current environment
"""
role.set_env(self)
self.roles[role.profile] = role
self.roles[str(role._setting)] = role
def add_roles(self, roles: Iterable[Role]):
"""增加一批在当前环境的角色
@ -72,8 +72,8 @@ class Environment(BaseModel):
"""
return self.roles
def get_role(self, name: str) -> Role:
def get_role(self, role_setting: str) -> Role:
"""获得环境内的指定角色
get all the environment roles
"""
return self.roles.get(name, None)
return self.roles.get(role_setting, None)

View file

@ -137,6 +137,11 @@ class Role:
"""Get the role description (position)"""
return self._setting.profile
@property
def name(self):
"""Get the role name"""
return self._setting.name
def _get_prefix(self):
"""Get the role prefix"""
if self._setting.desc:
@ -188,6 +193,10 @@ class Role:
self._rc.news = self._rc.memory.find_news(observed) # find news (previously unseen messages) from observed messages
for i in env_msgs:
if i.restricted_to != "" and self.profile not in i.restricted_to and self.name not in i.restricted_to:
# if the msg is not send to the whole audience ("") nor this role (self.profile or self.name),
# then this role should not be able to receive it and record it into its memory
continue
self.recv(i)
news_text = [f"{i.role}: {i.content[:20]}..." for i in self._rc.news]