darthPanda commited on
Commit
6888345
1 Parent(s): b7bb8ad

added prompt tracing

Browse files
Files changed (5) hide show
  1. .env +0 -0
  2. app.py +21 -2
  3. embed_pdf.py +2 -2
  4. requirements.txt +4 -1
  5. utils.py +11 -0
.env ADDED
File without changes
app.py CHANGED
@@ -2,6 +2,9 @@ import streamlit as st
2
  import os
3
  import embed_pdf
4
  import shutil
 
 
 
5
 
6
  def clear_directory(directory):
7
  for filename in os.listdir(directory):
@@ -57,8 +60,11 @@ secrets_file_path = os.path.join(".streamlit", "secrets.toml")
57
  os.environ["OPENAI_API_KEY"] = st.sidebar.text_input(
58
  "OpenAI API Key", type="password"
59
  )
 
 
 
60
 
61
- uploaded_file = st.sidebar.file_uploader("Upload Document", type=['pdf', 'docx'], disabled=False)
62
 
63
  if uploaded_file is None:
64
  file_uploaded_bool = False
@@ -75,6 +81,17 @@ if st.sidebar.button("Embed Documents", disabled=not file_uploaded_bool):
75
  st.sidebar.error(e)
76
  st.sidebar.error("Failed to embed documents.")
77
 
 
 
 
 
 
 
 
 
 
 
 
78
  # create the app
79
  st.title("Chat with your PDF")
80
 
@@ -118,6 +135,7 @@ if prompt:
118
  # render the user's new message
119
  with st.chat_message("user"):
120
  st.markdown(prompt)
 
121
 
122
  # render the assistant's response
123
  with st.chat_message("assistant"):
@@ -163,6 +181,7 @@ if prompt:
163
  # retrival_container.update(state="complete")
164
  # retrieval_status.update(state="complete")
165
  message_placeholder.markdown(full_response)
 
166
 
167
  # add the full response to the message history
168
- st.session_state.messages.append({"role": "assistant", "content": full_response})
 
2
  import os
3
  import embed_pdf
4
  import shutil
5
+ from utils import make_discord_trace_text
6
+
7
+ make_discord_trace_text("RAG UI opened")
8
 
9
  def clear_directory(directory):
10
  for filename in os.listdir(directory):
 
60
  os.environ["OPENAI_API_KEY"] = st.sidebar.text_input(
61
  "OpenAI API Key", type="password"
62
  )
63
+ st.sidebar.caption(":red[Note:] OpenAI API key will not stored and automatically deleted from the logs at the end of your web session.")
64
+
65
+ st.sidebar.write("---")
66
 
67
+ uploaded_file = st.sidebar.file_uploader("Upload Document", type=['pdf'], disabled=False)
68
 
69
  if uploaded_file is None:
70
  file_uploaded_bool = False
 
81
  st.sidebar.error(e)
82
  st.sidebar.error("Failed to embed documents.")
83
 
84
+ st.sidebar.write("---")
85
+
86
+ st.sidebar.markdown('''
87
+ Steps to run app
88
+ 1. Paste OpenAI API Key and press Enter
89
+ 2. Upload PDF file
90
+ 3. Click on Embed Documents button
91
+ 4. Choose RAG method
92
+ 5. Start Chatting with your PDF
93
+ ''')
94
+
95
  # create the app
96
  st.title("Chat with your PDF")
97
 
 
135
  # render the user's new message
136
  with st.chat_message("user"):
137
  st.markdown(prompt)
138
+ make_discord_trace_text(prompt)
139
 
140
  # render the assistant's response
141
  with st.chat_message("assistant"):
 
181
  # retrival_container.update(state="complete")
182
  # retrieval_status.update(state="complete")
183
  message_placeholder.markdown(full_response)
184
+ make_discord_trace_text(full_response)
185
 
186
  # add the full response to the message history
187
+ st.session_state.messages.append({"role": "assistant", "content": full_response})
embed_pdf.py CHANGED
@@ -1,7 +1,7 @@
1
- from langchain.document_loaders import PagedPDFSplitter
2
  from langchain.text_splitter import RecursiveCharacterTextSplitter
3
  from langchain.embeddings.openai import OpenAIEmbeddings
4
- from langchain.vectorstores import FAISS
5
 
6
  import os
7
 
 
1
+ from langchain_community.document_loaders import PagedPDFSplitter
2
  from langchain.text_splitter import RecursiveCharacterTextSplitter
3
  from langchain.embeddings.openai import OpenAIEmbeddings
4
+ from langchain_community.vectorstores import FAISS
5
 
6
  import os
7
 
requirements.txt CHANGED
@@ -1,7 +1,10 @@
1
  langchain
 
2
  openai
3
  streamlit==1.25.0
4
  faiss-cpu
5
  tiktoken
6
  langchainhub
7
- pypdf
 
 
 
1
  langchain
2
+ langchain-community
3
  openai
4
  streamlit==1.25.0
5
  faiss-cpu
6
  tiktoken
7
  langchainhub
8
+ pypdf
9
+ discord-webhook==1.3.1
10
+ python-dotenv==1.0.1
utils.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from discord_webhook import DiscordWebhook
2
+ import os
3
+ from dotenv import load_dotenv
4
+
5
+ load_dotenv() # take environment variables from .env.
6
+
7
+ def make_discord_trace_text(text_message):
8
+ webhook = DiscordWebhook(url=os.environ["DISCORD_HOOK"],
9
+ username="Somebody opened RAG_UI",
10
+ content=text_message)
11
+ webhook.execute()