Tim F commited on
Commit
e16892f
Β·
1 Parent(s): 77e791d

added secrets file for openai key

Browse files
Files changed (2) hide show
  1. .streamlit/secrets.toml +1 -0
  2. app.py +7 -5
.streamlit/secrets.toml ADDED
@@ -0,0 +1 @@
 
 
1
+ OPENAI_API_KEY = "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"
app.py CHANGED
@@ -12,11 +12,11 @@ from langchain_core.prompts import ChatPromptTemplate
12
 
13
  from langchain_community.document_loaders import UnstructuredFileLoader
14
 
15
- import os
16
- os.environ["OPENAI_API_KEY"] = "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"
17
 
18
  # Get all the filenames from the docs folder
19
  files = glob.glob("./docs/*.txt")
 
20
  # Load files into readable documents
21
  docs = []
22
  for file in files:
@@ -68,7 +68,7 @@ rag_chain = (
68
  | StrOutputParser()
69
  )
70
 
71
- st.title("πŸ’¬ Volker-Chat")
72
 
73
  if "messages" not in st.session_state:
74
  st.session_state["messages"] = [{"role": "assistant", "content": "Ahoi! Ich bin Volker. Wie kann ich dir helfen?"}]
@@ -78,5 +78,7 @@ for msg in st.session_state.messages:
78
 
79
  if prompt := st.chat_input():
80
  st.chat_message("user").write(prompt)
81
- response = rag_chain.invoke(prompt)
82
- st.chat_message("assistant").write(response)
 
 
 
12
 
13
  from langchain_community.document_loaders import UnstructuredFileLoader
14
 
15
+ OPENAI_API_KEY = st.secrets["OPENAI_API_KEY"]
 
16
 
17
  # Get all the filenames from the docs folder
18
  files = glob.glob("./docs/*.txt")
19
+
20
  # Load files into readable documents
21
  docs = []
22
  for file in files:
 
68
  | StrOutputParser()
69
  )
70
 
71
+ st.title("πŸ” Volker-Chat")
72
 
73
  if "messages" not in st.session_state:
74
  st.session_state["messages"] = [{"role": "assistant", "content": "Ahoi! Ich bin Volker. Wie kann ich dir helfen?"}]
 
78
 
79
  if prompt := st.chat_input():
80
  st.chat_message("user").write(prompt)
81
+ with get_openai_callback() as cb:
82
+ response = rag_chain.invoke(prompt)
83
+ st.chat_message("assistant").write(response)
84
+ st.chat_message("assistant").write(cb)