Phoenix21 commited on
Commit
52fbede
·
1 Parent(s): 60e4b1b

removed step 8 as it is not working because of it

Browse files
Files changed (1) hide show
  1. app.py +25 -25
app.py CHANGED
@@ -115,34 +115,34 @@ class ChatHistory:
115
  chat_history = ChatHistory()
116
 
117
  # Step 5: Self-Verification and Content Moderation
118
- def verify_health_wellness_query(query, retrieved_data):
119
- """
120
- Verifies if the query is related to health and wellness and checks if retrieved data is relevant.
121
- """
122
- query_lower = query.lower()
123
-
124
- # Use Groq's LLM to evaluate the safety of the query (new LLM-based moderation)
125
- chat_completion = client.chat.completions.create(
126
- messages=[
127
- {"role": "user", "content": query}
128
- ],
129
- model="llama-guard-3-8b",
130
- )
131
 
132
- moderation_result = chat_completion.choices[0].message.content.strip()
133
 
134
- # If the model's response indicates harmful content, block the query
135
- if 'unsafe' in moderation_result.lower() or 'harmful' in moderation_result.lower():
136
- return False, "The query is flagged as unsafe or harmful. Please rephrase it."
137
 
138
- # Proceed with verifying if the retrieved data aligns with the health/wellness context
139
- wellness_keywords = ['mental health', 'stress', 'wellness', 'anxiety', 'relaxation', 'meditation']
140
 
141
- # Check if the query contains any of the relevant wellness-related keywords
142
- if any(keyword in query_lower for keyword in wellness_keywords):
143
- return True, "" # If any relevant wellness keyword is present, it's valid
144
 
145
- return False, "The query does not seem to match health and wellness topics."
146
 
147
  # Step 6: Define Gradio Interface for Chatbot
148
  def gradio_chatbot(user_query):
@@ -150,8 +150,8 @@ def gradio_chatbot(user_query):
150
  retrieved_data = chatbot_response(user_query)
151
 
152
  # Step 8: Check and verify the query for health/wellness content
153
- is_valid, message = verify_health_wellness_query(user_query, retrieved_data)
154
-
155
  if is_valid:
156
  # Generate a coherent response using Groq's DeepSeek-R1 LLM
157
  coherent_response = generate_coherent_response(user_query, retrieved_data, chat_history.get_history())
 
115
  chat_history = ChatHistory()
116
 
117
  # Step 5: Self-Verification and Content Moderation
118
+ # def verify_health_wellness_query(query, retrieved_data):
119
+ # """
120
+ # Verifies if the query is related to health and wellness and checks if retrieved data is relevant.
121
+ # """
122
+ # query_lower = query.lower()
123
+
124
+ # # Use Groq's LLM to evaluate the safety of the query (new LLM-based moderation)
125
+ # chat_completion = client.chat.completions.create(
126
+ # messages=[
127
+ # {"role": "user", "content": query}
128
+ # ],
129
+ # model="llama-guard-3-8b",
130
+ # )
131
 
132
+ # moderation_result = chat_completion.choices[0].message.content.strip()
133
 
134
+ # # If the model's response indicates harmful content, block the query
135
+ # if 'unsafe' in moderation_result.lower() or 'harmful' in moderation_result.lower():
136
+ # return False, "The query is flagged as unsafe or harmful. Please rephrase it."
137
 
138
+ # # Proceed with verifying if the retrieved data aligns with the health/wellness context
139
+ # wellness_keywords = ['mental health', 'stress', 'wellness', 'anxiety', 'relaxation', 'meditation']
140
 
141
+ # # Check if the query contains any of the relevant wellness-related keywords
142
+ # if any(keyword in query_lower for keyword in wellness_keywords):
143
+ # return True, "" # If any relevant wellness keyword is present, it's valid
144
 
145
+ # return False, "The query does not seem to match health and wellness topics."
146
 
147
  # Step 6: Define Gradio Interface for Chatbot
148
  def gradio_chatbot(user_query):
 
150
  retrieved_data = chatbot_response(user_query)
151
 
152
  # Step 8: Check and verify the query for health/wellness content
153
+ # is_valid, message = verify_health_wellness_query(user_query, retrieved_data)
154
+ is_valid = True
155
  if is_valid:
156
  # Generate a coherent response using Groq's DeepSeek-R1 LLM
157
  coherent_response = generate_coherent_response(user_query, retrieved_data, chat_history.get_history())