Update app.py
Browse files
app.py
CHANGED
@@ -48,9 +48,9 @@ def augment_multiple_query(query):
|
|
48 |
messages=[
|
49 |
{
|
50 |
"role": "system",
|
51 |
-
"content": f"""You are a helpful expert in {topic}. Your users are asking questions about {topic}.
|
52 |
-
Suggest up to five additional related questions to help them find the information they need for the provided question.
|
53 |
-
Suggest only short questions without compound sentences. Suggest a variety of questions that cover different aspects of the topic.
|
54 |
Make sure they are complete questions, and that they are related to the original question."""
|
55 |
},
|
56 |
{
|
@@ -62,37 +62,10 @@ def augment_multiple_query(query):
|
|
62 |
)
|
63 |
return content.choices[0].message.content.split("\n")
|
64 |
|
65 |
-
# Custom function to handle fuzzy keyword searches
|
66 |
-
def load_wikipedia_page(topic):
|
67 |
-
try:
|
68 |
-
# Attempt to load the page directly
|
69 |
-
page = wikipedia.page(topic)
|
70 |
-
return page.content
|
71 |
-
|
72 |
-
except wikipedia.exceptions.DisambiguationError as e:
|
73 |
-
# Handle disambiguation page case
|
74 |
-
st.write(f"The keyword '{topic}' returned multiple possible pages.")
|
75 |
-
st.write("Please refine your search or select one of the following options:")
|
76 |
-
|
77 |
-
# List disambiguation options
|
78 |
-
options = e.options
|
79 |
-
selected_option = st.selectbox("Select the closest match:", options)
|
80 |
-
|
81 |
-
# Load the selected option
|
82 |
-
page = wikipedia.page(selected_option)
|
83 |
-
return page.content
|
84 |
-
|
85 |
-
except wikipedia.exceptions.PageError:
|
86 |
-
# Handle the case where no page is found
|
87 |
-
st.write(f"No page found for '{topic}'. Please try a different keyword.")
|
88 |
-
return None
|
89 |
-
|
90 |
# Function to handle RAG-based question answering
|
91 |
def rag_advanced(user_query):
|
92 |
# Document Loading
|
93 |
-
|
94 |
-
if docs_content:
|
95 |
-
docs = [docs_content] # Wrap the content in a list for consistency
|
96 |
|
97 |
# Text Splitting
|
98 |
character_splitter = RecursiveCharacterTextSplitter(separators=["\n\n", "\n", ". ", " ", ""], chunk_size=1000, chunk_overlap=0)
|
@@ -134,8 +107,8 @@ def rag_advanced(user_query):
|
|
134 |
messages=[
|
135 |
{
|
136 |
"role": "system",
|
137 |
-
"content": f"""You are a helpful expert in {topic}. Your users are asking questions about {topic}.
|
138 |
-
You will be shown the user's questions, and the relevant information from the documents related to {topic}.
|
139 |
Answer the user's question using only this information."""
|
140 |
},
|
141 |
{
|
|
|
48 |
messages=[
|
49 |
{
|
50 |
"role": "system",
|
51 |
+
"content": f"""You are a helpful expert in {topic}. Your users are asking questions about {topic}.
|
52 |
+
Suggest up to five additional related questions to help them find the information they need for the provided question.
|
53 |
+
Suggest only short questions without compound sentences. Suggest a variety of questions that cover different aspects of the topic.
|
54 |
Make sure they are complete questions, and that they are related to the original question."""
|
55 |
},
|
56 |
{
|
|
|
62 |
)
|
63 |
return content.choices[0].message.content.split("\n")
|
64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
# Function to handle RAG-based question answering
|
66 |
def rag_advanced(user_query):
|
67 |
# Document Loading
|
68 |
+
docs = WikipediaLoader(query=topic).load()
|
|
|
|
|
69 |
|
70 |
# Text Splitting
|
71 |
character_splitter = RecursiveCharacterTextSplitter(separators=["\n\n", "\n", ". ", " ", ""], chunk_size=1000, chunk_overlap=0)
|
|
|
107 |
messages=[
|
108 |
{
|
109 |
"role": "system",
|
110 |
+
"content": f"""You are a helpful expert in {topic}. Your users are asking questions about {topic}.
|
111 |
+
You will be shown the user's questions, and the relevant information from the documents related to {topic}.
|
112 |
Answer the user's question using only this information."""
|
113 |
},
|
114 |
{
|