From 29d5a72816c1444e93094fb56e647052d68e666e Mon Sep 17 00:00:00 2001 From: Andres Date: Thu, 9 Nov 2023 19:20:59 +0100 Subject: [PATCH] add utils --- .../frontend/streamlit_callback_handler.py | 12 ++------- chemcrow/frontend/utils.py | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 chemcrow/frontend/utils.py diff --git a/chemcrow/frontend/streamlit_callback_handler.py b/chemcrow/frontend/streamlit_callback_handler.py index 1a574d0..39f8870 100644 --- a/chemcrow/frontend/streamlit_callback_handler.py +++ b/chemcrow/frontend/streamlit_callback_handler.py @@ -3,18 +3,10 @@ StreamlitCallbackHandler, LLMThought, ) - -from chemcrow.agents.prompts import FORMAT_INSTRUCTIONS, SUFFIX, QUESTION_PROMPT - -from typing import TYPE_CHECKING, Any, Dict, List, NamedTuple, Optional, Union - -from langchain.callbacks.streamlit.mutable_expander import MutableExpander -from langchain.schema import AgentAction, AgentFinish, LLMResult - +from typing import Any, Dict, List, Optional from streamlit.delta_generator import DeltaGenerator -import ast -from .utils import cdk, is_valid_smiles +from .utils import cdk class LLMThoughtChem(LLMThought): diff --git a/chemcrow/frontend/utils.py b/chemcrow/frontend/utils.py new file mode 100644 index 0000000..dee56f1 --- /dev/null +++ b/chemcrow/frontend/utils.py @@ -0,0 +1,25 @@ +import requests +from rdkit import Chem +from langchain import LLMChain, PromptTemplate +from langchain.chat_models import ChatOpenAI + +def cdk(smiles): + """ + Get a depiction of some smiles. + """ + + url = "https://www.simolecule.com/cdkdepict/depict/wob/svg" + headers = {'Content-Type': 'application/json'} + response = requests.get( + url, + headers=headers, + params={ + "smi": smiles, + "annotate": "colmap", + "zoom": 2, + "w": 150, + "h": 80, + "abbr": "off", + } + ) + return response.text