doncamilom commited on
Commit
d409b89
1 Parent(s): 453acb7

llm error handling + buttons.

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -4,6 +4,7 @@ import os
4
  if 'OPENAI_API_KEY' not in os.environ:
5
  os.environ['OPENAI_API_KEY'] = 'none'
6
 
 
7
  import pandas as pd
8
  import streamlit as st
9
  from IPython.core.display import HTML
@@ -43,7 +44,7 @@ agent = ChemCrow(
43
  temp=0.1,
44
  openai_api_key=ss.get('api_key'),
45
  api_keys={
46
- 'rxn4chem':st.secrets['RXN4CHEM_API_KEY']
47
  }
48
  ).agent_executor
49
 
@@ -69,7 +70,6 @@ pre_prompts = [
69
 
70
 
71
  def run_prompt(prompt):
72
-
73
  st.chat_message("user").write(prompt)
74
  with st.chat_message("assistant"):
75
  st_callback = StreamlitCallbackHandlerChem(
@@ -78,9 +78,12 @@ def run_prompt(prompt):
78
  collapse_completed_thoughts = False,
79
  output_placeholder=ss
80
  )
81
- with wandb_tracing_enabled():
82
- response = agent.run(prompt, callbacks=[st_callback])
83
- st.write(response)
 
 
 
84
 
85
 
86
  # sidebar
 
4
  if 'OPENAI_API_KEY' not in os.environ:
5
  os.environ['OPENAI_API_KEY'] = 'none'
6
 
7
+ import openai
8
  import pandas as pd
9
  import streamlit as st
10
  from IPython.core.display import HTML
 
44
  temp=0.1,
45
  openai_api_key=ss.get('api_key'),
46
  api_keys={
47
+ 'rxn4chem': st.secrets['RXN4CHEM_API_KEY']
48
  }
49
  ).agent_executor
50
 
 
70
 
71
 
72
  def run_prompt(prompt):
 
73
  st.chat_message("user").write(prompt)
74
  with st.chat_message("assistant"):
75
  st_callback = StreamlitCallbackHandlerChem(
 
78
  collapse_completed_thoughts = False,
79
  output_placeholder=ss
80
  )
81
+ try:
82
+ with wandb_tracing_enabled():
83
+ response = agent.run(prompt, callbacks=[st_callback])
84
+ st.write(response)
85
+ except openai.error.AuthenticationError:
86
+ st.write("Please input a valid OpenAI API key")
87
 
88
 
89
  # sidebar