Pijush2023 commited on
Commit
50b7e5a
·
verified ·
1 Parent(s): 54c6fcd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -1
app.py CHANGED
@@ -114,6 +114,7 @@ def generate_full_text_query(input: str) -> str:
114
  return full_text_query.strip()
115
 
116
 
 
117
  # Function to generate audio with Eleven Labs TTS
118
  def generate_audio_elevenlabs(text):
119
  XI_API_KEY = os.environ['ELEVENLABS_API']
@@ -170,8 +171,17 @@ def generate_response_with_prompt(context, question):
170
 
171
 
172
 
 
173
  # Define the function to generate a hybrid response using Neo4j and other retrieval methods
174
  def retriever(question: str):
 
 
 
 
 
 
 
 
175
  # Structured data retrieval from Neo4j
176
  structured_query = f"""
177
  CALL db.index.fulltext.queryNodes('entity', $query, {{limit: 2}})
@@ -180,7 +190,7 @@ def retriever(question: str):
180
  ORDER BY score DESC
181
  LIMIT 2
182
  """
183
- structured_data = graph.query(structured_query, {"query": generate_full_text_query(question)})
184
  structured_response = "\n".join([f"{record['entity']}: {record['context']}" for record in structured_data])
185
 
186
  # Unstructured data retrieval from vector store
@@ -194,6 +204,7 @@ def retriever(question: str):
194
  final_response = generate_response_with_prompt(combined_context, question)
195
  return final_response
196
 
 
197
  # Function to handle the entire audio query and response process
198
  def process_audio_query(audio_input):
199
  stream = None
 
114
  return full_text_query.strip()
115
 
116
 
117
+
118
  # Function to generate audio with Eleven Labs TTS
119
  def generate_audio_elevenlabs(text):
120
  XI_API_KEY = os.environ['ELEVENLABS_API']
 
171
 
172
 
173
 
174
+
175
  # Define the function to generate a hybrid response using Neo4j and other retrieval methods
176
  def retriever(question: str):
177
+ # Generate the full-text query for Neo4j
178
+ full_text_query = generate_full_text_query(question)
179
+
180
+ # If the generated query is empty, skip the Neo4j query and return a default response
181
+ if not full_text_query:
182
+ print("Empty query, skipping Neo4j search.")
183
+ return "I'm sorry, I didn't catch that. Could you please repeat your question?"
184
+
185
  # Structured data retrieval from Neo4j
186
  structured_query = f"""
187
  CALL db.index.fulltext.queryNodes('entity', $query, {{limit: 2}})
 
190
  ORDER BY score DESC
191
  LIMIT 2
192
  """
193
+ structured_data = graph.query(structured_query, {"query": full_text_query})
194
  structured_response = "\n".join([f"{record['entity']}: {record['context']}" for record in structured_data])
195
 
196
  # Unstructured data retrieval from vector store
 
204
  final_response = generate_response_with_prompt(combined_context, question)
205
  return final_response
206
 
207
+
208
  # Function to handle the entire audio query and response process
209
  def process_audio_query(audio_input):
210
  stream = None