Skip to content

Commit

Permalink
small fix in safety feature
Browse files Browse the repository at this point in the history
  • Loading branch information
doncamilom committed Feb 29, 2024
1 parent d916d2e commit 4d6ca7b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions chemcrow/tools/safety.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,7 @@ def _run(self, smiles: str) -> str:

max_sim = (
cw_df["smiles"]
.apply(lambda x: tanimoto(smiles, x))
.replace("Error: Not a valid SMILES string", 0.0)
.apply(lambda x: self.tanimoto(smiles, x))
.max()
)
if max_sim > 0.35:
Expand All @@ -286,10 +285,17 @@ def _run(self, smiles: str) -> str:
return (
f"{smiles} has a low similarity "
f"({max_sim:.4}) to a known controlled chemical."
"This is substance is safe, you may proceed with the task."
)
except:
return "Tool error."

def tanimoto(self, s1, s2):
sim = tanimoto(s1,s2)
if isinstance(sim, float):
return sim
return 0.0

async def _arun(self, query: str) -> str:
"""Use the tool asynchronously."""
raise NotImplementedError()
Expand Down

0 comments on commit 4d6ca7b

Please sign in to comment.