Upload 5 files
Browse files- LLMInsights.py +16 -9
LLMInsights.py
CHANGED
@@ -127,7 +127,8 @@ class HallucinatonEvaluater:
|
|
127 |
|
128 |
|
129 |
|
130 |
-
|
|
|
131 |
def initialize_vectorstore():
|
132 |
|
133 |
webpage_loader = WebBaseLoader("https://www.tredence.com/case-studies/forecasting-app-installs-for-a-large-retailer-in-the-us").load()
|
@@ -144,6 +145,7 @@ def initialize_vectorstore():
|
|
144 |
retriever = vectorstore.as_retriever()
|
145 |
st.session_state['vectorstore'] = vectorstore
|
146 |
st.session_state['docadd'] = 0
|
|
|
147 |
|
148 |
return retriever
|
149 |
|
@@ -218,7 +220,7 @@ def scoring_eval(question: str, answer: str, context: str):
|
|
218 |
}
|
219 |
)
|
220 |
print("got score")
|
221 |
-
st.markdown('<h1 style="color:#100170;font-size:24px;">Score</h1>', unsafe_allow_html=True)
|
222 |
st.text_area(label=" ", value=score, height=30)
|
223 |
#return {"hallucination_score": hallucination_score}
|
224 |
#time.sleep(10)
|
@@ -247,18 +249,18 @@ And you'll need to submit your grading for the correctness, comprehensiveness an
|
|
247 |
- Correctness: If the answer correctly answer the question, below are the details for different scores:
|
248 |
- Score 0: the answer is completely incorrect, doesn’t mention anything about the question or is completely contrary to the correct answer.
|
249 |
- For example, when asked “How to terminate a databricks cluster”, the answer is empty string, or content that’s completely irrelevant, or sorry I don’t know the answer.
|
250 |
-
- Score
|
251 |
- Example:
|
252 |
- Question: How to terminate a databricks cluster
|
253 |
- Answer: Databricks cluster is a cloud-based computing environment that allows users to process big data and run distributed data processing tasks efficiently.
|
254 |
- Or answer: In the Databricks workspace, navigate to the "Clusters" tab. And then this is a hard question that I need to think more about it
|
255 |
-
- Score
|
256 |
- Example:
|
257 |
- Question: How to terminate a databricks cluster”
|
258 |
- Answer: “In the Databricks workspace, navigate to the "Clusters" tab.
|
259 |
Find the cluster you want to terminate from the list of active clusters.
|
260 |
And then you’ll find a button to terminate all clusters at once”
|
261 |
-
- Score
|
262 |
- Example:
|
263 |
- Question: How to terminate a databricks cluster
|
264 |
- Answer: In the Databricks workspace, navigate to the "Clusters" tab.
|
@@ -311,11 +313,16 @@ with tab1:
|
|
311 |
with st.form(" RAG with evaluation - scoring & hallucination "):
|
312 |
#tab1.subheader(''' # RAG App''')
|
313 |
initialize_vectorstore()
|
314 |
-
|
315 |
-
|
316 |
-
|
|
|
|
|
|
|
|
|
|
|
317 |
retriever = initialize_vectorstore()
|
318 |
-
|
319 |
#print("lenght in tab1, ", len(vectorstore.serialize_to_bytes()))
|
320 |
options = ["true", "false"]
|
321 |
|
|
|
127 |
|
128 |
|
129 |
|
130 |
+
#@st.cache_resource
|
131 |
+
@st.cache_data
|
132 |
def initialize_vectorstore():
|
133 |
|
134 |
webpage_loader = WebBaseLoader("https://www.tredence.com/case-studies/forecasting-app-installs-for-a-large-retailer-in-the-us").load()
|
|
|
145 |
retriever = vectorstore.as_retriever()
|
146 |
st.session_state['vectorstore'] = vectorstore
|
147 |
st.session_state['docadd'] = 0
|
148 |
+
print("st.session_state['docadd'] ", st.session_state['docadd'])
|
149 |
|
150 |
return retriever
|
151 |
|
|
|
220 |
}
|
221 |
)
|
222 |
print("got score")
|
223 |
+
st.markdown('<h1 style="color:#100170;font-size:24px;">Completion Score</h1>', unsafe_allow_html=True)
|
224 |
st.text_area(label=" ", value=score, height=30)
|
225 |
#return {"hallucination_score": hallucination_score}
|
226 |
#time.sleep(10)
|
|
|
249 |
- Correctness: If the answer correctly answer the question, below are the details for different scores:
|
250 |
- Score 0: the answer is completely incorrect, doesn’t mention anything about the question or is completely contrary to the correct answer.
|
251 |
- For example, when asked “How to terminate a databricks cluster”, the answer is empty string, or content that’s completely irrelevant, or sorry I don’t know the answer.
|
252 |
+
- Score 50: the answer provides some relevance to the question and answer one aspect of the question correctly.
|
253 |
- Example:
|
254 |
- Question: How to terminate a databricks cluster
|
255 |
- Answer: Databricks cluster is a cloud-based computing environment that allows users to process big data and run distributed data processing tasks efficiently.
|
256 |
- Or answer: In the Databricks workspace, navigate to the "Clusters" tab. And then this is a hard question that I need to think more about it
|
257 |
+
- Score 75: the answer mostly answer the question but is missing or hallucinating on one critical aspect.
|
258 |
- Example:
|
259 |
- Question: How to terminate a databricks cluster”
|
260 |
- Answer: “In the Databricks workspace, navigate to the "Clusters" tab.
|
261 |
Find the cluster you want to terminate from the list of active clusters.
|
262 |
And then you’ll find a button to terminate all clusters at once”
|
263 |
+
- Score 100: the answer correctly answer the question and not missing any major aspect
|
264 |
- Example:
|
265 |
- Question: How to terminate a databricks cluster
|
266 |
- Answer: In the Databricks workspace, navigate to the "Clusters" tab.
|
|
|
313 |
with st.form(" RAG with evaluation - scoring & hallucination "):
|
314 |
#tab1.subheader(''' # RAG App''')
|
315 |
initialize_vectorstore()
|
316 |
+
time.sleep(2)
|
317 |
+
try:
|
318 |
+
if st.session_state['docadd'] == 1:
|
319 |
+
retriever = st.session_state['retriever']
|
320 |
+
else:
|
321 |
+
retriever = initialize_vectorstore()
|
322 |
+
except:
|
323 |
+
st.session_state['docadd'] = 0
|
324 |
retriever = initialize_vectorstore()
|
325 |
+
|
326 |
#print("lenght in tab1, ", len(vectorstore.serialize_to_bytes()))
|
327 |
options = ["true", "false"]
|
328 |
|