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

Update query.py

Browse files
Files changed (1) hide show
  1. query.py +26 -18
query.py CHANGED
@@ -20,7 +20,11 @@ class VectaraQuery():
20
  [
21
  {{
22
  "role": "system",
23
- "content": "You are an assistant that provides information about drink names based on a given corpus."
 
 
 
 
24
  }},
25
  {{
26
  "role": "user",
@@ -88,25 +92,29 @@ class VectaraQuery():
88
  text = result['text']
89
  print(f"Processing text: {text}") # Debugging line
90
 
91
- # Adjusting regex patterns to be more flexible
92
- reason_match = re.search(r"Reason Why it Can't be Used:\s*(.*?)(?:\n|$)", text, re.DOTALL)
93
- alternative_match = re.search(r"Alternative:\s*(.*?)(?:\n|$)", text, re.DOTALL)
94
- notes_match = re.search(r"Notes:\s*(.*?)(?:\n|$)", text, re.DOTALL)
95
-
96
- # Improved regex to capture multiline fields
97
- if not reason_match:
98
- reason_match = re.search(r"DISCUSSION\s*-\s*(.*?)(?=\n|\r\n)", text, re.DOTALL)
99
- if not alternative_match:
100
- alternative_match = re.search(r"Alternative\s*:\s*(.*?)(?=\n|\r\n)", text, re.DOTALL)
101
- if not notes_match:
102
- notes_match = re.search(r"Notes\s*:\s*(.*?)(?=\n|\r\n)", text, re.DOTALL)
103
 
104
- reason = reason_match.group(1).strip() if reason_match else "Not available"
105
- alternative = alternative_match.group(1).strip() if alternative_match else "Not available"
106
- notes = notes_match.group(1).strip() if notes_match else "Not available"
107
-
108
- response = f"Reason: {reason}\nAlternative: {alternative}\nNotes: {notes}"
109
  print(f"Generated response: {response}") # Debugging line
110
  return response
111
 
112
  return "No relevant information found."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  [
21
  {{
22
  "role": "system",
23
+ "content": "You are an assistant that provides information about drink names based on a given corpus. \
24
+ Format the response in the following way:\n\
25
+ Reason: <reason why the name cannot be used>\n\
26
+ Alternative: <alternative name>\n\
27
+ Notes: <additional notes>"
28
  }},
29
  {{
30
  "role": "user",
 
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"
110
+
111
+ start_idx += len(start_keyword)
112
+ if end_keyword:
113
+ end_idx = text.find(end_keyword, start_idx)
114
+ if end_idx == -1:
115
+ end_idx = len(text)
116
+ else:
117
+ end_idx = len(text)
118
+
119
+ return text[start_idx:end_idx].strip()
120
+