prernasingh commited on
Commit
b99dbea
·
verified ·
1 Parent(s): d7a05f2

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +16 -18
app.py CHANGED
@@ -31,8 +31,6 @@ from langchain_core.prompts import ChatPromptTemplate
31
  # LangChain OpenAI imports
32
  from langchain_openai import AzureOpenAIEmbeddings, AzureChatOpenAI # OpenAI embeddings and models
33
  from langchain.embeddings.openai import OpenAIEmbeddings # OpenAI embeddings for text vectors
34
- from langchain_openai import OpenAIEmbeddings, ChatOpenAI
35
- from langchain_openai import ChatOpenAI
36
 
37
  # LlamaParse & LlamaIndex imports
38
  from llama_parse import LlamaParse # Document parsing library
@@ -143,7 +141,7 @@ def expand_query(state):
143
  # Initialize the Chroma vector store for retrieving documents
144
  vector_store = Chroma(
145
  collection_name="nutritional_hypotheticals",
146
- persist_directory="/nutritional_db",
147
  embedding_function=embedding_model
148
 
149
  )
@@ -246,9 +244,9 @@ def score_groundedness(state: Dict) -> Dict:
246
  Dict: The updated state with the groundedness score.
247
  """
248
  print("---------check_groundedness---------")
249
- system_message = '''Given the context and the response, score the response's groundedness,
250
- which represents its factual alignment with the context.
251
- A score of 1.0 represents perfect alignment with the context,
252
  while a score of 0.0 represents a complete lack of alignment.
253
 
254
  Context: {context}
@@ -257,15 +255,15 @@ def score_groundedness(state: Dict) -> Dict:
257
 
258
  ## Instructions:
259
  - Please provide a groundedness score.
260
- - The groundedness score should be a floating point number between 0.0 and 1.0 inclusive.
261
- - Please focus on evaluating the factual consistency and support for the claims
262
- in the response with information provided in the context.
263
- - If the response introduces or hallucinates information not found in the context,
264
  consider it as evidence for a lower score.
265
- - If any facts presented in the response are contradicted or unsupported by the context,
266
  consider it as evidence for a lower score.
267
 
268
- Groundedness Score:
269
  '''
270
 
271
  groundedness_prompt = ChatPromptTemplate.from_messages([
@@ -301,16 +299,16 @@ def check_precision(state: Dict) -> Dict:
301
  system_message = '''Given question, answer and context verify if the context was useful in arriving at the given answer.
302
  ## Instructions:
303
  - Please provide a precision score.
304
- - The precision score should be a floating point number between 0.0 and 1.0 inclusive.
305
- - Please focus on evaluating the factual consistency and support for the claims
306
- in the response with information provided in the context.
307
- - If the response introduces or hallucinates information not found in the context,
308
  consider it as evidence for a lower score.
309
- - If any facts presented in the response are contradicted or unsupported by the context,
310
  consider it as evidence for a lower score.
311
 
312
  Precision score:
313
-
314
  '''
315
 
316
  precision_prompt = ChatPromptTemplate.from_messages([
 
31
  # LangChain OpenAI imports
32
  from langchain_openai import AzureOpenAIEmbeddings, AzureChatOpenAI # OpenAI embeddings and models
33
  from langchain.embeddings.openai import OpenAIEmbeddings # OpenAI embeddings for text vectors
 
 
34
 
35
  # LlamaParse & LlamaIndex imports
36
  from llama_parse import LlamaParse # Document parsing library
 
141
  # Initialize the Chroma vector store for retrieving documents
142
  vector_store = Chroma(
143
  collection_name="nutritional_hypotheticals",
144
+ persist_directory="./nutritional_db",
145
  embedding_function=embedding_model
146
 
147
  )
 
244
  Dict: The updated state with the groundedness score.
245
  """
246
  print("---------check_groundedness---------")
247
+ system_message = '''Given the context and the response, score the response's groundedness,
248
+ which represents its factual alignment with the context.
249
+ A score of 1.0 represents perfect alignment with the context,
250
  while a score of 0.0 represents a complete lack of alignment.
251
 
252
  Context: {context}
 
255
 
256
  ## Instructions:
257
  - Please provide a groundedness score.
258
+ - The groundedness score should be a floating point number between 0.0 and 1.0 inclusive.
259
+ - Please focus on evaluating the factual consistency and support for the claims
260
+ in the response with information provided in the context.
261
+ - If the response introduces or hallucinates information not found in the context,
262
  consider it as evidence for a lower score.
263
+ - If any facts presented in the response are contradicted or unsupported by the context,
264
  consider it as evidence for a lower score.
265
 
266
+ Groundedness Score:
267
  '''
268
 
269
  groundedness_prompt = ChatPromptTemplate.from_messages([
 
299
  system_message = '''Given question, answer and context verify if the context was useful in arriving at the given answer.
300
  ## Instructions:
301
  - Please provide a precision score.
302
+ - The precision score should be a floating point number between 0.0 and 1.0 inclusive.
303
+ - Please focus on evaluating the factual consistency and support for the claims
304
+ in the response with information provided in the context.
305
+ - If the response introduces or hallucinates information not found in the context,
306
  consider it as evidence for a lower score.
307
+ - If any facts presented in the response are contradicted or unsupported by the context,
308
  consider it as evidence for a lower score.
309
 
310
  Precision score:
311
+
312
  '''
313
 
314
  precision_prompt = ChatPromptTemplate.from_messages([