Browse Source

feat: add min simularity to match role

master
lanvent 1 year ago
parent
commit
eaac3e3579
1 changed files with 2 additions and 2 deletions
  1. +2
    -2
      plugins/role/role.py

+ 2
- 2
plugins/role/role.py View File

@@ -52,7 +52,7 @@ class Role(Plugin):
logger.warn("[Role] init failed, ignore or see https://github.com/zhayujie/chatgpt-on-wechat/tree/master/plugins/role .") logger.warn("[Role] init failed, ignore or see https://github.com/zhayujie/chatgpt-on-wechat/tree/master/plugins/role .")
raise e raise e


def get_role(self, name, find_closest=True):
def get_role(self, name, find_closest=True, min_sim = 0.35):
name = name.lower() name = name.lower()
found_role = None found_role = None
if name in self.roles: if name in self.roles:
@@ -62,7 +62,7 @@ class Role(Plugin):


def str_simularity(a, b): def str_simularity(a, b):
return difflib.SequenceMatcher(None, a, b).ratio() return difflib.SequenceMatcher(None, a, b).ratio()
max_sim = 0.0
max_sim = min_sim
max_role = None max_role = None
for role in self.roles: for role in self.roles:
sim = str_simularity(name, role) sim = str_simularity(name, role)


Loading…
Cancel
Save