tstone87 commited on
Commit
ec4c7d2
·
verified ·
1 Parent(s): 47f602f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -8
app.py CHANGED
@@ -27,7 +27,7 @@ def load_json_data():
27
  data = load_json_data()
28
 
29
  # 🔹 Initialize FAISS for Searching Relevant Answers
30
- model = SentenceTransformer("all-MiniLM-L12-v2") # Faster with good accuracy
31
 
32
  def create_faiss_index(data):
33
  texts = list(data.values())
@@ -45,7 +45,7 @@ def search_faiss(query, top_k=1):
45
  return texts[indices[0][0]] if indices[0][0] < len(texts) else "No relevant information found."
46
 
47
  # 🔹 Hugging Face API for Additional Responses
48
- client = InferenceClient("meta-llama/Meta-Llama-3-8B-Instruct")
49
 
50
  def get_huggingface_response(query):
51
  messages = [{"role": "system", "content": "Provide accurate food stamp information for Colorado."},
@@ -57,19 +57,23 @@ def get_huggingface_response(query):
57
 
58
  # 🔹 Main Chatbot Function
59
  def chatbot_response(message, history):
60
- relevant_info = search_faiss(message)
61
 
62
  if "No relevant information found." not in relevant_info:
63
- # Summarize and clarify the retrieved policy text using Hugging Face LLM
64
  user_query_with_context = f"""
65
- The user is asking: {message}
66
 
67
- The most relevant policy information retrieved is:
68
 
 
69
  {relevant_info}
70
 
71
- Please summarize this information in a clear, concise, and user-friendly way for someone inquiring about Colorado food stamps.
72
- Provide the most recent information you can. If the most relevant policy information does not seem to apply do your best to answer the question accurately but make it clear you are not pulling the reply from the SNAP policy CCR and at that point you can encourage they try searching other keywords to possibly find better policy information.
 
 
 
 
73
  """
74
 
75
  return get_huggingface_response(user_query_with_context)
 
27
  data = load_json_data()
28
 
29
  # 🔹 Initialize FAISS for Searching Relevant Answers
30
+ model = SentenceTransformer("multi-qa-mpnet-base-dot-v1 ") # slower with great accuracy
31
 
32
  def create_faiss_index(data):
33
  texts = list(data.values())
 
45
  return texts[indices[0][0]] if indices[0][0] < len(texts) else "No relevant information found."
46
 
47
  # 🔹 Hugging Face API for Additional Responses
48
+ client = InferenceClient("mistralai/Mixtral-8x7B-Instruct")
49
 
50
  def get_huggingface_response(query):
51
  messages = [{"role": "system", "content": "Provide accurate food stamp information for Colorado."},
 
57
 
58
  # 🔹 Main Chatbot Function
59
  def chatbot_response(message, history):
60
+ relevant_info = search_faiss(message, top_k=3) # Retrieve 3 most relevant sections
61
 
62
  if "No relevant information found." not in relevant_info:
 
63
  user_query_with_context = f"""
64
+ You are an expert in Colorado SNAP (food stamp) policies. The user is asking:
65
 
66
+ **User Question:** {message}
67
 
68
+ ### **Relevant Policy Information Retrieved (Multiple Sources)**
69
  {relevant_info}
70
 
71
+ ### **Task:**
72
+ - **Summarize all retrieved policy information** and provide a clear, concise answer.
73
+ - **Use bullet points** for clarity.
74
+ - **If a rule applies, state it explicitly.**
75
+ - **If multiple sources provide different information, clarify the distinctions.**
76
+ - **If the policy does not fully answer the question, provide general guidance and suggest relevant keywords to search.**
77
  """
78
 
79
  return get_huggingface_response(user_query_with_context)