Update app.py
Browse files
app.py
CHANGED
|
@@ -16,7 +16,7 @@ import pinecone
|
|
| 16 |
from results import results_agent
|
| 17 |
from filter import filter_agent
|
| 18 |
from reranker import reranker
|
| 19 |
-
from utils import build_filter
|
| 20 |
from router import routing_agent
|
| 21 |
|
| 22 |
OPENAI_API = st.secrets["OPENAI_API"]
|
|
@@ -44,8 +44,7 @@ class_time = st.slider(
|
|
| 44 |
|
| 45 |
units = st.slider(
|
| 46 |
"Number of units",
|
| 47 |
-
1, 4,
|
| 48 |
-
value = (1, 4)
|
| 49 |
)
|
| 50 |
|
| 51 |
days = st.multiselect("What days are you free?",
|
|
@@ -57,6 +56,8 @@ days = st.multiselect("What days are you free?",
|
|
| 57 |
assistant = st.chat_message("assistant")
|
| 58 |
initial_message = "How can I help you today?"
|
| 59 |
|
|
|
|
|
|
|
| 60 |
def get_rag_results(prompt):
|
| 61 |
'''
|
| 62 |
1. Remove filters from the prompt to optimize success of the RAG-based step.
|
|
@@ -86,13 +87,15 @@ def get_rag_results(prompt):
|
|
| 86 |
## Query the pinecone database
|
| 87 |
response = index.query(
|
| 88 |
vector = embeddings.embed_query(query),
|
| 89 |
-
top_k =
|
| 90 |
filter = query_filter,
|
| 91 |
include_metadata = True
|
| 92 |
)
|
|
|
|
|
|
|
| 93 |
response = reranker(query, response) # BERT cross encoder for ranking
|
| 94 |
|
| 95 |
-
return response
|
| 96 |
|
| 97 |
|
| 98 |
|
|
@@ -120,8 +123,8 @@ if prompt := st.chat_input("What kind of class are you looking for?"):
|
|
| 120 |
|
| 121 |
if route == "1":
|
| 122 |
## Option for accessing Vector DB
|
| 123 |
-
rag_response = get_rag_results(prompt)
|
| 124 |
-
result_query = 'Original Query:' + prompt + 'Query Results:' + str(rag_response)
|
| 125 |
assistant_response = results_agent(result_query, OPENAI_API)
|
| 126 |
else:
|
| 127 |
## Option if not accessing Database
|
|
|
|
| 16 |
from results import results_agent
|
| 17 |
from filter import filter_agent
|
| 18 |
from reranker import reranker
|
| 19 |
+
from utils import build_filter, clean_pinecone
|
| 20 |
from router import routing_agent
|
| 21 |
|
| 22 |
OPENAI_API = st.secrets["OPENAI_API"]
|
|
|
|
| 44 |
|
| 45 |
units = st.slider(
|
| 46 |
"Number of units",
|
| 47 |
+
1, 4, 4
|
|
|
|
| 48 |
)
|
| 49 |
|
| 50 |
days = st.multiselect("What days are you free?",
|
|
|
|
| 56 |
assistant = st.chat_message("assistant")
|
| 57 |
initial_message = "How can I help you today?"
|
| 58 |
|
| 59 |
+
|
| 60 |
+
|
| 61 |
def get_rag_results(prompt):
|
| 62 |
'''
|
| 63 |
1. Remove filters from the prompt to optimize success of the RAG-based step.
|
|
|
|
| 87 |
## Query the pinecone database
|
| 88 |
response = index.query(
|
| 89 |
vector = embeddings.embed_query(query),
|
| 90 |
+
top_k = 45,
|
| 91 |
filter = query_filter,
|
| 92 |
include_metadata = True
|
| 93 |
)
|
| 94 |
+
|
| 95 |
+
response, additional_metadata = clean_pinecone(response)
|
| 96 |
response = reranker(query, response) # BERT cross encoder for ranking
|
| 97 |
|
| 98 |
+
return response, additional_metadata
|
| 99 |
|
| 100 |
|
| 101 |
|
|
|
|
| 123 |
|
| 124 |
if route == "1":
|
| 125 |
## Option for accessing Vector DB
|
| 126 |
+
rag_response, additional_metadata = get_rag_results(prompt)
|
| 127 |
+
result_query = 'Original Query:' + prompt + 'Query Results:' + str(rag_response) + '\n Additional Class Times:' + str(additional_metadata)
|
| 128 |
assistant_response = results_agent(result_query, OPENAI_API)
|
| 129 |
else:
|
| 130 |
## Option if not accessing Database
|