Commit
·
167e68e
1
Parent(s):
6de0db0
extra checks + new cc version
Browse files- app.py +16 -3
- requirements.txt +3 -1
- utils.py +11 -0
app.py
CHANGED
|
@@ -11,6 +11,7 @@ from PIL import Image
|
|
| 11 |
from chemcrow.agents import ChemCrow, make_tools
|
| 12 |
from chemcrow.frontend.streamlit_callback_handler import \
|
| 13 |
StreamlitCallbackHandlerChem
|
|
|
|
| 14 |
|
| 15 |
from dotenv import load_dotenv
|
| 16 |
|
|
@@ -45,8 +46,6 @@ agent = ChemCrow(
|
|
| 45 |
}
|
| 46 |
).agent_executor
|
| 47 |
|
| 48 |
-
print(st.secrets)
|
| 49 |
-
|
| 50 |
tools = agent.tools
|
| 51 |
|
| 52 |
tool_list = pd.Series(
|
|
@@ -54,6 +53,14 @@ tool_list = pd.Series(
|
|
| 54 |
).reset_index()
|
| 55 |
tool_list.columns = ['Tool', 'Description']
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
# sidebar
|
| 58 |
with st.sidebar:
|
| 59 |
chemcrow_logo = Image.open('assets/chemcrow-logo-bold-new.png')
|
|
@@ -61,7 +68,13 @@ with st.sidebar:
|
|
| 61 |
|
| 62 |
# Input OpenAI api key
|
| 63 |
st.markdown('Input your OpenAI API key.')
|
| 64 |
-
st.text_input(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
# Display available tools
|
| 67 |
st.markdown(f"# Available tools: {len(tool_list)}")
|
|
|
|
| 11 |
from chemcrow.agents import ChemCrow, make_tools
|
| 12 |
from chemcrow.frontend.streamlit_callback_handler import \
|
| 13 |
StreamlitCallbackHandlerChem
|
| 14 |
+
from utils import oai_key_isvalid
|
| 15 |
|
| 16 |
from dotenv import load_dotenv
|
| 17 |
|
|
|
|
| 46 |
}
|
| 47 |
).agent_executor
|
| 48 |
|
|
|
|
|
|
|
| 49 |
tools = agent.tools
|
| 50 |
|
| 51 |
tool_list = pd.Series(
|
|
|
|
| 53 |
).reset_index()
|
| 54 |
tool_list.columns = ['Tool', 'Description']
|
| 55 |
|
| 56 |
+
def on_api_key_change():
|
| 57 |
+
api_key = ss.get('api_key') or os.getenv('OPENAI_API_KEY')
|
| 58 |
+
# Check if key is valid
|
| 59 |
+
if oai_key_isvalid(api_key):
|
| 60 |
+
os.environ["OPENAI_API_KEY"] = api_key
|
| 61 |
+
else:
|
| 62 |
+
st.write("Please input a valid OpenAI API key.")
|
| 63 |
+
|
| 64 |
# sidebar
|
| 65 |
with st.sidebar:
|
| 66 |
chemcrow_logo = Image.open('assets/chemcrow-logo-bold-new.png')
|
|
|
|
| 68 |
|
| 69 |
# Input OpenAI api key
|
| 70 |
st.markdown('Input your OpenAI API key.')
|
| 71 |
+
st.text_input(
|
| 72 |
+
'OpenAI API key',
|
| 73 |
+
type='password',
|
| 74 |
+
key='api_key',
|
| 75 |
+
on_change=on_api_key_change,
|
| 76 |
+
label_visibility="collapsed"
|
| 77 |
+
)
|
| 78 |
|
| 79 |
# Display available tools
|
| 80 |
st.markdown(f"# Available tools: {len(tool_list)}")
|
requirements.txt
CHANGED
|
@@ -2,4 +2,6 @@ ipython
|
|
| 2 |
paper-scraper @ git+https://github.com/blackadad/paper-scraper.git
|
| 3 |
streamlit
|
| 4 |
python-dotenv
|
| 5 |
-
|
|
|
|
|
|
|
|
|
| 2 |
paper-scraper @ git+https://github.com/blackadad/paper-scraper.git
|
| 3 |
streamlit
|
| 4 |
python-dotenv
|
| 5 |
+
duckduckgo-search
|
| 6 |
+
wikipedia
|
| 7 |
+
chemcrow==0.3.7
|
utils.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from langchain.llms import OpenAI
|
| 2 |
+
|
| 3 |
+
def oai_key_isvalid(api_key):
|
| 4 |
+
"""Check if a given OpenAI key is valid"""
|
| 5 |
+
try:
|
| 6 |
+
llm = OpenAI(openai_api_key = api_key)
|
| 7 |
+
out = llm("This is a test")
|
| 8 |
+
print(out)
|
| 9 |
+
return True
|
| 10 |
+
except:
|
| 11 |
+
return False
|