gabrielaltay commited on
Commit
30d8324
·
verified ·
1 Parent(s): c027a07

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -8
app.py CHANGED
@@ -77,15 +77,12 @@ def show_bill(bdict):
77
  st.markdown(escape_markdown(bdict["text"]))
78
 
79
 
80
-
81
-
82
-
83
  if "messages" not in st.session_state:
84
  st.session_state["messages"] = []
85
  if "openai_model" not in st.session_state:
86
  st.session_state["openai_model"] = "gpt-3.5-turbo-0125"
87
  if "openai_api_key" not in st.session_state:
88
- st.session_state["openai_api_key"] = None
89
 
90
 
91
  df = get_data()
@@ -93,6 +90,8 @@ df = get_data()
93
 
94
  with st.sidebar:
95
 
 
 
96
  st.header("Configuration")
97
 
98
  st.text_input(
@@ -101,7 +100,8 @@ with st.sidebar:
101
  type="password",
102
  key="openai_api_key",
103
  )
104
-
 
105
  MODELS = ["gpt-3.5-turbo-0125", "gpt-4-0125-preview"]
106
  st.selectbox("Model Name", MODELS, key="openai_model")
107
 
@@ -123,7 +123,7 @@ with st.sidebar:
123
 
124
  system_message = {
125
  "role": "system",
126
- "content": "You are a helpful legislative question answering assistant. Use the following legislative text to help answer user questions.\n\n---" + bdict["text"],
127
  }
128
 
129
 
@@ -139,8 +139,11 @@ for message in st.session_state["messages"]:
139
 
140
  if prompt := st.chat_input("How can I help you understand this bill?"):
141
 
142
- if st.session_state["openai_api_key"] is None:
143
- st.warning("Enter API key to chat")
 
 
 
144
  st.stop()
145
  else:
146
  client = OpenAI(api_key=st.session_state["openai_api_key"])
 
77
  st.markdown(escape_markdown(bdict["text"]))
78
 
79
 
 
 
 
80
  if "messages" not in st.session_state:
81
  st.session_state["messages"] = []
82
  if "openai_model" not in st.session_state:
83
  st.session_state["openai_model"] = "gpt-3.5-turbo-0125"
84
  if "openai_api_key" not in st.session_state:
85
+ st.session_state["openai_api_key"] = ""
86
 
87
 
88
  df = get_data()
 
90
 
91
  with st.sidebar:
92
 
93
+ error_header = st.empty()
94
+
95
  st.header("Configuration")
96
 
97
  st.text_input(
 
100
  type="password",
101
  key="openai_api_key",
102
  )
103
+ st.write("You can create an OpenAI API key [here](https://platform.openai.com/account/api-keys)")
104
+
105
  MODELS = ["gpt-3.5-turbo-0125", "gpt-4-0125-preview"]
106
  st.selectbox("Model Name", MODELS, key="openai_model")
107
 
 
123
 
124
  system_message = {
125
  "role": "system",
126
+ "content": "You are a helpful legislative question answering assistant. Use the following legislative text to help answer user questions.\n\n" + bdict["text"],
127
  }
128
 
129
 
 
139
 
140
  if prompt := st.chat_input("How can I help you understand this bill?"):
141
 
142
+ if st.session_state["openai_api_key"] == "":
143
+ error_header.warning("Enter API key to chat")
144
+ st.stop()
145
+ elif not st.session_state["openai_api_key"].startswith("sk-"):
146
+ error_header.warning("Enter valid API key to chat")
147
  st.stop()
148
  else:
149
  client = OpenAI(api_key=st.session_state["openai_api_key"])