iamrobotbear commited on
Commit
7bbdc33
1 Parent(s): 7a9af26

Update query.py

Browse files
Files changed (1) hide show
  1. query.py +6 -7
query.py CHANGED
@@ -1,6 +1,5 @@
1
  import requests
2
  import json
3
- import re
4
 
5
  class VectaraQuery():
6
  def __init__(self, api_key: str, customer_id: str, corpus_id: str, prompt_name: str = None):
@@ -92,18 +91,18 @@ class VectaraQuery():
92
  text = result['text']
93
  print(f"Processing text: {text}") # Debugging line
94
 
95
- # Instead of using regex, split the text by specific keywords
96
- reason = self.extract_between_keywords(text, "Reason:", "Alternative:")
97
- alternative = self.extract_between_keywords(text, "Alternative:", "Notes:")
98
- notes = self.extract_between_keywords(text, "Notes:", "")
99
 
100
- response = f"Reason: {reason.strip()}\nAlternative: {alternative.strip()}\nNotes: {notes.strip()}"
101
  print(f"Generated response: {response}") # Debugging line
102
  return response
103
 
104
  return "No relevant information found."
105
 
106
- def extract_between_keywords(self, text, start_keyword, end_keyword):
107
  start_idx = text.find(start_keyword)
108
  if start_idx == -1:
109
  return "Not available"
 
1
  import requests
2
  import json
 
3
 
4
  class VectaraQuery():
5
  def __init__(self, api_key: str, customer_id: str, corpus_id: str, prompt_name: str = None):
 
91
  text = result['text']
92
  print(f"Processing text: {text}") # Debugging line
93
 
94
+ # Improved keyword-based extraction
95
+ reason = self.extract_text(text, "Reason:", "Alternative:")
96
+ alternative = self.extract_text(text, "Alternative:", "Notes:")
97
+ notes = self.extract_text(text, "Notes:", "")
98
 
99
+ response = f"Reason: {reason}\nAlternative: {alternative}\nNotes: {notes}"
100
  print(f"Generated response: {response}") # Debugging line
101
  return response
102
 
103
  return "No relevant information found."
104
 
105
+ def extract_text(self, text, start_keyword, end_keyword):
106
  start_idx = text.find(start_keyword)
107
  if start_idx == -1:
108
  return "Not available"