andreped commited on
Commit
97c0fd5
1 Parent(s): 83ba0e6

Load secrets as environmental variables for HF support

Browse files
Files changed (2) hide show
  1. app.py +8 -3
  2. chatbot/data.py +6 -6
app.py CHANGED
@@ -5,8 +5,14 @@ import streamlit as st
5
  from chatbot.data import download_test_data
6
  from chatbot.data import load_data
7
 
8
- # add OpenAI API key to environemntal variables
9
- os.environ["OPENAI_API_KEY"] = st.secrets["OPENAI_API_KEY"]
 
 
 
 
 
 
10
 
11
  # Initialize message history
12
  st.header("Chat with André's research 💬 📚")
@@ -14,7 +20,6 @@ st.header("Chat with André's research 💬 📚")
14
  if "messages" not in st.session_state.keys(): # Initialize the chat message history
15
  st.session_state.messages = [{"role": "assistant", "content": "Ask me a question about André's research!"}]
16
 
17
-
18
  def main():
19
  # setup logger sidebar
20
  # st.sidebar.text("Standard output log:")
 
5
  from chatbot.data import download_test_data
6
  from chatbot.data import load_data
7
 
8
+ # add all secrets into environmental variables
9
+ try:
10
+ for key, value in st.secrets.items():
11
+ os.environ[key] = value
12
+ except FileNotFoundError as e:
13
+ print(e)
14
+ print("./streamlit/secrets.toml not found. Assuming secrets are already available"
15
+ "as environmental variables...")
16
 
17
  # Initialize message history
18
  st.header("Chat with André's research 💬 📚")
 
20
  if "messages" not in st.session_state.keys(): # Initialize the chat message history
21
  st.session_state.messages = [{"role": "assistant", "content": "Ask me a question about André's research!"}]
22
 
 
23
  def main():
24
  # setup logger sidebar
25
  # st.sidebar.text("Standard output log:")
chatbot/data.py CHANGED
@@ -28,12 +28,12 @@ def load_data():
28
  with st.spinner(text="Setting up Azure OpenAI..."):
29
  llm = AzureOpenAI(
30
  model="gpt-3.5-turbo",
31
- engine=st.secrets["ENGINE"],
32
  temperature=0.5,
33
  api_key=os.environ["OPENAI_API_KEY"],
34
- api_base=st.secrets["OPENAI_API_BASE"],
35
  api_type="azure",
36
- api_version=st.secrets["OPENAI_API_VERSION"],
37
  system_prompt="You are an expert on André's research and your job is to answer"
38
  "technical questions. Assume that all questions are related to"
39
  "André's research. Keep your answers technical and based on facts;"
@@ -44,11 +44,11 @@ def load_data():
44
  # You need to deploy your own embedding model as well as your own chat completion model
45
  embed_model = OpenAIEmbedding(
46
  model="text-embedding-ada-002",
47
- deployment_name=st.secrets["ENGINE_EMBEDDING"],
48
  api_key=os.environ["OPENAI_API_KEY"],
49
- api_base=st.secrets["OPENAI_API_BASE"],
50
  api_type="azure",
51
- api_version=st.secrets["OPENAI_API_VERSION"],
52
  embed_batch_size=10, # set to low value to reduce rate limit -> may degrade response runtime
53
  )
54
 
 
28
  with st.spinner(text="Setting up Azure OpenAI..."):
29
  llm = AzureOpenAI(
30
  model="gpt-3.5-turbo",
31
+ engine=os.environ["ENGINE"],
32
  temperature=0.5,
33
  api_key=os.environ["OPENAI_API_KEY"],
34
+ api_base=os.environ["OPENAI_API_BASE"],
35
  api_type="azure",
36
+ api_version=os.environ["OPENAI_API_VERSION"],
37
  system_prompt="You are an expert on André's research and your job is to answer"
38
  "technical questions. Assume that all questions are related to"
39
  "André's research. Keep your answers technical and based on facts;"
 
44
  # You need to deploy your own embedding model as well as your own chat completion model
45
  embed_model = OpenAIEmbedding(
46
  model="text-embedding-ada-002",
47
+ deployment_name=os.environ["ENGINE_EMBEDDING"],
48
  api_key=os.environ["OPENAI_API_KEY"],
49
+ api_base=os.environ["OPENAI_API_BASE"],
50
  api_type="azure",
51
+ api_version=os.environ["OPENAI_API_VERSION"],
52
  embed_batch_size=10, # set to low value to reduce rate limit -> may degrade response runtime
53
  )
54